here is a little patch to add localization support to the popup datepicker.

You must use jquery ui module to benefit from this patch.
jquery-ui has a great datepicker plugin that is distributed with a large set of pre-defined i18n presets
This patch will load the right i18n preset according to drupal current language (global $language)

IMHO this feature should be part of this module

File attached

You can locate all i18n presets under modules\jquery_ui\jquery.ui\ui\i18n
I also included code changes summary for reference

function date_popup_load() {
   ...
  if (module_exists('jquery_ui')) {
    jquery_ui_add('ui.datepicker');

    // Add i18n support
    global $language;
    if ($language->language != 'en') {
        drupal_add_js (JQUERY_UI_PATH.'/ui/i18n/ui.datepicker-'.($language->language).'.js');
    }
  }
  ...
}

function date_popup_process_date(&$element, $edit = NULL, $date = NULL) {
  ...
  $year_range = date_range_string($range);
  
  // When using jquery ui, we load the language settings
  // So we don't need to use drupal translations 
  if (module_exists('jquery_ui')) {
	  $settings = array(
		//'buttonImage' => base_path() . drupal_get_path('module', 'date_api') ."/images/calendar.png",
		//'buttonImageOnly' => TRUE,
		'autoPopUp' => 'focus',
		'closeAtTop' => FALSE,
		'speed' => 'immediate',
		'yearRange' => $year_range,
		// Custom setting, will be expanded in Drupal.behaviors.date_popup()
		'fromTo' => isset($fromto),
	  );    
  }
  else {
      global $language;
      $settings = array(
            ...
            'isRTL' => $language->direction == LANGUAGE_RTL,
     );    
  }
  ...
}

Comments

optalgin’s picture

StatusFileSize
new21.98 KB

And here is the file

jedihe’s picture

Issue tags: +datepicker localization workaround

In the meanwhile, there is a workaround that can be implemented in template.php:

function MYTHEMENAME_preprocess_node(&$vars) {
  // Add the localization for the datepicker widget, if it's included in the current rendered node. It should have been done on preprocess_page, but at that point the scripts array haven't been populated as much as now
  $jss = drupal_add_js(NULL, NULL, NULL); //read http://api.drupal.org/api/function/drupal_add_js/6 for info on this obscure call to drupal_add_js
  
  // Check for the three possible cases (normal, minified or packed)
  if (isset($jss['header']['module']['sites/all/modules/contrib/jquery_ui/jquery.ui/ui/ui.datepicker.js'])
      || isset($jss['header']['module']['sites/all/modules/contrib/jquery_ui/jquery.ui/ui/minified/ui.datepicker.min.js'])
      || isset($jss['header']['module']['sites/all/modules/contrib/jquery_ui/jquery.ui/ui/packed/ui.datepicker.packed.js'])) {
    $datepicker_locale = drupal_get_path('module', 'jquery_ui') . '/jquery.ui/ui/minified/i18n/ui.datepicker-es.min.js'; //The minified version is the smallest one for spanish, so I chose that one
    drupal_add_js($datepicker_locale, 'theme');
  }
}

//Remember the closing php tag shouldn't be used on the actual template.php, it's used here only to get the nice code highlighting.

I haven't tested it thoroughly, but it works ok with a couple webform nodes on a site I'm developing. This one also depends on jQuery UI

That's it, that way you can avoid patching a module, which is highly discouraged. Hopefully the actual localization support will be added soon.

YK85’s picture

Status: Patch (to be ported) » Needs review

subscribing

dway’s picture

subscribing

dway’s picture

Comment #2 is not working in CCK content type forms : the MYTHEME_preprocess_node() function seems not be called in these cases. I've put the code in the MYTHEME_preprocess_page instead and it works fine.

karens’s picture

Status: Needs review » Active

This is not a patch. The current code uses t() on the month and day names. Is that not sufficient? If not, please explain how this will help, make it into a real patch, and it needs to be tested by others who use i18n.

karens’s picture

Status: Active » Postponed (maintainer needs more info)
optalgin’s picture

Status: Postponed (maintainer needs more info) » Active

The jQuery date picker has its own translation files, including RTL support and more,
using drupal's t() is not the preferred way here.

My patch includes the jQuery datepicker own translation files (user need to download from jquery ui site)
and by this uses the full i18n features of the datepicker widget.

I am sorry but I cannot produce a patch file, I attached my code and made it as clear as I can see original post

webflo’s picture

Version: 6.x-2.4 » 6.x-2.7
Status: Active » Needs review
StatusFileSize
new2.84 KB

I rerolled this patch from #1 with some modifications. Localization is handeld by jquery.ui module. Please review.

mvc’s picture

Version: 6.x-2.7 » 6.x-2.x-dev
StatusFileSize
new2.32 KB

#975320: Date picker not translated was just committed, which solves half this problem. rerolled with just the second half for 6.x-2.x-dev.

damienmckenna’s picture

Assigned: optalgin » Unassigned
Issue summary: View changes
Status: Needs review » Closed (won't fix)

Unfortunately the D6 branch is no longer supported.