/** * 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.'); } }
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(); } } }