Answer the question
In order to leave comments, you need to log in
Yii2. How to use Yii::t?
/common/config/main.php
'
components' => [
...
'i18n' => [
'translations' => [
'*' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '@common/messages',
'fileMap' => [
'app' => 'app.php',
'app/auth' => 'auth.php'
]
],
],
],
<?php
return [
'City ID' => 'Город',
];
<?php
return [
'language' => 'ru-RU',
'sourceLanguage' => 'ru-RU',
echo \Yii::t('app','City ID');
Answer the question
In order to leave comments, you need to log in
Thanks to all. You were right, my sourceLanguage is not correctly specified.
And a couple more points for the translations to work:
1) moved
<?php
return [
'language' => 'ru-RU',
'sourceLanguage' => 'ru-RU',
'i18n' => [
'translations' => [
'app*'=> [
'class' => 'yii\i18n\PhpMessageSource',
echo \Yii::$app->language;
var_dump(\Yii::$app->i18n);
the source language (the one you use inside Yii::t) is Russian. application language (the one you want to display) - Russian. what to translate?
Yii understands this in Russian. Change sourceLanguage
I can assume the following:
When language and sourceLanguage match, then Yii will not even go for the translation, but will take what is indicated. You have this City ID.
PS Try changing the sourceLanguage since you are using Yii::t('app','City ID') English here.
Under tell me why messages like Update {modelClass} are not translated?
Code in app.php file
<?php
return [
'Update' => 'Изменить',
'Brandnames' => 'Брэнд',
'Update {modelClass}'=>'Изменить {modelClass}',
];
?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question