2017 © Pedro PelĂĄez
 

yii2-extension yii2-language-picker

Yii2 Language Picker Widget

image

lajax/yii2-language-picker

Yii2 Language Picker Widget

  • Sunday, March 25, 2018
  • by lajax
  • Repository
  • 10 Watchers
  • 31 Stars
  • 29,570 Installations
  • CSS
  • 2 Dependents
  • 0 Suggesters
  • 23 Forks
  • 6 Open issues
  • 10 Versions
  • 10 % Grown

The README.md

Yii2 Language Picker

Yii2 Language Picker Widget, (*1)

Introduction

The widget provides an easy to use language selector which makes it possible to change the language of our website easily. The language change can take place synchronously or asynchronously (through Ajax). The default method is asynchronous (through an Ajax call), however when this method fails for any reason (e.g. JavaScript is blocked on the client side) the new language will actualise synchronously through an automatic page reload., (*2)

The language switcher is fully customisable. However, the pre-defined options provide a dropdown list (DropDownList), and a link-based list (ButtonList). Both versions can display the name of the chosen language and the corresponding flag (icon)., (*3)

Installation

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

composer require lajax/yii2-language-picker

Config:

Identifier of the language element. e.g.: en, en-US, (*5)

IMPORTANT

To use the widget, the value of the enablePrettyUrl property in the urlManager configuration must be true, and the value of showScriptName false., (*6)

example:, (*7)

'components' => [
    // ...
    'urlManager' => [
        'enablePrettyUrl' => true,
        'showScriptName' => false,
        'rules' => [
            // your rules go here
        ],
        // ...
    ],
    // ...
]

Using of urlManager., (*8)

Minimal configuration (icons only)

'language' => 'en',
'bootstrap' => ['languagepicker'],
'components' => [
    'languagepicker' => [
        'class' => 'lajax\languagepicker\Component',
        // List of available languages (icons only)
        'languages' => ['en', 'de', 'fr'],
    ]
],

Minimal configuration (icons and text)

'language' => 'en',
'bootstrap' => ['languagepicker'],
'components' => [
    'languagepicker' => [
        'class' => 'lajax\languagepicker\Component',
        // List of available languages (icons and text)
        'languages' => ['en' => 'English', 'de' => 'Deutsch', 'fr' => 'Français']
    ]
],

Full configuration (icons only)

'language' => 'en-US',
'bootstrap' => ['languagepicker'],
'components' => [
    'languagepicker' => [
        'class' => 'lajax\languagepicker\Component',
        'languages' => ['en-US', 'de-DE', 'fr-FR'], // List of available languages (icons only)
        'cookieName' => 'language', // Name of the cookie.
        'cookieDomain' => 'example.com', // Domain of the cookie.
        'expireDays' => 64, // The expiration time of the cookie is 64 days.
        // Function to execute after changing the language
        'callback' => function() {
            if (!\Yii::$app->user->isGuest) {
                $user = \Yii::$app->user->identity;
                $user->language = \Yii::$app->language;
                $user->save();
            }
        }
    ]
],

Yii2-translate-manager integration

Minimal configuration (icons only)

'language' => 'en',
'bootstrap' => ['languagepicker'],
'components' => [
    'languagepicker' => [
        'class' => 'lajax\languagepicker\Component',
        // Get available languages from translate manager
        'languages' => function () {
            return array_keys(\lajax\translatemanager\models\Language::getLanguageNames(true));
        }
    ]
],

Minimal configuration (icons and text)

'language' => 'en',
'bootstrap' => ['languagepicker'],
'components' => [
    'languagepicker' => [
        'class' => 'lajax\languagepicker\Component',
        // Get available languages from translate manager
        'languages' => function () {
            return \lajax\translatemanager\models\Language::getLanguageNames(true);
        }
    ]
],

Usage

Displaying language selector

Displaying pre-defined languate picker buttons (icons and text or icons only):

