Skip to content

newscloud/yii2-language-switcher

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Yii 2 Language Switcher

Yii2 extension for simple and flexible language switching via a given template

The preferred way to install this extension is through composer.

Either run

composer require "kmergen/yii2-language-switcher": "*"

or add

"kmergen/yii2-language-switcher": "*",

to the require section of your composer.json file.

Usage

Simple list

echo \kmergen\LanguageSwitcher::widget([

]);

Bootstrap dropdown Menu

echo \kmergen\LanguageSwitcher::widget([
                   'parentTemplate' => '<nav class="navbar-nav nav">
                    <li class="dropdown">{activeItem}
                        <ul class="dropdown-menu">{items}</ul>
                     </li>   
                 </nav>',
                 'activeItemTemplate' => '<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">{label} <span class="caret"></span></a>',
                 'itemTemplate' => '<li><a href="{url}">{label}</a></li>'
            ]);

Bootstrap dropdown Menu with flags

echo \kmergen\LanguageSwitcher::widget([
                   'parentTemplate' => '<nav class="navbar-nav nav">
                    <li class="dropdown">{activeItem}
                        <ul class="dropdown-menu">{items}</ul>
                     </li>   
                 </nav>',
                 'activeItemTemplate' => '<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><i class="flag flag-{language}"></i> {label} <span class="caret"></span></a>',
                 'itemTemplate' => '<li><a href="{url}"><i class="flag flag-{language}"></i> {label}</a></li>'
            ]);

In the assets folder of this extension are a flags.png and a flags.css file which you can implement in your project template. We do not register these assets directly with the extension to keep it as flexible as possible.

Note: This widget get the languages from the extension Yii2 LocaleUrls. Therefore you may configure localeUrls first before you run the widget.

About

A Yii2 Language Switcher widget

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 72.0%
  • CSS 28.0%