PHP code example of razonyang / yii-translator-middleware

1. Go to this page and download the library: Download razonyang/yii-translator-middleware 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/ */

    

razonyang / yii-translator-middleware example snippets




declare(strict_types=1);

use RazonYang\Yii\TranslatorMiddleware\LocaleParser\CompositeParser;
use RazonYang\Yii\TranslatorMiddleware\LocaleParser\HeaderParser;
use RazonYang\Yii\TranslatorMiddleware\LocaleParser\QueryParamsParser;
use RazonYang\Yii\TranslatorMiddleware\LocaleParserInterface;
use RazonYang\Yii\TranslatorMiddleware\TranslatorMiddleware;
use Yiisoft\Definitions\Reference;
use Yiisoft\Translator\TranslatorInterface;

return [
    TranslatorMiddleware::class => [
        'class' => TranslatorMiddleware::class,
        '__construct()' => [
            Reference::to(LocaleParserInterface::class),
            Reference::to(TranslatorInterface::class),
        ],
    ],

    LocaleParserInterface::class => CompositeParser::class,
    CompositeParser::class => [
        'class' => CompositeParser::class,
        '__construct()' => [
            Reference::to(QueryParamsParser::class),
            Reference::to(HeaderParser::class),
        ],
    ],
    QueryParamsParser::class => [
        'class' => QueryParamsParser::class,
        '__construct()' => [
            'lang',
        ],
    ],
];