예제 #1
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();
 }
예제 #2
0
 /**
  * @return array
  */
 protected function getMessageSourceConfig()
 {
     $defaults = ['class' => DbMessageSource::className()];
     if ($this->handleMissing) {
         $defaults['on missingTranslation'] = ['metalguardian\\i18n\\components\\TranslationEventHandler', 'handleMissingTranslation'];
     }
     return ArrayHelper::merge($defaults, $this->messageSourceConfig);
 }
예제 #3
0
 /**
  * @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();
 }
예제 #4
-1
파일: I18N.php 프로젝트: athl64/yii2-i18n
 /**
  * @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();
 }