/** * Finds the Message model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @param string $language * @return Message the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id, $language) { if (($model = Message::findOne(['id' => $id, 'language' => $language])) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @param $attributes * @param MissingTranslationEvent $event * @return bool */ protected static function saveMessage($attributes, MissingTranslationEvent $event) { /** @var Message $message */ $message = Message::findOne(['language' => $attributes['language'], 'id' => $attributes['id']]); if (!$message) { $message = new Message(); } $message->attributes = $attributes; if ($event->category === 'app' && $attributes['language'] === Language::getDefaultLanguage()->varCode) { $message->translation = $event->message; } elseif ($event->category === 'admin') { $message->translation = self::$autoTranslate ? (new ApiTranslation($message->language))->run($event->message) : $event->message; } return $message->save(); }