diff --git a/LanguageAsset.php b/LanguageAsset.php new file mode 100644 index 0000000..a0663a6 --- /dev/null +++ b/LanguageAsset.php @@ -0,0 +1,10 @@ +language === null) { + $this->language = ['en']; + } + + if ($this->languageParam === null) { + $this->languageParam = ['language']; + } + + LanguageAsset::register($this->view); + $this->url = $this->view->assetBundles[LanguageAsset::className()]->baseUrl; + } + + public function run(){ + return $this->widgetRender(); + } + + public function patchFlag($lang){ + return $this->url .'/images/flags/'.$lang.'.png'; + } + + public function allFlag(){ + $items = ''; + + foreach ($this->language as $key => $value) { + if (Yii::$app->language != $value){ + $img = Html::img( $this->patchFlag($value)); + $a = Html::a ($img , ['', $this->languageParam => $value] ); + $items .= Html::tag('li',$a ); + } + } + + return $items; + } + + public function widgetRender(){ + + return $this->render('language-selection', [ + 'flags' => [ + 'now' => $this->patchFlag(Yii::$app->language), + 'all' => $this->allFlag(), + ] + ]); + } +} + +?> diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..e9e1dfe --- /dev/null +++ b/composer.json @@ -0,0 +1,28 @@ +{ + "name": "pceuropa/yii2-language-selection-widget", + "description": "Menu dropdown to select languages", + "keywords": [ + "yii2", + "extension", + "dropmenu", + "flag icons", + "bootstrap menu" + ], + "version": "1.0.0", + "homepage": "https://github.com/pceuropa/yii2-language-selection-widget.git", + "type": "yii2-extension", + "license": "MIT", + "minimum-stability": "dev", + "authors": [ + { + "name": "Rafal Marguzewicz", + "email": "info@pceuropa.net", + "homepage": "https://pceuropa.net/" + } + ], + "autoload": { + "psr-4": { + "pceuropa\\language-selection\\": "" + } + } +} diff --git a/views/language-selection.php b/views/language-selection.php new file mode 100644 index 0000000..725696f --- /dev/null +++ b/views/language-selection.php @@ -0,0 +1,12 @@ +'; +?> +