I use keyword-based translations in my Yii2 application (I know this is not the best option, but I have no others). I prepared the files @app/messages/pl/app.php and @app/messages/en/app.php with translation strings using keywords and not full-featured sentences or words:
<?php return [ 'name_english'=>'Name in English', 'keywords_english'=>'Keywords in English' ]; ?>
I installed my application to use the default Polish language:
'language' => 'pl', 'sourceLanguage' => 'en',
And I invoke the translation:
Yii::t('app', 'keywords_english');
Everything works fine when the language is actually installed on the base, Polish ( pl ):

But, when I change it to English ( en ; either by setting Yii::$app->language at runtime, or by changing the configuration of the application), the translation fails, and I get keywords_english :

I put die() at the beginning of the @app/messages/pl/app.php and @app/messages/en/app.php , and I clearly see that when the language is set to English, the second file does not include Yii2 (launch application follows), whereas when the language is Polish, the first file is included, and the application stream is split into die() .
What am I missing? Why doesn't Yii2 use translations from the @app/messages/en/app.php if the language is set to English ( en )?
EDIT . By default, I did not change the configuration of the default i18n component in my application configuration, since I did not need this. Translation files are stored in the default position ( @app/messages/<language>/ ) and use the default class ( yii\i18n\PhpMessageSource ). And this works for all languages except sourceLanguage . At some point, I tried to change the configuration:
'i18n' => [ 'translations' => [ '*' => [ 'class' => 'yii\i18n\PhpMessageSource', 'sourceLanguage' => 'en', 'basePath' => '@app/messages' ], ], ],
But that did not change (why it should - it still uses the default settings).