lajax / yii2-translate-manager

Translation Manager
MIT License
227 stars 90 forks source link

Question: troubleshooting no translations shown #91

Closed HankBrown closed 7 years ago

HankBrown commented 7 years ago

Help please. I am not seeing any translations.

In the database I have:

category='app', message='Apple' in language_source table.

language='fr-FR', translation='Pomme de terre' in language_translate table.

To test, I have SiteController init:

    public function init()
    {
        parent::init();
        \Yii::$app->language = 'fr-FR';
    }

The view has:


    <?= Lx::t('app', 'Apple');?>
    <?='lang='.\Yii::$app->language;?>
    At runtime it shows "Apple" and "fr-FR".

By inserting some debug I can see the translations were not loaded (I think):

'BEGIN translateMessage'
yii\i18n\PhpMessageSource#1
(
    [basePath] => '@app/messages'
    [fileMap] => null
    [forceTranslation] => false
    [sourceLanguage] => 'en-US'
    [yii\i18n\MessageSource:_messages] => array
    (
        [fr-FR/app] => array
        (
            [Apple] => false
                        ... all false

In the app log I find this sql:

(SELECT t1.message AS message, t2.translation AS translation FROM language_source t1, language_translate t2 WHERE (t1.id=t2.id) AND (t1.category='language') AND (t2.language='fr-FR')) UNION ALL ( SELECT t1.message AS message, t2.translation AS translation FROM language_source t1, language_translate t2 WHERE ((t1.id=t2.id) AND (t1.category='language') AND (t2.language='fr')) AND (t2.id NOT IN (SELECT id FROM language_translate WHERE language='fr-FR')) )

I notice the occurrence of 'fr' instead of 'fr-FR' in the query. Nowhere do I use 'fr' instead of 'fr-FR'. This returns the expected result in phpMyAdmin when I manually change

a) 'language' to 'app', and b) 'fr' to 'fr-FR;

2017-01-11 10:30:57 [192.168.56.1][1][-][error][yii\i18n\PhpMessageSource::loadFallbackMessages] The message file for category 'app' does not exist: /home/me/sites/www/frontend/messages/fr-FR/app.php Fallback file does not exist as well: /home/me/sites/www/frontend/messages/fr/app.php in /home/me/sites/www/vendor/lajax/yii2-translate-manager/helpers/Language.php:55

This confuses me, I have only DbMessageSource configured.

I am sure this is a simple/stupid error but I am lost.

Config is


    'bootstrap' => ['translatemanager'],
    'components' => [
        //'language' => 'en-US',          // USER (target) Change with Yii::$app->language
        'translatemanager' => [
            'class' => 'lajax\translatemanager\Component',   // ljax component for front end translation
        ],
        'i18n' => [
            'translations' => [
                '*' => [
                    'db'=>'dbFOX',
                    'class' => 'yii\i18n\DbMessageSource',
                    'sourceLanguage' => 'en-US', // Developer language
                    'sourceMessageTable' => '{{%language_source}}',
                    'messageTable' => '{{%language_translate}}',
                    'cachingDuration' => 86400,
                    'enableCaching' => false,        // Hmmm guessing while dev/implement
                    //'forceTranslation' => true,   // NOPE
                ],
            ],
        ],
...
    'modules' => [
        'translatemanager' => [
            'class' => 'lajax\translatemanager\Module',
            'connection'=>'dbFOX',
            'root'=>[
                '/home/me/sites/www/frontend',
                '/home/me/sites/www/common',
            ],
            'allowedIPs'=>['*'],
        ],

Any suggestions much appreciated. Thank you.

Later: change config (remove asterisk, replace with category names) and I see translations:

So I know what I am chasing maybe. Why would '*' fail?

//                '*' => [
//                    ...
//                ],
                'app' => [
                    ...
                ],
                'language' => [
                    ...
                ],
moltam commented 7 years ago

The app and yii message category is configured default by the Yii 2 to use the files shipped with the framework. Try to use another message category for your messages, or overwrite the i18n config for these categories like this:

'i18n' => [
    'translations' => [
        '*' => [
            'db' => 'dbFOX',
            'class' => 'yii\i18n\DbMessageSource',
            'sourceLanguage' => 'en-US', // Developer language
            'sourceMessageTable' => '{{%language_source}}',
            'messageTable' => '{{%language_translate}}',
            'cachingDuration' => 86400,
            'enableCaching' => false, // Hmmm guessing while dev/implement
        //'forceTranslation' => true,   // NOPE
        ],
        'app' => [
            'class' => 'yii\i18n\DbMessageSource',
            'db' => 'dbFOX',
            'sourceLanguage' => 'en-US', // Developer language
            'sourceMessageTable' => '{{%language_source}}',
            'messageTable' => '{{%language_translate}}',
            'cachingDuration' => 86400,
            'enableCaching' => false,
        ],
        'yii' => [
            'class' => 'yii\i18n\DbMessageSource',
            'db' => 'dbFOX',
            'sourceLanguage' => 'en-US', // Developer language
            'sourceMessageTable' => '{{%language_source}}',
            'messageTable' => '{{%language_translate}}',
            'cachingDuration' => 86400,
            'enableCaching' => false,
        ],
    ],
],
HankBrown commented 7 years ago

Thank you so much moltam. You beat me to the punch by a minute ;) I saw this as a previous issue but it did not register with me.

moltam commented 7 years ago

No problem :-)