-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
namespace pceuropa\language-selection; | ||
|
||
class LanguageAsset extends \yii\web\AssetBundle{ | ||
public $sourcePath = '@vendor/pceuropa/yii2-language-selection-widget/assets'; | ||
public $baseUrl = '@web'; | ||
public $depends = [ | ||
'yii\bootstrap\BootstrapAsset', | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
namespace pceuropa\language-selection\LanguageSelection; | ||
|
||
use Yii; | ||
use yii\helpers\Html; | ||
use pceuropa\language-selection\LanguageAsset; | ||
|
||
class LanguageSelection extends \yii\base\Widget { | ||
|
||
public $language; | ||
public $url; | ||
public $languageParam; | ||
|
||
public function init(){ | ||
parent::init(); | ||
if ($this->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(), | ||
] | ||
]); | ||
} | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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": "[email protected]", | ||
"homepage": "https://pceuropa.net/" | ||
} | ||
], | ||
"autoload": { | ||
"psr-4": { | ||
"pceuropa\\language-selection\\": "" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
use yii\helpers\Html; | ||
$img = Html::img($flags['now']) . ' <span class="caret"></span>'; | ||
?> | ||
<li class="dropdown"> | ||
<?= Html::a ($img, ['#'], [ 'class' => 'dropdown-toggle', 'data-toggle' => 'dropdown', 'role' => 'button', 'aria-haspopup' => 'true', 'aria-expanded' => 'false', ] ); ?> | ||
<ul class="dropdown-menu court"> | ||
<?= $flags['all']?> | ||
</ul> | ||
</li> | ||
|
||
<?php $this->registerCss(".court { width: 50px; min-width:50px}"); ?> |