summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Rothstein <drothstein@gmail.com>2012-06-25 23:03:38 -0400
committerDavid Rothstein <drothstein@gmail.com>2012-06-25 23:03:38 -0400
commit09b754ae8a78fdc9ab076779f10ce5d81c656623 (patch)
tree6edc98838f3c5228afe83e0bb49e7e48d7b25246
parenteb35c1048cb44dfc730e233565366bac9234ace3 (diff)
downloadbrdo-09b754ae8a78fdc9ab076779f10ce5d81c656623.tar.gz
brdo-09b754ae8a78fdc9ab076779f10ce5d81c656623.tar.bz2
Issue #507502 by fietserwin, cosmicdreams, Rob Loach, tim.plunkett, sun, marvil07, nod_: Fixed missing Locale support for jQuery UI Datepicker.
-rw-r--r--CHANGELOG.txt1
-rw-r--r--modules/locale/locale.datepicker.js138
-rw-r--r--modules/locale/locale.module21
-rw-r--r--modules/locale/locale.test32
4 files changed, 120 insertions, 72 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index db4a8341d..ce8802338 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -20,6 +20,7 @@ Drupal 7.15, xxxx-xx-xx (development version)
- Fixed bug: Language detection by domain only worked on port 80.
- Fixed bug which prevented image styles from being deleted on PHP 5.4.
- Made Ajax alert dialogs respect error reporting settings.
+- Fixed bug which prevented the jQuery UI Datepicker from being localized.
Drupal 7.14 2012-05-02
----------------------
diff --git a/modules/locale/locale.datepicker.js b/modules/locale/locale.datepicker.js
index 81f1e17b3..f81928238 100644
--- a/modules/locale/locale.datepicker.js
+++ b/modules/locale/locale.datepicker.js
@@ -1,69 +1,79 @@
(function ($) {
-$.datepicker.regional['drupal-locale'] = {
- closeText: Drupal.t('Done'),
- prevText: Drupal.t('Prev'),
- nextText: Drupal.t('Next'),
- currentText: Drupal.t('Today'),
- monthNames: [
- Drupal.t('January'),
- Drupal.t('February'),
- Drupal.t('March'),
- Drupal.t('April'),
- Drupal.t('May'),
- Drupal.t('June'),
- Drupal.t('July'),
- Drupal.t('August'),
- Drupal.t('September'),
- Drupal.t('October'),
- Drupal.t('November'),
- Drupal.t('December')
- ],
- monthNamesShort: [
- Drupal.t('Jan'),
- Drupal.t('Feb'),
- Drupal.t('Mar'),
- Drupal.t('Apr'),
- Drupal.t('May'),
- Drupal.t('Jun'),
- Drupal.t('Jul'),
- Drupal.t('Aug'),
- Drupal.t('Sep'),
- Drupal.t('Oct'),
- Drupal.t('Nov'),
- Drupal.t('Dec')
- ],
- dayNames: [
- Drupal.t('Sunday'),
- Drupal.t('Monday'),
- Drupal.t('Tuesday'),
- Drupal.t('Wednesday'),
- Drupal.t('Thursday'),
- Drupal.t('Friday'),
- Drupal.t('Saturday')
- ],
- dayNamesShort: [
- Drupal.t('Sun'),
- Drupal.t('Mon'),
- Drupal.t('Tue'),
- Drupal.t('Wed'),
- Drupal.t('Thu'),
- Drupal.t('Fri'),
- Drupal.t('Sat')
- ],
- dayNamesMin: [
- Drupal.t('Su'),
- Drupal.t('Mo'),
- Drupal.t('Tu'),
- Drupal.t('We'),
- Drupal.t('Th'),
- Drupal.t('Fr'),
- Drupal.t('Sa')
- ],
- dateFormat: Drupal.t('mm/dd/yy'),
- firstDay: Drupal.settings.jqueryuidatepicker.firstDay,
- isRTL: Drupal.settings.jqueryuidatepicker.rtl
+/**
+ * Attaches language support to the jQuery UI datepicker component.
+ */
+Drupal.behaviors.localeDatepicker = {
+ attach: function(context, settings) {
+ // This code accesses Drupal.settings and localized strings via Drupal.t().
+ // So this code should run after these are initialized. By placing it in an
+ // attach behavior this is assured.
+ $.datepicker.regional['drupal-locale'] = $.extend({
+ closeText: Drupal.t('Done'),
+ prevText: Drupal.t('Prev'),
+ nextText: Drupal.t('Next'),
+ currentText: Drupal.t('Today'),
+ monthNames: [
+ Drupal.t('January'),
+ Drupal.t('February'),
+ Drupal.t('March'),
+ Drupal.t('April'),
+ Drupal.t('May'),
+ Drupal.t('June'),
+ Drupal.t('July'),
+ Drupal.t('August'),
+ Drupal.t('September'),
+ Drupal.t('October'),
+ Drupal.t('November'),
+ Drupal.t('December')
+ ],
+ monthNamesShort: [
+ Drupal.t('Jan'),
+ Drupal.t('Feb'),
+ Drupal.t('Mar'),
+ Drupal.t('Apr'),
+ Drupal.t('May'),
+ Drupal.t('Jun'),
+ Drupal.t('Jul'),
+ Drupal.t('Aug'),
+ Drupal.t('Sep'),
+ Drupal.t('Oct'),
+ Drupal.t('Nov'),
+ Drupal.t('Dec')
+ ],
+ dayNames: [
+ Drupal.t('Sunday'),
+ Drupal.t('Monday'),
+ Drupal.t('Tuesday'),
+ Drupal.t('Wednesday'),
+ Drupal.t('Thursday'),
+ Drupal.t('Friday'),
+ Drupal.t('Saturday')
+ ],
+ dayNamesShort: [
+ Drupal.t('Sun'),
+ Drupal.t('Mon'),
+ Drupal.t('Tue'),
+ Drupal.t('Wed'),
+ Drupal.t('Thu'),
+ Drupal.t('Fri'),
+ Drupal.t('Sat')
+ ],
+ dayNamesMin: [
+ Drupal.t('Su'),
+ Drupal.t('Mo'),
+ Drupal.t('Tu'),
+ Drupal.t('We'),
+ Drupal.t('Th'),
+ Drupal.t('Fr'),
+ Drupal.t('Sa')
+ ],
+ dateFormat: Drupal.t('mm/dd/yy'),
+ firstDay: 0,
+ isRTL: 0
+ }, Drupal.settings.jquery.ui.datepicker);
+ $.datepicker.setDefaults($.datepicker.regional['drupal-locale']);
+ }
};
-$.datepicker.setDefaults($.datepicker.regional['drupal-locale']);
})(jQuery);
diff --git a/modules/locale/locale.module b/modules/locale/locale.module
index 029492091..a20f3d5d7 100644
--- a/modules/locale/locale.module
+++ b/modules/locale/locale.module
@@ -950,15 +950,22 @@ function locale_css_alter(&$css) {
* Provides the language support for the jQuery UI Date Picker.
*/
function locale_library_alter(&$libraries, $module) {
- global $language;
- if ($module == 'system' && isset($libraries['system']['ui.datepicker'])) {
+ if ($module == 'system' && isset($libraries['ui.datepicker'])) {
+ global $language;
+ // locale.datepicker.js should be added in the JS_LIBRARY group, so that
+ // this attach behavior will execute early. JS_LIBRARY is the default for
+ // hook_library_info_alter(), thus does not have to be specified explicitly.
$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(
+ $libraries['ui.datepicker']['js'][$datepicker] = array();
+ $libraries['ui.datepicker']['js'][] = array(
'data' => array(
- 'jqueryuidatepicker' => array(
- 'rtl' => $language->direction == LANGUAGE_RTL,
- 'firstDay' => variable_get('date_first_day', 0),
+ 'jquery' => array(
+ 'ui' => array(
+ 'datepicker' => array(
+ 'isRTL' => $language->direction == LANGUAGE_RTL,
+ 'firstDay' => variable_get('date_first_day', 0),
+ ),
+ ),
),
),
'type' => 'setting',
diff --git a/modules/locale/locale.test b/modules/locale/locale.test
index 97bdafc32..a710ab25d 100644
--- a/modules/locale/locale.test
+++ b/modules/locale/locale.test
@@ -180,6 +180,36 @@ class LocaleConfigurationTest extends DrupalWebTestCase {
}
/**
+ * Tests 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');
+ }
+
+ /**
+ * Verifies that the datepicker can be localized.
+ *
+ * @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.'));
+ }
+}
+
+/**
* Functional tests for JavaScript parsing for translatable strings.
*/
class LocaleJavascriptTranslationTest extends DrupalWebTestCase {
@@ -1515,7 +1545,6 @@ class LocaleUninstallFrenchFunctionalTest extends LocaleUninstallFunctionalTest
}
}
-
/**
* Functional tests for the language switching feature.
*/
@@ -2795,6 +2824,7 @@ class LocaleCommentLanguageFunctionalTest extends DrupalWebTestCase {
}
}
}
+
/**
* Functional tests for localizing date formats.
*/