Beispiel #1
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();
         }
     }
 }
Beispiel #2
0
 /**
  * Updates an existing I18nSource model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param string $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $i18nSource = $this->findModel($id);
     $i18nMessage = I18nMessage::find()->where(['id' => $id, 'language' => Language::getCurrent()])->one();
     if (Yii::$app->request->isPost) {
         $transaction = Yii::$app->db->beginTransaction();
         try {
             $i18nSource->load(Yii::$app->request->post());
             if ($i18nSource->save()) {
                 $i18nMessage->load(Yii::$app->request->post());
                 if ($i18nMessage->save()) {
                     $transaction->commit();
                 }
             }
             return $this->redirect(['view', 'id' => $id]);
         } catch (\Exception $e) {
             $transaction->rollBack();
             return $this->redirect(['update', 'id' => $id]);
         }
     }
     return $this->render('update', ['i18nSource' => $i18nSource, 'i18nMessage' => $i18nMessage]);
 }
Beispiel #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getI18nMessage()
 {
     return $this->hasOne(I18nMessage::className(), ['id' => 'id'])->where(['language' => Language::getCurrent()]);
 }