harlangray/languageswitcher

Yii Framework 2.0 Component language switcher

Installs: 17

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 2

Forks: 0

Open Issues: 0

Type:yii2-extension

1.0.0 2015-01-22 05:52 UTC

This package is not auto-updated.

Last update: 2024-06-04 15:13:47 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();