Yii2 translate a module from outside

89 Views Asked by At

If you have a yii2 module installed by composer how can you add a new language without touching the module itself (since touching anything in vendor/ is quite a bad practice)?

Let's say you have a module vbt-cron which already have an English an a Hungarian language files inside and it's configured like this:

\Yii::$app->i18n->translations['vbt-cron'] = [
    'class' => '\yii\i18n\PhpMessageSource',
    'sourceLanguage' => 'en-US',
    'basePath' => '@sharkom/cron/messages',
];

Your app is in Italian so you want to translate the module externally, yii message extracted the strings from the module, you added it to the config:

'vbt-cron' => [
    'class' => 'yii\i18n\PhpMessageSource',
    'basePath' => '@app/messages',
    'fileMap' => [
        'vbt-cron'     => 'vbt-cron.php'
    ],
]

but it doesn't work because yii only look for translations inside the module messages folder:

The message file for category 'vbt-cron' does not exist: vendor/sharkom/yii2-cron/messages/it-IT/vbt-cron.php Fallback file does not exist as well: vendor/sharkom/yii2-cron/messages/it/vbt-cron.php

So, how can you make yii look inside the app messages folder as well?

P.S. I'm looking for a generic answer, not for a way to translate the specific module used as example here.

0

There are 0 best solutions below