Translate datepicker on VM3 (NL or other languages do not work)

Started by stAn99, March 14, 2016, 13:24:37 PM

Previous topic - Next topic

stAn99

hello, we just located a bug in VM3 (3.0.14 and before) which did not load jquery datepicker language files properly.

\administrator\components\com_virtuemart\helpers\vmjsapi.php

update whole function to:

static function jDate($date='',$name="date",$id=NULL,$resetBt = TRUE, $yearRange='') {

if ($yearRange) {
$yearRange = 'yearRange: "' . $yearRange . '",';
}

$test = (int) str_replace(array('-',' ',':'),'',$date);
if(empty($test)){
$date = 0;
}

if (empty($id)) {
$id = str_replace(array('[]','[',']'),'.',$name);
$id = str_replace('..','.',$id);
}

static $jDate;
if(!class_exists('VmHtml')) require(VMPATH_ADMIN.DS.'helpers'.DS.'html.php');
$id = VmHtml::ensureUniqueId($id);
$dateFormat = vmText::_('COM_VIRTUEMART_DATE_FORMAT_INPUT_J16');//="m/d/y"
$search  = array('m', 'd', 'Y');
$replace = array('mm', 'dd', 'yy');
$jsDateFormat = str_replace($search, $replace, $dateFormat);

if ($date) {
$formatedDate = JHtml::_('date', $date, $dateFormat );
}
else {
$formatedDate = vmText::_('COM_VIRTUEMART_NEVER');
}
$display  = '<input class="datepicker-db" id="'.$id.'" type="hidden" name="'.$name.'" value="'.$date.'" />';
$display .= '<input id="'.$id.'_text" class="datepicker" type="text" value="'.$formatedDate.'" />';
if ($resetBt) {
$display .= '<span class="vmicon vmicon-16-logout icon-nofloat js-date-reset"></span>';
}

// If exist exit
if ($jDate) {
return $display;
}

self::addJScript('datepicker','
jQuery(document).ready( function($) {
jQuery(document).on( "focus",".datepicker", function() {
jQuery( this ).datepicker({
changeMonth: true,
changeYear: true,
'.$yearRange.'
dateFormat:"'.$jsDateFormat.'",
altField: $(this).prev(),
altFormat: "yy-mm-dd"
});
});
jQuery(document).on( "click",".js-date-reset", function() {
jQuery(this).prev("input").val("'.vmText::_('COM_VIRTUEMART_NEVER').'").prev("input").val("0");
});
});
');


vmJsApi::css('ui/jquery.ui.all');

$lg = JFactory::getLanguage();
    $lang = $lg->getTag();

  $existingLang = array("af","ar","ar-DZ","az","bg","bs","ca","cs","da","de","el","en-AU","en-GB","en-NZ","eo","es","et","eu","fa","fi","fo","fr","fr-CH","gl","he","hr","hu","hy","id","is","it","ja","ko","kz","lt","lv","ml","ms","nl","no","pl","pt","pt-BR","rm","ro","ru","sk","sl","sq","sr","sr-SR","sv","ta","th","tj","tr","uk","vi","zh-CN","zh-HK","zh-TW");
  if (!in_array ($lang, $existingLang)) {
$lang = substr ($lang, 0, 2);
  }
  if (!in_array ($lang, $existingLang)) {
$lang = "en-GB";
  }
$vlePath = vmJsApi::setPath('i18n/jquery.ui.datepicker-'.$lang, FALSE , '' ,$minified = NULL ,   'js', true);
if(!file_exists($vlePath) or is_dir($vlePath)){
$lang = 'en-GB';
}
vmJsApi::addJScript( 'i18n/jquery.ui.datepicker-'.$lang );

$jDate = TRUE;
return $display;
}


some of the language files use this format:
jquery.ui.datepicker-nl.js
while a very few of them use a full format like:
jquery.ui.datepicker-en-NZ.js

best regards, stan, rupostel.com
----
RuposTel.com
www.rupostel.com
Your customized checkout solution for Virtuemart