lajax / yii2-translate-manager

Translation Manager
MIT License
227 stars 90 forks source link

Not work with dmstr/yii2-adminlte-asset #76

Closed tedyonly closed 8 years ago

tedyonly commented 8 years ago

I use "dmstr/yii2-adminlte-asset": "2.*". put on top " use lajax\translatemanager\helpers\Language; \lajax\translatemanager\helpers\Language::registerAssets(); use lajax\translatemanager\helpers\Language as Lx; "

Trying to put Lx::t('app','User Management') the error message " Class 'Lx' not found ".

It's ok for original Yii2 Advance Framework. How to solve this ?

moltam commented 8 years ago

It works fine for me, even if I install the dmstr/yii2-adminlte-asset package.

Can you post a detailed example (view file, config, etc.)?

Side note: You can simplify your above code like this:

use lajax\translatemanager\helpers\Language as Lx;

Lx::registerAssets();
tedyonly commented 8 years ago

config like this: <?php return [ //Default 'vendorPath' => dirname(dirname(DIR)) . '/vendor',

'bootstrap' => [
    'languagepicker',           
    'translatemanager'
    ],      
'sourceLanguage' => 'en-US',        
'components' => [
    //Default
    'cache' => [
        'class' => 'yii\caching\FileCache',
    ],

    '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,
            ],
            'app' => [
                'class' => 'yii\i18n\DbMessageSource',
                'db' => 'db',
                'sourceLanguage' => 'en-US', // Developer language
                'sourceMessageTable' => '{{%language_source}}',
                'messageTable' => '{{%language_translate}}',
                'forceTranslation' => true,
                'cachingDuration' => 86400,
                'enableCaching' => false,
            ],
            'yii' => [
                'class' => 'yii\i18n\DbMessageSource',
                'db' => 'db',
                'sourceLanguage' => 'en-US', // Developer language
                'sourceMessageTable' => '{{%language_source}}',
                'messageTable' => '{{%language_translate}}',
                'forceTranslation' => true,
                'cachingDuration' => 86400,
                'enableCaching' => false,
            ],
        ],
    ],

    // lajax language picker translatemanager
    'languagepicker' => [
            'class' => 'lajax\languagepicker\Component',
            'languages' => function () {                       
                return \lajax\translatemanager\models\Language::getLanguageNames(true);
            },
            'cookieName' => 'language',                       
            'expireDays' => 64,                                
            'callback' => function() {
                if (!\Yii::$app->user->isGuest) {
                    $user = \Yii::$app->user->identity;
                    $user->language = \Yii::$app->language;
                    $user->save();
                }
            }
        ],  

    'urlManager' => [
        'enablePrettyUrl' => true,
        'showScriptName' => false,
        'rules' => [
            // your rules go here
            ],
            // ...
    ],

],

'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' => ['*'],          // 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
            ],
        ]
    ],
],

];

view file, for header.php I put on top like this as your suggestion; use lajax\translatemanager\helpers\Language as Lx; Lx::registerAssets();

view file, for left.php I just cut the file only to show you the point; <?= dmstr\widgets\Menu::widget( [

            'options' => ['class' => 'sidebar-menu'],
            'items' => [
                ['label' => Lx::t('app','Menu Yii2'), 'options' => ['class' => 'header']],

---end---

moltam commented 8 years ago

There is no use statement in left.php? You should use the Language helper class every view file, where you need it (not only header.php).

tedyonly commented 8 years ago

It works, thank you.