lajax / yii2-translate-manager

Translation Manager
MIT License
227 stars 90 forks source link

Menu Translation #24

Closed rahulk-k closed 9 years ago

rahulk-k commented 9 years ago

Hi, I'm using yii2 advanced template. but menu translation is not working. I'm using Yii::t('language', 'Home'); or Lx::t('language', 'Home') in frontend view.

lajax commented 9 years ago

Hi! Where do you set the language of the application?

rahulk-k commented 9 years ago

Here is my common\config\main.php code

'language' => 'hi-IN', // hindi-india language 'modules' => [ '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' => ['127.0.0.1'], // IP addresses from which the translation interface is accessible. 'roles' => ['admin'], // 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 'tables' => [ // Properties of individual tables [ 'connection' => 'db', // connection identifier 'table' => 'language', // table name 'columns' => ['name', 'name_ascii'] //names of multilingual fields ] ] ], ], 'components' => [

    'urlManager'=>[
        'enablePrettyUrl'=>true,
        'showScriptName'=>false,

    ],

    'authManager' => [
        'class' => 'yii\rbac\DbManager',
    ],
    'i18n' => [
        'translations' => [
            '*' => [
                'class' => 'yii\i18n\DbMessageSource',
                'db' => 'db',
                'sourceLanguage' => 'en-US', // Developer language
                'sourceMessageTable' => 'language_source',
                'messageTable' => 'language_translate',
                'cachingDuration' => 86400,
                'enableCaching' => true,
            ],
        ],
    ],

frontend\config\main.php

.......... 'bootstrap' => ['translatemanager'],
'components' => [ 'translatemanager' => [ 'class' => 'lajax\translatemanager\Component' ],

...

frontend\views\layout\main.php ... $menuItems = [ ['label' => Yii::t('language', 'Home'), 'url' => ['/site/index']], ['label' => Yii::t('language','About'), 'url' => ['/site/about']], ['label' => Yii::t('language','Contact'), 'url' => ['/site/contact']], ]; ...

lajax commented 9 years ago

Hi!

Try this configs:

'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' => ['127.0.0.1'], // IP addresses from which the translation interface is accessible.
    'roles' => ['admin'], // 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
    'tables' => [ // Properties of individual tables
        [
            'connection' => 'db', // connection identifier
            'table' => 'language', // table name
            'columns' => ['name', 'name_ascii'] //names of multilingual fields
        ]
    ]
]

Best Regards

rahulk-k commented 9 years ago

Hi @lajax Thanks for your comment.I noticed that when we run yii2 application it stores cache file for each page within @frontend/runtime/cache folders.It loads the contents from that file for each word translation.i removed cache,debug,html etc folder and re-run application, It works fine.