diff --git a/core/modules/locale/locale.module b/core/modules/locale/locale.module index 0a2e70e..01a8aa5 100644 --- a/core/modules/locale/locale.module +++ b/core/modules/locale/locale.module @@ -935,11 +935,17 @@ function locale_css_alter(&$css) { * Provides the language support for the jQuery UI Date Picker. */ function locale_library_info_alter(&$libraries, $module) { - global $language; - if ($module == 'system' && isset($libraries['system']['ui.datepicker'])) { + if ($module == 'system' && isset($libraries['ui.datepicker'])) { + global $language; $datepicker = drupal_get_path('module', 'locale') . '/locale.datepicker.js'; - $libraries['system']['ui.datepicker']['js'][$datepicker] = array('group' => JS_THEME); - $libraries['system']['ui.datepicker']['js'][] = array( + // locale.datepicker.js defines a configuration object for jQuery UI Date + // Picker containing strings translated via Drupal.t(). The configuration + // itself most likely won't be altered by other modules, but the JavaScript + // translations have to be loaded already. Library files use the group + // JS_LIBRARY by default, but translations are only loaded in JS_DEFAULT. + // @see locale_js_alter() + $libraries['ui.datepicker']['js'][$datepicker] = array('group' => JS_DEFAULT, 'weight' => 10); + $libraries['ui.datepicker']['js'][] = array( 'data' => array( 'jqueryuidatepicker' => array( 'rtl' => $language->direction == LANGUAGE_RTL, diff --git a/core/modules/locale/locale.test b/core/modules/locale/locale.test index 842b8f5..fd540c0 100644 --- a/core/modules/locale/locale.test +++ b/core/modules/locale/locale.test @@ -2742,3 +2742,33 @@ class LocaleLanguageNegotiationInfoFunctionalTest extends DrupalWebTestCase { } } } + +/** + * Functional test for localization of the javascript libraries. + * + * Currently only the jQuery datepicker is localized, using Drupal translations. + */ +class LocaleLibraryInfoAlterTest extends DrupalWebTestCase { + public static function getInfo() { + return array( + 'name' => 'Javascript library localisation', + 'description' => 'Tests the localisation of javascript libraries.', + 'group' => 'Locale', + ); + } + + function setUp() { + parent::setUp('locale', 'locale_test'); + } + + /** + * Verify that locale_library_info_alter adds localisation to the datepicker. + * + * @see locale_library_info_alter() + */ + public function testLibraryInfoAlter() { + drupal_add_library('system', 'ui.datepicker'); + $scripts = drupal_get_js(); + $this->assertTrue(strpos($scripts, 'locale.datepicker.js'), t('locale.datepicker.js added to scripts in footer.')); + } +}