V
V
Viktor Yanyshev2017-06-20 07:08:03
Yii
Viktor Yanyshev, 2017-06-20 07:08:03

Why don't i18n pull up translations?

In the application configuration:

'language' => 'ru-RU',
'components' => [
        'i18n' => [
            'translations' => [
                'app*' => [
                    'class' => 'yii\i18n\PhpMessageSource',
                    'basePath' => '@common/messages',
                ],
            ],
        ],

In ./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
.....

In the view:
Yii::t('app', 'Products');
// на выходе Products

Why are translations not being uploaded? Yii2 Advanced

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2017-06-20
@villiwalla

Either the sourceLanguage of the application matches the language or the translation is not found for you (in this case, use the yii log or the debug panel)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question