diff --git a/components/I18N.php b/components/I18N.php index d52d616..0ae882a 100644 --- a/components/I18N.php +++ b/components/I18N.php @@ -116,4 +116,22 @@ class I18N extends \Zelenin\yii\modules\I18n\components\I18N */ public $catalog = 'messages'; + /** + * @throws InvalidConfigException + */ + public function init() + { + if (!$this->languages) { + throw new InvalidConfigException('You should configure i18n component [language]'); + } + + if (is_callable($this->languages)) { + $this->languages = call_user_func($this->languages); + } + if (!is_array($this->languages)) { + throw new InvalidConfigException('i18n component [language] must be an array or a callable returning an array'); + } + + parent::init(); + } } diff --git a/composer.json b/composer.json index d0723bb..61d40ee 100644 --- a/composer.json +++ b/composer.json @@ -1,45 +1,44 @@ { - "name": "uran1980/yii2-translate-panel", - "description": "Yii2 Translate Panel makes the translation of your application awesome!", - "version": "0.1.28", - "type": "yii2-extension", - "keywords": [ - "yii2", - "i18n", - "translation", - "translations", - "translate-panel" - ], - "homepage": "https://github.com/uran1980/yii2-translate-panel", - "time": "2015-03-11 17:30", - "license": "MIT", - "authors": [ - { - "name": "Ivan Yakovlev", - "email": "uran1980@gmail.com", - "homepage": "https://github.com/uran1980", - "role": "Developer" - } - ], - "support": { - "issues": "https://github.com/uran1980/yii2-translate-panel/issues", - "source": "https://github.com/uran1980/yii2-translate-panel" - }, - "require": { - "yiisoft/yii2": "~2", - "zelenin/yii2-i18n-module": "0.1.*", - "rmrevin/yii2-fontawesome": "*", - "uran1980/yii2-igrowl-widget": "*", - "uran1980/yii2-chosen-select": "*", - "uran1980/yii2-bootstrap-confirmation": "*", - "uran1980/yii2-jquery-essential": "*" - }, - "autoload": { - "psr-4": { - "uran1980\\yii\\modules\\i18n\\": "" - } - }, - "extra": { - "bootstrap": "uran1980\\yii\\modules\\i18n\\Bootstrap" - } -} + "name" : "uran1980/yii2-translate-panel", + "description" : "Yii2 Translate Panel makes the translation of your application awesome!", + "version" : "0.1.29", + "type" : "yii2-extension", + "keywords" : [ + "yii2", + "i18n", + "translation", + "translations", + "translate-panel" + ], + "homepage" : "https://github.com/uran1980/yii2-translate-panel", + "time" : "2015-03-11 17:30", + "license" : "MIT", + "authors" : [{ + "name" : "Ivan Yakovlev", + "email" : "uran1980@gmail.com", + "homepage" : "https://github.com/uran1980", + "role" : "Developer" + } + ], + "support" : { + "issues" : "https://github.com/uran1980/yii2-translate-panel/issues", + "source" : "https://github.com/uran1980/yii2-translate-panel" + }, + "require" : { + "yiisoft/yii2" : "~2", + "zelenin/yii2-i18n-module" : "0.1.*", + "rmrevin/yii2-fontawesome" : "*", + "uran1980/yii2-igrowl-widget" : "*", + "uran1980/yii2-chosen-select" : "*", + "uran1980/yii2-bootstrap-confirmation" : "*", + "uran1980/yii2-jquery-essential" : "*" + }, + "autoload" : { + "psr-4" : { + "uran1980\\yii\\modules\\i18n\\" : "" + } + }, + "extra" : { + "bootstrap" : "uran1980\\yii\\modules\\i18n\\Bootstrap" + } +} \ No newline at end of file diff --git a/controllers/DefaultController.php b/controllers/DefaultController.php index 2137663..cb79739 100644 --- a/controllers/DefaultController.php +++ b/controllers/DefaultController.php @@ -5,6 +5,7 @@ use Yii; use yii\base\Model; use uran1980\yii\modules\i18n\Module; +use uran1980\yii\modules\i18n\models\SourceMessage; use uran1980\yii\modules\i18n\models\search\SourceMessageSearch; use uran1980\yii\modules\i18n\helpers\AppHelper; use yii\helpers\Html; @@ -184,4 +185,22 @@ public function actionRestore($id) return $response; } + + /** + * @param array|integer $id + * @return SourceMessage|SourceMessage[] + * @throws NotFoundHttpException + */ + protected function findModel($id) + { + $query = SourceMessage::find()->where('id = :id', [':id' => $id]); + $models = is_array($id) + ? $query->all() + : $query->one(); + if (!empty($models)) { + return $models; + } else { + throw new NotFoundHttpException(Module::t('The requested page does not exist')); + } + } } diff --git a/models/SourceMessage.php b/models/SourceMessage.php index 7cc2f73..1ab5de2 100644 --- a/models/SourceMessage.php +++ b/models/SourceMessage.php @@ -57,7 +57,7 @@ public function attributeLabels() return [ 'id' => Module::t('ID'), 'category' => Module::t('Category'), - 'message' => Module::t('Sourse Messages'), + 'message' => Module::t('Source Messages'), 'translation' => Module::t('Message Translations'), 'status' => Module::t('Translation status') ]; @@ -92,7 +92,7 @@ public static function getCategories() public function initMessages() { $messages = []; - foreach (Yii::$app->getI18n()->languages as $language) { + foreach (Yii::$app->i18n->languages as $language) { if (!isset($this->messages[$language])) { $message = new Message; $message->language = $language; diff --git a/views/default/_message-tabs.php b/views/default/_message-tabs.php index 4098ea4..91ab0c2 100644 --- a/views/default/_message-tabs.php +++ b/views/default/_message-tabs.php @@ -4,11 +4,8 @@ use yii\bootstrap\Tabs; $items = []; -if (is_callable(Yii::$app->i18n->languages)) { - $languages = call_user_func(Yii::$app->i18n->languages); -} else { - $languages = Yii::$app->i18n->languages; -} + +$languages = Yii::$app->i18n->languages; foreach ( $languages as $lang ) { $message = Yii::t($model->category, $model->message, [], $lang); $message = ($model->message == $message && $lang != $languages[0]) diff --git a/views/default/update.php b/views/default/update.php index 3a8dcb6..60f2995 100644 --- a/views/default/update.php +++ b/views/default/update.php @@ -25,7 +25,7 @@
messages as $language => $message) : ?> - field($model->messages[$language], '[' . $language . ']translation', ['options' => ['class' => 'form-group col-sm-6']])->textInput()->label($language); ?> + field($model->messages[$language], '[' . $language . ']translation', ['options' => ['class' => 'form-group col-sm-6']])->textInput()->label(strtoupper($language)); ?>