harlangray / languageswitcher
Yii Framework 2.0 Component language switcher
Installs: 17
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Type:yii2-extension
Requires
- yiisoft/yii2: *
This package is not auto-updated.
Last update: 2025-03-11 19:07:36 UTC
README
Component for Yii2 language switcher
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist "harlangray/languageswitcher": "*"
or add
"harlangray/languageswitcher": "*"
to the require section of your composer.json
file.
Usage
Once the extension is installed, simply modify your application configuration as follows:
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
'languages' => [ 'en' => 'english', 'si' => 'සිංහල', 'ta' => 'தமிழ்' ]
and use
Yii::$app->lang->getMenuItems()
In your menu "items"
EX:
echo Nav::widget([
'options' => ['class' => 'navbar-nav navbar-right'],
'items' => [
['label' => 'Home', 'url' => ['/site/index']],
........
.........
........
Yii::$app->lang->getMenuItems()
],
]);
NavBar::end();