languageswitcher
Component for Yii2 language switcher, (*1)
Installation
The preferred way to install this extension is through composer., (*2)
Either run, (*3)
php composer.phar require --prefer-dist "harlangray/languageswitcher": "*"
or add, (*4)
"harlangray/languageswitcher": "*"
to the require section of your composer.json
file., (*5)
Usage
Once the extension is installed, simply modify your application configuration as follows:, (*6)
return [
'bootstrap' => ['lang'],
'components' => [
'lang' => [
'class' => 'harlangray\language\Language',
'queryParam' => 'lang',
],
// ...
],
...
];
You must define available languages in Yii::$app->params['languages']
as code => language in the config/params.php, (*7)
'languages' => [
'en' => 'english',
'si' => 'සිංහල',
'ta' => 'தமிழ்'
], (*8)
and use, (*9)
Yii::$app->lang->getMenuItems()
In your menu "items", (*10)
EX:
echo Nav::widget([
'options' => ['class' => 'navbar-nav navbar-right'],
'items' => [
['label' => 'Home', 'url' => ['/site/index']],
........
.........
........
Yii::$app->lang->getMenuItems()
],
]);
NavBar::end();, (*11)