<?= \lajax\languagepicker\widgets\LanguagePicker::widget([
    'skin' => \lajax\languagepicker\widgets\LanguagePicker::SKIN_BUTTON,
    'size' => \lajax\languagepicker\widgets\LanguagePicker::SIZE_SMALL
]); ?>

Displaying pre-defined languate picker dropdown list (icons and text or icons only):

<?= \lajax\languagepicker\widgets\LanguagePicker::widget([
    'skin' => \lajax\languagepicker\widgets\LanguagePicker::SKIN_DROPDOWN,
    'size' => \lajax\languagepicker\widgets\LanguagePicker::SIZE_LARGE
]); ?>

Customising the language picker:

<?= \lajax\languagepicker\widgets\LanguagePicker::widget([
    'itemTemplate' => '<li><a href="{link}" title="{language}"><i id="{language}"></i> {name}</a></li>',
    'activeItemTemplate' => '<a href="{link}" title="{language}"><i id="{language}"></i> {name}</a>',
    'parentTemplate' => '<div class="language-picker dropdown-list {size}"><div>{activeItem}<ul>{items}</ul></div></div>',
    'languageAsset' => 'lajax\languagepicker\bundles\LanguageLargeIconsAsset',      // StyleSheets
    'languagePluginAsset' => 'lajax\languagepicker\bundles\LanguagePluginAsset',    // JavaScripts
]); ?>

Screenshots

Buttons icons and text

language-picker-0 2-screen-1, (*9)

Buttons icons only

language-picker-0 2-screen-2, (*10)

Buttons text only

language-picker-0 2-screen-3, (*11)

language-picker-0 2-screen-4, (*12)

language-picker-0 2-screen-5, (*13)

language-picker-0 2-screen-5, (*14)

The Versions

25/03 2018

dev-master

9999999-dev

Yii2 Language Picker Widget

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Lajos Molnar

extension yii2 widget translate multilanguage sample languagepicker

25/03 2018

1.2.1

1.2.1.0

Yii2 Language Picker Widget

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Lajos Molnar

extension yii2 widget translate multilanguage sample languagepicker

01/09 2015

1.2.0

1.2.0.0

Yii2 Language Picker Widget

  Sources   Download

BSD-3-Clause

The Requires

 

by Lajos Molnar

extension yii2 widget translate multilanguage sample languagepicker

12/05 2015

1.1.5

1.1.5.0

Yii2 Language Picker Widget

  Sources   Download

BSD-3-Clause

The Requires

 

by Lajos Molnar

extension yii2 widget translate multilanguage sample languagepicker

26/04 2015

1.1.4

1.1.4.0

Yii2 Language Picker Widget

  Sources   Download

BSD-3-Clause

The Requires

 

by Lajos Molnar

extension yii2 widget translate multilanguage sample languagepicker

07/04 2015

1.1.2

1.1.2.0

Yii2 Language Picker Widget

  Sources   Download

BSD-3-Clause

The Requires

 

by Lajos Molnar

extension yii2 widget translate multilanguage sample languagepicker

05/04 2015

1.1.1

1.1.1.0

Yii2 Language Picker Widget

  Sources   Download

BSD-3-Clause

The Requires

 

by Lajos Molnar

extension yii2 widget translate multilanguage sample languagepicker

29/03 2015

1.1.0

1.1.0.0

Yii2 Language Picker Widget

  Sources   Download

BSD-3-Clause

The Requires

 

by Lajos Molnar

extension yii2 widget translate multilanguage sample languagepicker

25/03 2015

1.0.1

1.0.1.0

Yii2 Language Picker Widget

  Sources   Download

BSD-3-Clause

The Requires

 

by Lajos Molnar

extension yii2 widget translate multilanguage sample languagepicker

01/03 2015

1.0.0

1.0.0.0

Yii2 Language Picker Widget

  Sources   Download

BSD-3-Clause

The Requires

 

by Lajos Molnar

extension yii2 widget translate multilanguage sample languagepicker