2017 © Pedro Peláez
 

yii2-extension yii2-language-switcher

A simple and flexible language switcher

image

kmergen/yii2-language-switcher

A simple and flexible language switcher

  • Sunday, December 31, 2017
  • by kmergen
  • Repository
  • 1 Watchers
  • 3 Stars
  • 280 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 1 Open issues
  • 2 Versions
  • 7 % Grown

The README.md

Yii 2 Language Switcher

Yii2 extension for simple and flexible language switching via a given template, (*1)

The preferred way to install this extension is through composer., (*2)

Either run, (*3)

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

or add, (*4)

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

to the require section of your composer.json file., (*5)

Usage

Simple list

echo \kmergen\LanguageSwitcher::widget([

]);

Bootstrap 3 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 3 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>'
            ]);

Bootstrap 4 dropdown Menu

<?= \kmergen\LanguageSwitcher::widget([
                'parentTemplate' => '<li class="nav-item dropdown">{activeItem}                               
                    <div class="dropdown-menu" aria-labelledby="navbarDropdownLanguageMenuLink">{items}</div></li>',
                'activeItemTemplate' => '<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">{label}</a>',
                'itemTemplate' => '<a class="dropdown-item" href="{url}">{label}</a>'
                ]); ?>

Bootstrap 4 dropdown Menu with flags

<?= \kmergen\LanguageSwitcher::widget([
                'parentTemplate' => '<li class="nav-item dropdown">{activeItem}                               
                    <div class="dropdown-menu" aria-labelledby="navbarDropdownLanguageMenuLink">{items}</div></li>',
                'activeItemTemplate' => '<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">{label}</a>',
                'itemTemplate' => '<a class="dropdown-item" href="{url}"><i class="flag flag-{language}"></i> {label}</a>'
                ]); ?>

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., (*6)

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

The Versions

31/12 2017

dev-master

9999999-dev

A simple and flexible language switcher

  Sources   Download

BSD-3-Clause

The Requires

 

by Klaus Megen

language extension yii2 yii language-switcher

31/12 2017

2.0.x-dev

2.0.9999999.9999999-dev

A simple and flexible language switcher

  Sources   Download

BSD-3-Clause

The Requires

 

by Klaus Megen

language extension yii2 yii language-switcher