Ejemplo n.º 1
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()];
     }
 }
Ejemplo n.º 2
0
 public function resolveFile($file)
 {
     if (!is_file($file)) {
         throw new \yii\base\Exception('Source file not found.');
     }
     $data = json_decode(file_get_contents($file), true);
     foreach (Countries::find(1)->all() as $country) {
         $countryCode = strtoupper($country->iso_alpha2);
         if (isset($data[$countryCode])) {
             if (($message = $country->getAttribute($this->targetAttribute)) === null) {
                 throw new \yii\base\Exception('Bad target attribute value.');
             }
             Message::initDbMessage($this->category, $this->language, $message, $data[$countryCode]);
         }
     }
 }
 public function down()
 {
     $this->dropTable(Message::tableName());
     $this->dropTable(MessageSource::tableName());
 }
Ejemplo n.º 4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getMessage()
 {
     return $this->hasOne(Message::className(), ['id' => 'id']);
 }