Commit 43e4ad70 authored by catch's avatar catch

Issue #507502 by fietserwin, cosmicdreams, tim.plunkett, sun, nod_: Fixed...

Issue #507502 by fietserwin, cosmicdreams, tim.plunkett, sun, nod_: Fixed locale support for jQuery UI.
parent 62b1cbde
<?php
/**
* @file
* Definition of Drupal\locale\Tests\LocaleLibraryInfoAlterTest.
*/
namespace Drupal\locale\Tests;
use Drupal\simpletest\WebTestBase;
/**
* Tests localization of the JavaScript libraries.
*
* Currently, only the jQuery datepicker is localized using Drupal translations.
*/
class LocaleLibraryInfoAlterTest extends WebTestBase {
public static function getInfo() {
return array(
'name' => 'Javascript library localisation',
'description' => 'Tests localization of the JavaScript libraries.',
'group' => 'Locale',
);
}
function setUp() {
parent::setUp(array('locale'));
}
/**
* 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.'));
}
}
......@@ -2,70 +2,80 @@
"use strict";
$.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);
......@@ -641,21 +641,28 @@ function locale_js_alter(&$javascript) {
}
}
/**
/**
* Implement hook_library_info_alter().
*
* Provides the language support for the jQuery UI Date Picker.
*/
function locale_library_info_alter(&$libraries, $module) {
global $language_interface;
if ($module == 'system' && isset($libraries['system']['ui.datepicker'])) {
if ($module == 'system' && isset($libraries['ui.datepicker'])) {
global $language_interface;
// 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_interface->direction == LANGUAGE_RTL,
'firstDay' => variable_get('date_first_day', 0),
'jquery' => array(
'ui' => array(
'datepicker' => array(
'isRTL' => $language_interface->direction == LANGUAGE_RTL,
'firstDay' => variable_get('date_first_day', 0),
),
),
),
),
'type' => 'setting',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment