A
A
AtomU2352018-09-28 12:10:39
Yii
AtomU235, 2018-09-28 12:10:39

Yii 2 select 2 by kartik. Why doesn't Russian language work in ajax search?

Hello.
Tell me why the Russian locale may not work in the widget? The widget's language property is explicitly set to 'ru', but all the captions are still in English.

$form->field($model, 'dir_streets_id')->widget(Select2::classname(), [
        'initValueText' => $model->streetDesc, // set the initial display text
        'language' => 'ru',
        'options' => ['placeholder' => 'Поиск ...'],        
        'pluginOptions' => [            
            'allowClear' => true,
            'minimumInputLength' => 3,
            'language' => [
                'errorLoading' => new JsExpression("function () { return 'Загрузка...'; }"),
            ],
            'ajax' => [
                'url' => $urlList,
                'dataType' => 'json',
                'data' => new JsExpression('function(params) { return {q:params.term}; }')
            ],
            'escapeMarkup' => new JsExpression('function (markup) { return markup; }'),
            'templateResult' => new JsExpression('function(dir_streets_id) { return dir_streets_id.text; }'),
            'templateSelection' => new JsExpression('function (dir_streets_id) { return dir_streets_id.text; }'),
        ],
    ]);

5badf03f17d41673422604.png
UPD: The vendor/kartik-v/yii2-widget-select2/src/assets/js/i18n/ru.js file is present.
Solution:
Remove
'language' => [
     'errorLoading' => new JsExpression("function () { return 'Загрузка...'; }"),
],

solved the issue.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2018-09-28
@AtomU235

Good afternoon.
Does the ru.js file exist in the vendor/kartik-v/yii2-widget-select2/assets/js/i18n directory ?
If it is not there, then there will be no Russian translation.
You also need to check which language is set in the application's configuration file, in the config directory .

return [
    'language' => 'ru', // указать русский язык
    'components' => [

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question