From d18ab05cec17b8483df88a3840e08b271f797282 Mon Sep 17 00:00:00 2001 From: Cloud User Date: Thu, 11 Jun 2015 08:09:29 +0000 Subject: [PATCH] fix language configured in widget options --- ImperaviRedactorAsset.php | 16 ++++++++++------ Widget.php | 3 ++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/ImperaviRedactorAsset.php b/ImperaviRedactorAsset.php index 890323a..28a2fa0 100644 --- a/ImperaviRedactorAsset.php +++ b/ImperaviRedactorAsset.php @@ -15,6 +15,7 @@ */ class ImperaviRedactorAsset extends AssetBundle { + public $language; public $sourcePath = '@yii/imperavi/assets'; public $js = [ 'redactor.js' @@ -26,13 +27,16 @@ class ImperaviRedactorAsset extends AssetBundle 'yii\web\JqueryAsset' ]; - public function init() { - + public function registerAssetFiles($view) { $appLanguage = strtolower(substr(Yii::$app->language , 0, 2)); //First 2 letters - if($appLanguage != 'en') - $this->js[] = 'lang/' . $appLanguage . '.js'; - - parent::init(); + //check if the language configured or use appLanguage instead + $language = $this->language ? $this->language : $appLanguage; + $languageJs = 'lang/' . $language . '.js'; + if($language != 'en'){ + $this->js[] = $languageJs; + } + + parent::registerAssetFiles($view); } } diff --git a/Widget.php b/Widget.php index 1bfb05f..5076847 100644 --- a/Widget.php +++ b/Widget.php @@ -89,7 +89,8 @@ public function run() echo Html::textarea($this->attribute, $this->value, $this->htmlOptions); } - ImperaviRedactorAsset::register($this->getView()); + //register asset and configure language from options + ImperaviRedactorAsset::register($this->getView())->language = $this->options['lang']; $this->registerClientScript(); }