Exemple #1
0
 /**
  * @throws InvalidConfigException
  */
 public function init()
 {
     if (!isset($this->translations['*'])) {
         $this->translations['*'] = ['class' => 'yii\\i18n\\PhpMessageSource'];
     }
     parent::init();
 }
Exemple #2
0
 /**
  * @throws InvalidConfigException
  */
 public function init()
 {
     if (!$this->languages) {
         throw new InvalidConfigException('You should configure i18n component [language]');
     }
     if (empty($this->defaultLanguage)) {
         $this->defaultLanguage = Yii::$app->language;
     }
     if (empty($this->languageSessionKey)) {
         $this->languageSessionKey = 'language';
     }
     if (empty($this->languageParam)) {
         $this->languageParam = 'language';
     }
     if (!isset($this->translations['*'])) {
         $this->translations['*'] = ['class' => DbMessageSource::className(), 'sourceMessageTable' => $this->sourceMessageTable, 'messageTable' => $this->messageTable, 'on missingTranslation' => $this->missingTranslationHandler];
     }
     if (!isset($this->translations['app']) && !isset($this->translations['app*'])) {
         $this->translations['app'] = ['class' => DbMessageSource::className(), 'sourceMessageTable' => $this->sourceMessageTable, 'messageTable' => $this->messageTable, 'on missingTranslation' => $this->missingTranslationHandler];
     }
     if ($this->autoSetLanguage) {
         $this->setLanguage();
     } else {
         \Yii::$app->language = \Yii::$app->session->get($this->languageSessionKey, \Yii::$app->language);
     }
     parent::init();
 }
 /**
  * @throws \yii\base\InvalidConfigException
  */
 public function init()
 {
     if (!is_array($this->languages) || empty($this->languages)) {
         throw new \yii\base\InvalidConfigException('You should configure i18n component [language]');
     }
     parent::init();
 }
 /**
  * @throws InvalidConfigException
  */
 public function init()
 {
     parent::init();
     if ($this->languages instanceof \Closure) {
         $this->languages = call_user_func($this->languages);
     }
     if (!is_array($this->languages)) {
         throw new InvalidConfigException('\\metalguardian\\i18n\\components\\I18n::languages have to be array.');
     }
     if (empty($this->languages)) {
         throw new InvalidConfigException('\\metalguardian\\i18n\\components\\I18n::languages have to contains at least 1 item.');
     }
     $config = $this->getMessageSourceConfig();
     if (is_array($this->only)) {
         foreach ($this->only as $item) {
             if ($this->override || !isset($this->translations[$item]) && !isset($this->translations[$item . '*'])) {
                 $this->translations[$item] = $config;
             }
         }
     } else {
         if ($this->override) {
             $this->translations = ['*' => $config];
         }
     }
 }
Exemple #5
0
 /**
  * @inheritDoc
  */
 public function init()
 {
     parent::init();
     // TODO: Change the autogenerated stub
     if (!isset($this->translations['common/' . $this->suffix]) && !isset($this->translations['*'])) {
         $this->translations['common/' . $this->suffix] = ['class' => 'yii\\i18n\\PhpMessageSource', 'basePath' => '@modules/views/' . $this->suffix . '/messages', 'fileMap' => ['common/' . $this->suffix => 'common.php']];
     }
 }
Exemple #6
0
 public function init()
 {
     parent::init();
     if (!isset($this->translations['platform']) && !isset($this->translations['platform*'])) {
         $this->translations['platform'] = ['class' => 'yii\\i18n\\GettextMessageSource', 'sourceLanguage' => P::$app->sourceLanguage, 'basePath' => '@platform/messages'];
     }
     if (!isset($this->translations['db']) && !isset($this->translations['db*'])) {
         $this->translations['db'] = ['class' => 'yii\\i18n\\DbMessageSource', 'sourceLanguage' => P::$app->sourceLanguage, 'sourceMessageTable' => models\MessageSource::tableName(), 'messageTable' => models\Message::tableName()];
     }
 }
 /**
  * @throws InvalidConfigException
  */
 public function init()
 {
     if (!$this->languages) {
         throw new InvalidConfigException('You should configure i18n component [language]');
     }
     if (!isset($this->translations['*'])) {
         $this->translations['*'] = ['class' => DbMessageSource::className(), 'db' => $this->db, 'sourceMessageTable' => $this->sourceMessageTable, 'messageTable' => $this->messageTable, 'on missingTranslation' => $this->missingTranslationHandler];
     }
     if (!isset($this->translations['app']) && !isset($this->translations['app*'])) {
         $this->translations['app'] = ['class' => DbMessageSource::className(), 'db' => $this->db, 'sourceMessageTable' => $this->sourceMessageTable, 'messageTable' => $this->messageTable, 'on missingTranslation' => $this->missingTranslationHandler];
     }
     parent::init();
 }
Exemple #8
0
 public function init()
 {
     parent::init();
 }
Exemple #9
-1
 /**
  * @throws InvalidConfigException
  */
 public function init()
 {
     if (!$this->languages) {
         throw new InvalidConfigException('You should configure i18n component [language]');
     }
     if ($this->languages instanceof \Closure) {
         $this->languages = $this->languages->__invoke();
     }
     $cacheConfig = [];
     if ($this->enableCaching) {
         $this->cache = Instance::ensure($this->cache, Cache::className());
         $cacheConfig = ['cache' => $this->cache, 'cachingDuration' => $this->cachingDuration, 'enableCaching' => true];
     }
     $translationConfig = ['class' => DbMessageSource::className(), 'db' => $this->db, 'sourceMessageTable' => $this->sourceMessageTable, 'messageTable' => $this->messageTable, 'on missingTranslation' => $this->missingTranslationHandler];
     $translationConfig = ArrayHelper::merge($translationConfig, $cacheConfig);
     if (!isset($this->translations['*'])) {
         $this->translations['*'] = $translationConfig;
     }
     if (!isset($this->translations['app']) && !isset($this->translations['app*'])) {
         $this->translations['app'] = $translationConfig;
     }
     parent::init();
 }