PHP code example of motion / yii2-language-provider

1. Go to this page and download the library: Download motion/yii2-language-provider 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/ */

    

motion / yii2-language-provider example snippets


$config = [
    'languages' => [
        [
            'label' => 'English',
            'locale' => 'en',
        ],
        [
            'label' => 'Ukrainian',
            'locale' => 'uk',
        ],
        [
            'label' => 'Russian',
            'locale' => 'ru',
        ],
    ],
    'defaultLanguage' => [
        'label' => 'English',
        'locale' => 'en',
    ],
];

$provider = new \motion\i18n\ConfigLanguageProvider($config);
$provider->getLanguages(); // returns list of languages
$provider->getDefaultLanguage(); // returns default language
$provider->getLanguageLabel('en'); // returns language label by locale (`English`)

$config = [
    'db' => 'secondDb',
    'labelField' => 'title',
];

$provider = new \motion\i18n\DbLanguageProvider($config);
$provider->getLanguages(); // returns list of languages
$provider->getDefaultLanguage(); // returns default language
$provider->getLanguageLabel('uk'); // returns language label by locale