V
V
Viktor Yanyshev2018-02-17 23:15:07
Yii
Viktor Yanyshev, 2018-02-17 23:15:07

How to translate error labels into JS on the client, activeForm?

Why or how to make the translation work?
5a888d5f5263c544293400.png
Now I have this:
Config:

'sourceLanguage' => 'en-EN',
'language' => 'ru-RU',
'components' => [
  'i18n' => [
            'translations' => [
                'app*' => [
                    'class' => 'yii\i18n\PhpMessageSource',
                    'basePath' => '@app/messages',
                    'sourceLanguage' => 'en-EN',
                    'fileMap' => [
                        'app' => 'app.php',
                        'app/error' => 'error.php',
                    ],
                ],
            ],
        ],
]

./messages/
└── ru-RU
    ├── app.php
    └── error.php

app.php
return [
    'First Name' => 'Имя',
    'Name' => 'Имя',
    'Last Name' => 'Фамилия',
    'Middle Name' => 'Отчество',
    'Password' => 'Пароль',
    'Title' => 'Заголовок',
    'Tags ID' => 'Тэги',
    'Content' => 'Содержание',
    'Body' => 'Содержание',
    'Save' => 'Сохранить',
    'Send' => 'Отправить',
    'Comment' => 'Комментарий'
];

The form:
<? $form = \yii\widgets\ActiveForm::begin(['id' => 'b-contacts__form']) ?>
                <?= $form->field($model, 'name')->textInput()->label(Yii::t('app', 'Name')); ?>
                <?= $form->field($model, 'email')->textInput(['type' => 'email'])->label(Yii::t('app', 'Email')); ?>
                <?= $form->field($model, 'body')->textarea(['rows' => 5])->label(Yii::t('app', 'Content')); ?>
                <?= \yii\helpers\Html::submitButton(Yii::t('app', 'Send'), ['class' => 'btn btn-success pull-right']); ?>
<? \yii\widgets\ActiveForm::end(); ?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2018-02-18
@villiwalla

Goodnight.
How are the attributes called in the model?
It should be like this:

public function attributeLabels()
{
     retunr [
         'name' => Yii::t('app', 'Name')
     ];
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question