Skip to content

Commit

Permalink
init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
pceuropa committed Jan 1, 2017
1 parent b672411 commit 02b7c67
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 0 deletions.
10 changes: 10 additions & 0 deletions LanguageAsset.php
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',
];
}
61 changes: 61 additions & 0 deletions LanguageSelection.php
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(),
]
]);
}
}

?>
28 changes: 28 additions & 0 deletions composer.json
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\\": ""
}
}
}
12 changes: 12 additions & 0 deletions views/language-selection.php
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}"); ?>

0 comments on commit 02b7c67

Please sign in to comment.