Answer the question
In order to leave comments, you need to log in
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
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
OK. This is clear.
How to translate the activeform field into Russian?
For example, username in the authorization menu?
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',
],
],
],
],
]
<?php
return [
'Create' => 'Добавить',
'Update' => 'Обновить',
'Delete' => 'Удалить',
'Create {modelClass}' => 'Добавить {modelClass}',
'Update {modelClass}' => 'Обновить {modelClass}',
]
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 questionAsk a Question
731 491 924 answers to any question