Code Monkey home page Code Monkey logo

yii2-language-switcher's Introduction

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.

yii2-language-switcher's People

Contributors

asetss avatar kmergen avatar newscloud avatar

Forkers

svfolder

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.