В конфигурации приложения:
'language' => 'ru-RU',
'components' => [
'i18n' => [
'translations' => [
'app*' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '@common/messages',
],
],
],
В ./common/messages/ru-RU/app.php:
return [
'Create Products' => 'Создать товар',
'Products' => 'Товары',
];
var_dump(Yii::$app->i18n->translations)array (size=3)
'app*' =>
object(yii\i18n\PhpMessageSource)[92]
public 'basePath' => string '@common/messages' (length=16)
public 'fileMap' => null
public 'forceTranslation' => boolean false
public 'sourceLanguage' => string 'ru-RU' (length=5)
private '_messages' (yii\i18n\MessageSource) =>
array (size=0)
empty
private '_events' (yii\base\Component) =>
array (size=0)
empty
private '_behaviors' (yii\base\Component) => null
.....
Во вьюхе:
Yii::t('app', 'Products');
// на выходе Products
Почему не подтягиваются переводы? Yii2 Advanced