yii2-date-picker-widget的西班牙语位置

时间:2015-06-22 08:56:53

标签: datepicker yii2

我正在研究Yii2的基本模板。我使用2amigos yii2-date-picker-widget。 Datepicker工作正常,但它一直向我显示默认语言(即英语)而不是西班牙语。 正如您在下面的代码中看到的那样,语言参数设置为' es':

<?= $form->field($model, 'alta')->widget(
    DatePicker::className(), [
        'inline' => false, 
        'clientOptions' => [
            'format' => 'yyyy-mm-dd',
            'weekStart' => 1,
            'todayBtn' => 'linked',
            'clearBtn' => true,
            'language' => 'es',
            'autoclose' => true,
            'todayHighlight' => true
        ]
]);?>

看起来2amigos Datepicker进入正确的位置:

DatePickerLanguageAsset::register($view)->js[] = 'bootstrap-datepicker.' . $this->language . '.min.js';

这意味着@ vendor / bower / bootstrap-datepicker / dist / locales / bootstrap-datepicker.es.min.js,这是一个包含我所需西班牙语位置的现有文件:

!function(a){a.fn.datepicker.dates.es={days:["Domingo","Lunes","Martes","Miércoles","Jueves","Viernes","Sábado","Domingo"],daysShort:["Dom","Lun","Mar","Mié","Jue","Vie","Sáb","Dom"],daysMin:["Do","Lu","Ma","Mi","Ju","Vi","Sa","Do"],months:["Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre"],monthsShort:["Ene","Feb","Mar","Abr","May","Jun","Jul","Ago","Sep","Oct","Nov","Dic"],today:"Hoy",clear:"Borrar",weekStart:1,format:"dd/mm/yyyy"}}(jQuery);

为什么没有应用此翻译? 非常感谢。

1 个答案:

答案 0 :(得分:1)

由于语法错误,您的翻译无效,您应将语言参数从“clientOptions”移至顶级数组:

<?= $form->field($model, 'alta')->widget(
DatePicker::className(), [
    'inline' => false, 
    'language' => 'es',
    'clientOptions' => [
        'format' => 'yyyy-mm-dd',
        'weekStart' => 1,
        'todayBtn' => 'linked',
        'clearBtn' => true,
        'autoclose' => true,
        'todayHighlight' => true
        ]
]);?>