Yii2 translation i18n with multiple files

Hello Guys, i have a question about i18n with yii2. As i have a pretty big app, i did several files under /backend/messages/en-US like this app.php explication.php delivery.php etc. and i’ve added the code in my config/main.php and i don’t get why only the app.php translations are working. Any string on all other files are not showing… Do you have any idea why ? Or is it possible to work only with app.php ?

Kind regards

my configuration code

'i18n' => [
           'translations' => [
               '*'=> [
                   'class' => 'yii\i18n\PhpMessageSource',
                   'basePath' => '$app/messages',
                   'sourceLanguage' => 'en-US',
                   'fileMap' => [
                       'app' => 'app.php',
                       'app/maker' => 'maker.php',
                       'app/producer' => 'producer.php',
                       'app/product' => 'product.php',
                       'app/delivery' => 'delivery.php',
                       'app/explication'=>'explication.php',
                       'app/faq'=>'faq.php',
                       'app/greensocial'=>'greensocial.php',
                       'app/rbac-admin'=>'rbac-admin.php',
                       'app/yii'=>'yii.php',
                       'app/error' => 'error.php',

                   ],
               ],
           ],
       ],

Try moving app to be last on this list.

Thank you, i tried, but it does not work either.

I also tried forceTranslation = true
and with and without the app/…

but same problem. only the app.php shows the correct translations

So, i found one way to do it…

'i18n' => [
        'translations' => [
            'app'=> [
                'class' => 'yii\i18n\PhpMessageSource',
                //'basePath' => '$app/messages',
                'sourceLanguage' => 'en-US',
                'fileMap' => [    
                    'app' => 'app.php',
                    'app/error' => 'error.php',
                ],
            ],
            'explication'=> [
              'class' => 'yii\i18n\PhpMessageSource',
              'sourceLanguage' => 'en-US',
              'fileMap' => [    
                  'explication' => 'explication.php',
              ],
          ],
...

you can also try this to simplify, it worked for me but will depend on your application configuration

...
use yii\i18n\PhpMessageSource;
...
'i18n' => [
            'translations' => [
                '*' => [
                    'class' => PhpMessageSource::class,
                    'sourceLanguage' => 'en-US',
                    'basePath' => '@app/messages'
                ],
            ],
],
...

usage:

Yii::t('app', 'message')
Yii::t('delivery', 'message')
Yii::t('rbac', 'message')
...
Yii::t('yii', 'message')

and under app structure

\app
    \messages
           \fr-FR
           \en-GB
           \pt-PT
              app.php
              delivery.php
              rbac.php
              ...
              yii.php