I want to change english validation messages in overall app.
so for example:
showing "field required" rather than "date of birth is required".
I tried to configure the I18N component as following:
'i18n' => [
'translations' => [
'*' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '@common/messages',
'sourceLanguage' => 'en',
'fileMap' => [
'yii' => 'yii.php',
]
// 'on missingTranslation' => ['app\components\TranslationEventHandler', 'handleMissingTranslation']
],
],
but not working
To change language globally for the whole application, add language to your config:
return [
...
'language' => 'ru',
...
],
This is for russian language, you can set any language you want. But framework messages are translated only in popular languages, you can open vendor/yiisoft/yii2/messages folder to see the complete list. Also you can refer to IETF language tags page.
To change message just for specific validation rule use message option:
['attributeName', 'validatorName', 'message' => 'Your customized message'],
Note that you can use internationalization (Yii::t()) here if your app is multilanguage.
['attribute', 'validator', 'message' => 'Your message {attribute}'],
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With