├── img └── flags │ ├── classic │ ├── br.png │ ├── ca.png │ ├── ch.png │ ├── de.png │ ├── en.png │ ├── es.png │ ├── fr.png │ ├── in.png │ ├── it.png │ ├── ja.png │ ├── ne.png │ ├── pr.png │ ├── ru.png │ └── us.png │ └── rounded │ ├── br.png │ ├── ca.png │ ├── ch.png │ ├── de.png │ ├── en.png │ ├── es.png │ ├── fr.png │ ├── in.png │ ├── it.png │ ├── ja.png │ ├── ne.png │ ├── pr.png │ ├── ru.png │ └── us.png ├── composer.json ├── widgets ├── views │ ├── languageClassic.php │ └── languageSelector.php └── MultiLanguageWidget.php └── README.md /img/flags/classic/br.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cinghie/yii2-multilanguage/HEAD/img/flags/classic/br.png -------------------------------------------------------------------------------- /img/flags/classic/ca.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cinghie/yii2-multilanguage/HEAD/img/flags/classic/ca.png -------------------------------------------------------------------------------- /img/flags/classic/ch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cinghie/yii2-multilanguage/HEAD/img/flags/classic/ch.png -------------------------------------------------------------------------------- /img/flags/classic/de.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cinghie/yii2-multilanguage/HEAD/img/flags/classic/de.png -------------------------------------------------------------------------------- /img/flags/classic/en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cinghie/yii2-multilanguage/HEAD/img/flags/classic/en.png -------------------------------------------------------------------------------- /img/flags/classic/es.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cinghie/yii2-multilanguage/HEAD/img/flags/classic/es.png -------------------------------------------------------------------------------- /img/flags/classic/fr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cinghie/yii2-multilanguage/HEAD/img/flags/classic/fr.png -------------------------------------------------------------------------------- /img/flags/classic/in.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cinghie/yii2-multilanguage/HEAD/img/flags/classic/in.png -------------------------------------------------------------------------------- /img/flags/classic/it.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cinghie/yii2-multilanguage/HEAD/img/flags/classic/it.png -------------------------------------------------------------------------------- /img/flags/classic/ja.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cinghie/yii2-multilanguage/HEAD/img/flags/classic/ja.png -------------------------------------------------------------------------------- /img/flags/classic/ne.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cinghie/yii2-multilanguage/HEAD/img/flags/classic/ne.png -------------------------------------------------------------------------------- /img/flags/classic/pr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cinghie/yii2-multilanguage/HEAD/img/flags/classic/pr.png -------------------------------------------------------------------------------- /img/flags/classic/ru.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cinghie/yii2-multilanguage/HEAD/img/flags/classic/ru.png -------------------------------------------------------------------------------- /img/flags/classic/us.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cinghie/yii2-multilanguage/HEAD/img/flags/classic/us.png -------------------------------------------------------------------------------- /img/flags/rounded/br.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cinghie/yii2-multilanguage/HEAD/img/flags/rounded/br.png -------------------------------------------------------------------------------- /img/flags/rounded/ca.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cinghie/yii2-multilanguage/HEAD/img/flags/rounded/ca.png -------------------------------------------------------------------------------- /img/flags/rounded/ch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cinghie/yii2-multilanguage/HEAD/img/flags/rounded/ch.png -------------------------------------------------------------------------------- /img/flags/rounded/de.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cinghie/yii2-multilanguage/HEAD/img/flags/rounded/de.png -------------------------------------------------------------------------------- /img/flags/rounded/en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cinghie/yii2-multilanguage/HEAD/img/flags/rounded/en.png -------------------------------------------------------------------------------- /img/flags/rounded/es.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cinghie/yii2-multilanguage/HEAD/img/flags/rounded/es.png -------------------------------------------------------------------------------- /img/flags/rounded/fr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cinghie/yii2-multilanguage/HEAD/img/flags/rounded/fr.png -------------------------------------------------------------------------------- /img/flags/rounded/in.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cinghie/yii2-multilanguage/HEAD/img/flags/rounded/in.png -------------------------------------------------------------------------------- /img/flags/rounded/it.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cinghie/yii2-multilanguage/HEAD/img/flags/rounded/it.png -------------------------------------------------------------------------------- /img/flags/rounded/ja.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cinghie/yii2-multilanguage/HEAD/img/flags/rounded/ja.png -------------------------------------------------------------------------------- /img/flags/rounded/ne.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cinghie/yii2-multilanguage/HEAD/img/flags/rounded/ne.png -------------------------------------------------------------------------------- /img/flags/rounded/pr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cinghie/yii2-multilanguage/HEAD/img/flags/rounded/pr.png -------------------------------------------------------------------------------- /img/flags/rounded/ru.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cinghie/yii2-multilanguage/HEAD/img/flags/rounded/ru.png -------------------------------------------------------------------------------- /img/flags/rounded/us.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cinghie/yii2-multilanguage/HEAD/img/flags/rounded/us.png -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cinghie/yii2multilanguage", 3 | "description": "Multi Language support for Yii2 Framework.", 4 | "keywords": [ 5 | "yii2 multilanguage", 6 | "yii2 language", 7 | "yii2 lang", 8 | "yii2 translate" 9 | ], 10 | "homepage": "https://github.com/cinghie/yii2-multilanguage", 11 | "type": "yii2-extension", 12 | "license": "BSD-3-Clause", 13 | "authors": [ 14 | { 15 | "name": "Gogodigital.it", 16 | "email": "info@gogodigital.it", 17 | "homepage": "http://www.gogodigital.it/" 18 | } 19 | ], 20 | "require": { 21 | "yiisoft/yii2": "~2.0.14", 22 | "codemix/yii2-localeurls": "^1.8.0" 23 | }, 24 | "autoload": { 25 | "psr-4": { 26 | "cinghie\\multilanguage\\": "" 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /widgets/views/languageClassic.php: -------------------------------------------------------------------------------- 1 | 16 | 17 |
18 | 19 | getUrlManager()->parseRequest(Yii::$app->getRequest()); 22 | 23 | $params = ArrayHelper::merge($_GET, $params); 24 | $url = isset($params['route']) ? $params['route'] : $route; 25 | $html = ''; 26 | $ul = ''; 56 | 57 | echo $html; 58 | 59 | ?> 60 | 61 |
-------------------------------------------------------------------------------- /widgets/MultiLanguageWidget.php: -------------------------------------------------------------------------------- 1 | languages not defined 37 | if (!isset(Yii::$app->urlManager->languages)) { 38 | throw new InvalidConfigException("You must define Yii::\$app->urlManager->languages array like ['it', 'en', 'fr', 'de', 'es']"); 39 | } 40 | 41 | // Add Current Lang 42 | if(!$this->addCurrentLang) { 43 | $this->addCurrentLang = false; 44 | } 45 | 46 | // Icon Width 47 | if(!$this->width) { 48 | $this->width = '24'; 49 | } 50 | 51 | // Image Type 52 | if(!$this->image_type) { 53 | $this->image_type = 'classic'; 54 | } 55 | 56 | // Link Home 57 | if(!$this->link_home) { 58 | $this->link_home = false; 59 | } 60 | 61 | // Widget Type 62 | if(!$this->widget_type) { 63 | $this->widget_type = 'classic'; 64 | } 65 | } 66 | 67 | public function run($params = []) 68 | { 69 | $currentLang = Yii::$app->language; 70 | $languages = Yii::$app->urlManager->languages; 71 | 72 | if ((string)$this->widget_type === 'selector') { 73 | $renderView = 'languageSelector'; 74 | } else { 75 | $renderView = 'languageClassic'; 76 | } 77 | 78 | return $this->render($renderView, [ 79 | 'addCurrentLang' => $this->addCurrentLang, 80 | 'controller' => $this->calling_controller, 81 | 'currentLang' => $currentLang, 82 | 'image_type' => $this->image_type, 83 | 'languages' => $languages, 84 | 'link_home' => $this->link_home, 85 | 'width' => $this->width 86 | ]); 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /widgets/views/languageSelector.php: -------------------------------------------------------------------------------- 1 | 16 | 17 |
18 | 19 | 77 | 78 |
-------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Yii2 MultiLanguage 2 | 3 | ![License](https://img.shields.io/packagist/l/cinghie/yii2-multilanguage.svg) 4 | ![Latest Stable Version](https://img.shields.io/github/release/cinghie/yii2-multilanguage.svg) 5 | ![Latest Release Date](https://img.shields.io/github/release-date/cinghie/yii2-multilanguage.svg) 6 | ![Latest Commit](https://img.shields.io/github/last-commit/cinghie/yii2-multilanguage.svg) 7 | [![Total Downloads](https://img.shields.io/packagist/dt/cinghie/yii2-multilanguage.svg)](https://packagist.org/packages/cinghie/yii2-multilanguage) 8 | 9 | Multi Language support for Yii2 Framework based on this post on Official Forum:
10 | http://www.yiiframework.com/forum/index.php/topic/56027-yii2-multilingual-website-url-rules/ 11 | 12 | Installation 13 | ------------ 14 | 15 | The preferred way to install this extension is through [composer](http://getcomposer.org/download/). 16 | 17 | Either run 18 | 19 | ``` 20 | php composer.phar require cinghie/yii2-multilanguage "*" 21 | ``` 22 | 23 | or add this line to the require section of your `composer.json` file. 24 | 25 | ``` 26 | "cinghie/yii2-multilanguage": "*" 27 | ``` 28 | 29 | Configuration 30 | ----------------- 31 | 32 | Set in Configuration File: 33 | 34 | ``` 35 | // Language Settings 36 | 'language' => 'en', 37 | 'sourceLanguage' => 'en_GB', 38 | ``` 39 | 40 | Make sure you have set the parameter 'language': the default language will be that 41 | 42 | Set URL Manager in 'component' Configuration File: 43 | 44 | ``` 45 | // Url Manager 46 | 'urlManager' => [ 47 | 'class' => 'codemix\localeurls\UrlManager', 48 | 'languages' => ['en', 'it', 'fr', 'de', 'es'], // List all supported languages here 49 | 'enablePrettyUrl' => true, 50 | 'showScriptName' => false, 51 | ], 52 | ``` 53 | 54 | Images 55 | ----------------- 56 | 57 | Copy the img folder from the project root to your web folders to see flag's images 58 | 59 | Widgets 60 | ----------------- 61 | 62 | You can load the MultiLanguage Widget in the your view like this: 63 | 64 | ``` 65 | true, // add current lang 67 | 'calling_controller' => $this->context, 68 | 'image_type' => 'classic', // classic or rounded 69 | 'link_home' => true, // true or false 70 | 'widget_type' => 'classic', // classic or selector 71 | 'width' => '28' 72 | ]); ?> 73 | ``` 74 | 75 | There are 4 params in the Widget: 76 | * Widget Type can be classic or selector 77 | * Image Type can be classic or rounded 78 | * Width in pixel of the flags 79 | * The Calling Controller (Do not Edit) 80 | 81 | Changelog 82 | ----------------- 83 | 84 | 94 | --------------------------------------------------------------------------------