PHP code example of kialex / yii2-translation-center

1. Go to this page and download the library: Download kialex/yii2-translation-center 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/ */

    

kialex / yii2-translation-center example snippets




$translateCenter = \Yii::createObject(\Kialex\TranslateCenter\Client::class);
$translateCenter->createResource([
    [
        'key' => 'someKey',
        'value' => 'someValue',
        'tags' => ['category1', 'category2']
    ],
    [
        'key' => 'someKey1',
        'value' => 'someValue1',
        'tags' => ['category3', 'category4']
    ]
], 'ru');
// Fetch 1st page resources (default 300 sources) with langs `ru`, `en` and `someGroup1` tag
$translateCenter->fetch([
    'langs' => 'ru,en',
    'tags' => 'someGroup1'
], 1);

...
'components' => [
    ...
    'i18n' => [
        'translations' => [
            'app*' => [
                'class' => 'yii\i18n\PhpMessageSource', // default Yii transaltion
                'fileMap' => [
                    'app'       => 'app.php',
                    'app/error' => 'error.php',
                ],
            ],
            '*' => [
                'class' => '\yii\i18n\JsonMessageSource', // Your tranlation fron Translate Center
                'basePath' => '@common/messages'
                // If you change this path, you shoud change it in// 
            // `\Kialex\TranslateCenter\Storage\JsonFileStorage` as well
                    // You may do it via singletons or defenations in config
            ],
        ],
    ]
]
...
bash
# Install Composer
curl -sS https://getcomposer.org/installer | php

/app/common/config/main.php
...php
'container' => [
        'singletons' => [
            'Kialex\TranslateCenter\Client' => [
                [],
                [
                    [
                        'login' => '[email protected]',
                        'password' => 'qwerty',
                        'projectUuid' => 'xxxxxx-fxxx-4xx2-8c0a-35axxxxxx8'
                    ],
                ]
            ]
        ]
    ],
...

/app/console/config/main.php
...
'controllerMap' => [
        ...
        'translate-center' => [
            ...
            'staticStorageClass' => \Kialex\TranslateCenter\Storage\RedisStorage,
            ...
          ],
    ],
...