Exemplo n.º 1
0
 /**
  * Finds the I18nSource model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return I18nSource the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = I18nSource::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemplo n.º 2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = I18nSource::find()->joinWith('i18nMessage');
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['like', 'category', $this->category])->andFilterWhere(['like', 'translation', $this->translation])->andFilterWhere(['like', 'message', $this->message]);
     return $dataProvider;
 }
Exemplo n.º 3
0
 public static function handleMissingTranslation(MissingTranslationEvent $event)
 {
     $i18nSource = I18nSource::findOne(['category' => $event->category, 'message' => $event->message]);
     if ($i18nSource === null) {
         $i18nSource = new I18nSource();
         $i18nSource->category = $event->category;
         $i18nSource->message = $event->message;
         $i18nSource->save();
     }
     foreach (Language::listing() as $language) {
         $i18nMessage = I18nMessage::findOne(['id' => $i18nSource->id, 'language' => $language['iso']]);
         if ($i18nMessage === null) {
             $i18nMessage = new I18nMessage();
             $i18nMessage->id = $i18nSource->id;
             $i18nMessage->language = $language['iso'];
             $i18nMessage->translation = $event->message;
             $i18nMessage->save();
         }
     }
 }
Exemplo n.º 4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getId()
 {
     return $this->hasOne(I18nSource::className(), ['id' => 'id']);
 }