Doesn’t work. Translation with the environment in Yii2

I have installed 3 environments.

My application must download different translation sets, because each env is different.

I have a language RO, HU, DE.

I am trying to install translations but this will not work.

in frontend / config main.php I have:

'sourceLanguage' => 'en', 'language' => 'en',

in frontend/web/index.phpi:

defined('YII_ENV') or define('YII_ENV', 'dev_ro');

also, I am merging the configuration array:

(file_exists(__DIR__ . '/../../environments/' . YII_ENV . '/common/config/main-local.php') ? require(__DIR__ . '/../../environments/' . YII_ENV . '/common/config/main-local.php') : [])

now, in environments/dev_ro/common/config/, in componentsi:

'i18n' => [
            'translations' => [
                'companie' => [
                    'class' => 'yii\i18n\PhpMessageSource',
                    'basePath' => '@app/messages',
                    'sourceLanguage' => 'en',
                    'fileMap' => [
                        'companie' => 'companie.php',
                    ],
                ],
            ],
        ],

in the model CompanieI have:

'nume' => Yii::t('companie', 'Name'),

This is a movie, with my thing:

movie

+4
source share
2 answers

The problem is in the application *, because it is not an application * of the category, it works:

    'i18n' => [
        'translations' => [
            '*' => [
                'class' => 'yii\i18n\PhpMessageSource',
                'fileMap' => [
                    'companie' => 'companie.php',
                ],
            ],
        ],
    ],

Or if you want to write 'companie*' =>

, . BasePath/messages/LanguageID/CategoryName.php.

backend frontend, , , ( yii) i18n. :

:

Yii::setAlias('@common', dirname(__DIR__));
return [
    'language' => 'ru',
    'sourceLanguage' => 'ru',
    'components' => [
    'i18n' => [
        'translations' => [
            '*' => [
                'class' => 'yii\i18n\PhpMessageSource',
                'basePath' => '@common/messages',
                'fileMap' => [
                    'companie' => 'companie.php',
                ],
  ....

traslate/common/messages/en-US/companie.php

<?php
return [
    'string in russian' => 'string in english'
];

, :

\Yii::$app->language = 'en-US';
echo \Yii::t('companie', 'string in russian');
+2

:

en-US >> en_US

.

0

Source: https://habr.com/ru/post/1537729/


All Articles