Localisation not working when language is same as source

The translations do not appear when the language of the application is the same as the sourceLanguage.

Here is the main.php:


return [

    'id' => 'applicationID',

    'sourceLanguage' => 'en-US',

    'basePath' => dirname(__DIR__),

    'language' => 'en-US',

        'i18n' => [

            'translations' => [

                '*' => [

                    'class' => 'yii\i18n\PhpMessageSource',

                    'basePath' => "@app/messages",

                ],

            ],

        ],

    ],

];

messages/en-US/feedback.php:


<?php

return [

    'TEST' => 'TEST EN',

];

message/de-DE/feedback.php


<?php

return [

    'TEST' => 'TEST DE',

];

When I set the language of the application to be de-DE \Yii::t(‘feedback’, ‘TEST’); output:

TEST DE

When I set the language of the application to be en-US \Yii::t(‘feedback’, ‘TEST’); output:

TEST

I can’t see anything wrong in what I am doing. Any ideas?

EDIT: I already tried to add :


'sourceLanguage' => 'en-US',



To the i18n configuration but it doesn’t change anything.

any idea about what could cause this issue?

what do you want to translate, when text in source is in correct language ?

Well, the keys in the message files do not represent always the appropriate translation. Yii grabs the key where it should grab its translation.

That is the correct behaviour unless you set forceTranslation to true in your i18n configuration. If you look at the code for DbMessageSource, you should find out exactly where to put this setting (can’t remember off the top of my head).

This caught me out for ages but the suggested way to use translations is to make the source message be correct for the source language and then you don’t have to translate if you are viewing the site in the source language.