lajax / yii2-translate-manager

Translation Manager
MIT License
227 stars 90 forks source link

Translation not working #27

Closed mzysk closed 9 years ago

mzysk commented 9 years ago

Hi, great extension (i see that from screenshot and administration tools) but i can't get it working.

In common config i have that:

'i18n' => [
            'translations' => [
                '*' => [
                    'class' => 'yii\i18n\DbMessageSource',
                    'db' => 'db',
                    'sourceLanguage' => 'en-US', // Developer language
                    'sourceMessageTable' => '{{%language_source}}',
                    'messageTable' => '{{%language_translate}}',
                    'cachingDuration' => 86400,
                    'enableCaching' => false,
                ],
            ],
        ],

and in custom frontend main config i've added module:

'translatemanager' => [
            'class' => 'lajax\translatemanager\Module',
        ],

translation manager is working great, i've scanned my project and have above 500 strings. So now i want to go to language 'en-US' and just for testing change some string with your editor. I'm saving changes, my translated string is visible in database table also it's still visible in your form. But on front i can't get it to work. I've tried to use this:

Html::a(Yii::t('dashboard', 'My Profile'), ['/settings'])

and that (with including on top of layout: use lajax\translatemanager\helpers\Language as Lx;):

Html::a(Lx::t('dashboard', 'My Profile'), ['/settings'])

but it's still showing my old default string - i can't overwrite it with your tools.

Could you tell me what am i doing wrong?

Thanks for your time and help.


also i have errors in log for some missing module translations like that: The message file for category 'user' does not exist: /Library/WebServer/Documents/projectname/vendor/dektrium/yii2-user/messages/en/user.php

lajax commented 9 years ago

Hi,

Try the forceTranslation option.

'i18n' => [
    'translations' => [
        '*' => [
            'class' => 'yii\i18n\DbMessageSource',
            'db' => 'db',
            'sourceLanguage' => 'en-US', // Developer language
            'sourceMessageTable' => '{{%language_source}}',
            'messageTable' => '{{%language_translate}}',
            'forceTranslation' => true,
            'cachingDuration' => 86400,
            'enableCaching' => false,
        ],
    ],
],

