PHP code example of demondogsl / yii2-translate-manager

1. Go to this page and download the library: Download demondogsl/yii2-translate-manager library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

demondogsl / yii2-translate-manager example snippets


'modules' => [
    'translateManager' => [
        'class' => 'DemonDogSL\translateManager\Module',    //  instances. For example: ['@backend', '@common', '@frontend']. For Default is '@app'
        'allowedIPs' => ['0.0.0.0'],  // optional     IP addresses from which the translation interface is accessible. For Default is ['127.0.0.1']
        'roles' => ['@'],   // optional     For setting access levels to the translating interface. For Default is []
        'tmpDir' => '@example',     // optional     Writable directory for the client-side temporary javascript language files. Can be '@backend/runtime'. For Default is '@runtime'
        'ignoredCategories' => ['example'],     // optional     These categories won't be scanned. For Default is ['yii']
        'onlyCategories' => ['example'],    // optional     Only these categories will be scanned. For Default is []
        'ignoredItems' => ['example'],   // optional     These files will not be processed. For Default is ['.svn', '.git', '.gitignore', '.gitkeep', '.hgignore', '.hgkeep', '/messages', '/BaseYii.php', 'runtime', 'bower', 'nikic']
        'tables' => [   // optional     Database Tables that will be scanned. For Default not exists
            [
                'connection' => 'db',
                'table' => '{{%example}}',     // Table name
                'columns' => ['example1', 'example2'],    // Names of columns
                'category' => 'database-table-name',
            ]
        ],
    ],
],

'tables' => [
    [
        'connection' => 'db',
        'table' => 'language_force_translation',
        'columns' => ['value'],
        'category' => 'database-table-name'
    ]
]

'components' => [
    'translateManager' => [
        'class' => 'DemonDogSL\translateManager\Component'
    ]
]

'bootstrap' => [
    'translateManager' => [
        'class' => 'DemonDogSL\translateManager\Component'
    ],
],

'language' => 'en-GB',
'components' => [
    'i18n' => [
        'translations' => [
            '*' => [
                'class' => 'yii\i18n\DbMessageSource',
                'db' => 'db',
                'sourceLanguage' => 'xx-XX',    // Your language
                'sourceMessageTable' => '{{%language_source}}',
                'messageTable' => '{{%language_translate}}',
                'cachingDuration' => 86400,
                'enableCaching' => true,
            ],
        ],
    ],
],

\DemonDogSL\translateManager\helpers\Language::registerAssets();

namespace backend\controllers;

use DemonDogSL\translateManager\helpers\Language;

class Controller extends \yii\web\Controller {

    public function init() {
        Language::registerAssets();
        parent::init();
    }
}

// Default
echo \DemonDogSL\translateManager\widgets\ToggleTranslate::widget();

// If you want change position
echo \DemonDogSL\translateManager\widgets\ToggleTranslate::widget([
    'position' => 'example',  // optional   Can be 'top-left', 'top-right', 'bottom-left' or 'bottom-right'. For Default is 'bottom-left'
]);

ddt.t('Hello');
ddt.t('Hello {name}!', {name:'World'});

Yii::t('example', 'Hello');
Yii::t('example', 'Hello {name}!', ['name' => 'World']);

use DemonDogSL\translateManager\models\DDT;

DDT::t('example', 'Hello');
DDT::t('example', 'Hello {name}!', ['name' => 'World']);

/translateManager/language/list
/translateManager/language/scan
/translateManager/language/optimize
/translateManager/language/import
/translateManager/language/export

php yii migrate --migrationPath vendor/demondogsl/yii2-translate-manager/migrations