V
V
Vitaly Liber2015-05-06 15:59:40
Yii
Vitaly Liber, 2015-05-06 15:59:40

How to Russify validation messages, etc. in Yii2?

Created an application in Yii2. Read the documentation about localization. However, to understand the process, you need to see the localization with an example.
Does anyone have an example of localizing an application into Russian.
It is required to translate, for example, validation error messages.

Answer the question

In order to leave comments, you need to log in

5 answer(s)
P
Papa, 2015-05-06
Stifflera @PapaStifflera

Specify the Russian language in the application config.

M
mitaichik, 2015-05-06
@mitaichik

If the labels - then the models have an attributeLabels field - you write names there using Yii::t
Validation messages - then each validator has a message field (configured in the rules of the model for each validator separately), where you also write a message using Yii:: t. Some validators have many fields for different cases (for example, for StringValidator - tooShort, tooLong, notEqual) - they must also be specified when configuring the validator (if you use these validation features, for example, checking for the minimum string length).
Well, of course, in the application config, register the Russian language

V
Vitaly Liber, 2015-05-06
@VitalyLiber

OK. This is clear.
How to translate the activeform field into Russian?
For example, username in the authorization menu?

R
Roman Frank, 2015-05-07
@Akellacom

As answered above, use Yii::t
in config

'language' => 'ru-RU',

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

messages/ru-RU/app.php
<?php
return [
  'Create' => 'Добавить',
  'Update' => 'Обновить',
  'Delete' => 'Удалить',
  'Create {modelClass}' => 'Добавить {modelClass}',
  'Update {modelClass}' => 'Обновить {modelClass}',
]

And like this use
www.yiiframework.com/doc-2.0/guide-tutorial-i18n.html
rmcreative.ru/blog/post/yii2-perevod-soobscheniy

L
lebedyncrs, 2015-05-07
@lebedyncrs

public function rules() {
return [
['crmSegment_Id', 'required', 'message' => 'error message'],
['AssignedTo', 'required', 'message' => 'error message'],
];
}
not the best way, but you can

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question