PHP code example of w3lifer / yii2-i18n-js

1. Go to this page and download the library: Download w3lifer/yii2-i18n-js 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/ */

    

w3lifer / yii2-i18n-js example snippets

 php


return [
    // ...
    'components' => [
        'i18n' => [ // https://www.yiiframework.com/doc/guide/2.0/en/tutorial-i18n
            'translations' => [
                '*' => [
                    'class' => \yii\i18n\PhpMessageSource::class,
                ],
            ],
        ],
        'i18nJs' => [
            'class' => \w3lifer\Yii2\I18nJs::class,
        ],
        // ...
    ],
    // ...
];
 php


return [
    'Hello, World!' => 'Привет, Мир!',
    'Hello, {username}!' => 'Привет, {username}!',
    'Hello, {0} {1}!' => 'Привет, {0} {1}!',
];
 php


namespace app\controllers;

class I18nJsController extends \yii\web\Controller
{
    public function actionIndex(): string
    {
        return $this->render('index');
    }
}
 php
Yii::$app->i18nJs;
 php


/**
 * @see \app\controllers\I18nJsController::actionIndex()
 *
 * @var \yii\web\View $this
 *
 * @see http://localhost:809/i-18n-js
 */

Yii::$app->i18nJs;

Yii::$app->language = 'ru';

$this->title = 'I18nJs';