(http://www.yiiframework.com/doc-2.0/yii-i18n-messagesource.html#$forceTranslation-detail)

Best Regards,

mzysk commented 9 years ago

Hi @lajax - thank you for your help. It's working great now. Missing translation files disappeared after setting up in main config global parameter 'sourceLanguage' to 'en-US'.

ettolo commented 9 years ago

Hi, same situation of mzysk, but forceTranslation doesn't work for me. I use the advanced template, so changed tmpdir to 'tmpDir' => '@frontend/runtime' with no luck. I still get this error in log:

2015-09-18 10:29:04 [192.168.1.3][1][-][error][yii\i18n\PhpMessageSource::loadMessages] The message file for category 'app' does not exist: /home/yii2/public_html/frontend/messages/it-IT/app.php Fallback file does not exist as well: /home/yii2/public_html/frontend/messages/it/app.php

Btw, you are great and your extension is a must have! Thank you!

lajax commented 9 years ago

Hi! Could you send me the config of the i18n and the translateManager?

ettolo commented 9 years ago

Thank you, here you are! settings in common/config/main:

'i18n' => [
            'translations' => [
                '*' => [
                    'class' => 'yii\i18n\DbMessageSource',
                    'db' => 'db',
                    'sourceLanguage' => 'en-GB', // Developer language
                    'sourceMessageTable' => '{{%language_source}}',
                    'messageTable' => '{{%language_translate}}',
                    'forceTranslation' => true,
                    'cachingDuration' => 86400,
                    'enableCaching' => false,
                ],
            ],
        ],
'translatemanager' => [
            'class' => 'lajax\translatemanager\Module',
            'root' => '@app',               // The root directory of the project scan.
            'layout' => 'language',         // Name of the used layout. If using own layout use 'null'.
            'allowedIPs' => ['*'],          // IP addresses from which the translation interface is accessible.
            'roles' => ['@'],               // For setting access levels to the translating interface.
            'tmpDir' => '@frontend/runtime',         // Writable directory for the client-side temporary language files. 
                                            // IMPORTANT: must be identical for all applications (the AssetsManager serves the JavaScript files containing language elements from this directory).
            'phpTranslators' => ['::t'],    // list of the php function for translating messages.
            'jsTranslators' => ['lajax.t'], // list of the js function for translating messages.
            'patterns' => ['*.js', '*.php'],// list of file extensions that contain language elements.
            'ignoredCategories' => ['yii'], // these categories won’t be included in the language database.
            'ignoredItems' => ['config'],   // these files will not be processed.
            'scanTimeLimit' => null,        // increase to prevent "Maximum execution time" errors, if null the default max_execution_time will be used
            'searchEmptyCommand' => '!',    // the search string to enter in the 'Translation' search field to find not yet translated items, set to null to disable this feature
            'defaultExportStatus' => 1,     // the default selection of languages to export, set to 0 to select all languages by default
            'defaultExportFormat' => 'json',// the default format for export, can be 'json' or 'xml'
            'tables' => [                   // Properties of individual tables
                [
                    'connection' => 'db',   // connection identifier
                    'table' => '{{%language}}',         // table name
                    'columns' => ['name', 'name_ascii'] //names of multilingual fields
                ],
            ]
        ],
ettolo commented 9 years ago

Hi, i tried using a different and new category for translation and it works. It still doesn't work for 'app' category, don't know the other standard categories

ettolo commented 9 years ago

Neither 'user' category works, but 'translate' category do! I found this two errors in the log of a page with translation of 'user' and 'app': The first: why the hell is looking for GB??? page is in IT!

yii\i18n\PhpMessageSource::loadMessages The message file for category 'user' does not exist: /home/yii2/public_html/vendor/dektrium/yii2-user/messages/en-GB/user.php Fallback file does not exist as well: /home/yii2/public_html/vendor/dektrium/yii2-user/messages/en/user.php

The second:

The message file for category 'app' does not exist: /home/yii2/public_html/backend/messages/it-IT/app.php Fallback file does not exist as well: /home/yii2/public_html/backend/messages/it/app.php
/home/yii2/public_html/backend/views/layouts/main.php (41)
/home/yii2/public_html/vendor/dektrium/yii2-user/controllers/AdminController.php (93)

What I can see is that user module is loaded before the translatemanager one

moltam commented 9 years ago

Hi!

The Yii's I18N module configures the 'yii', and 'app' category default to use PhpMessageSource. You can read about this in the $translations property description.

Because of this, when the extensions translates these categories during page rendering, the Yii looks for php message source files, but your translations are in a database table as the extension saves the translations to db.

To get this working you need to specify for categories like this to use the translate-manager's db source. For example:

'i18n' => [
    'translations' => [
        '*' => [
            'class' => 'yii\i18n\DbMessageSource',
            'db' => 'db',
            'sourceLanguage' => 'en-GB', // Developer language
            'sourceMessageTable' => '{{%language_source}}',
            'messageTable' => '{{%language_translate}}',
            'forceTranslation' => true,
            'cachingDuration' => 86400,
            'enableCaching' => false,
        ],
        'app' => [
            'class' => 'yii\i18n\DbMessageSource',
            'db' => 'db',
            'sourceLanguage' => 'en-GB', // Developer language
            'sourceMessageTable' => '{{%language_source}}',
            'messageTable' => '{{%language_translate}}',
            'forceTranslation' => true,
            'cachingDuration' => 86400,
            'enableCaching' => false,
        ],
        'yii' => [
            'class' => 'yii\i18n\DbMessageSource',
            'db' => 'db',
            'sourceLanguage' => 'en-GB', // Developer language
            'sourceMessageTable' => '{{%language_source}}',
            'messageTable' => '{{%language_translate}}',
            'forceTranslation' => true,
            'cachingDuration' => 86400,
            'enableCaching' => false,
        ],
    ],
],

For dektrium/yii2-user extension you need to do the same with the 'user*' category. The extension configures this category with php message source, if it's not defined in the I18N config. But this extension provides its own translation files, so if you want to use them, you don't have to overwrite its configuration.

ettolo commented 9 years ago

Great! Thank you!

masihfathi commented 7 years ago

thanks for your great help.