Commit 84890625 by Qiang Xue

Merge pull request #2573 from andy5/datepicker-language

Use the current appliaction language in DatePicker
parents db8685cc 3073543c
......@@ -6,6 +6,7 @@ Yii Framework 2 jui extension Change Log
- Bug #1550: fixed the issue that JUI input widgets did not property input IDs. (qiangxue)
- Bug #2514: Jui sortable clientEvents were not working because of wrong naming assumptions. (cebe)
- Enh #2573: Jui datepicker now uses the current appliaction language by default. (andy5)
2.0.0 alpha, December 1, 2013
-----------------------------
......
......@@ -7,11 +7,12 @@
namespace yii\jui;
use Yii;
use yii\helpers\Html;
use yii\helpers\Json;
/**
* DatePicker renders an datepicker jQuery UI widget.
* DatePicker renders a datepicker jQuery UI widget.
*
* For example:
*
......@@ -46,9 +47,9 @@ class DatePicker extends InputWidget
{
/**
* @var string the locale ID (eg 'fr', 'de') for the language to be used by the date picker.
* If this property set to false, I18N will not be involved. That is, the date picker will show in English.
* If this property is empty, then the current application language will be used.
*/
public $language = false;
public $language;
/**
* @var boolean If true, shows the widget as an inline calendar and the input as a hidden field.
*/
......@@ -77,12 +78,13 @@ class DatePicker extends InputWidget
{
echo $this->renderWidget() . "\n";
$containerID = $this->inline ? $this->containerOptions['id'] : $this->options['id'];
if ($this->language !== false) {
$language = $this->language ? $this->language : Yii::$app->language;
if ($language != 'en') {
$view = $this->getView();
DatePickerRegionalAsset::register($view);
$options = Json::encode($this->clientOptions);
$view->registerJs("$('#{$containerID}').datepicker($.extend({}, $.datepicker.regional['{$this->language}'], $options));");
$view->registerJs("$('#{$containerID}').datepicker($.extend({}, $.datepicker.regional['{$language}'], $options));");
$options = $this->clientOptions;
$this->clientOptions = false; // the datepicker js widget is already registered
......
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