/** * @param MissingTranslationEvent $event */ public static function missingTranslation(MissingTranslationEvent $event) { $sourceMessage = static::getSourceMessage($event); if (!$sourceMessage) { $sourceMessage = new SourceMessage(); $sourceMessage->setAttributes(['category' => $event->category, 'message' => $event->message], false); $sourceMessage->save(false); } $sourceMessage->initMessages(); $sourceMessage->saveMessages(); }
/** * @param string $category * @param string $message * @return SourceMessage */ private function getSourceMessage($category, $message) { $params = ['category' => $category, 'message' => $message]; $sourceMessage = SourceMessage::find()->where($params)->with('messages')->one(); if (!$sourceMessage) { $sourceMessage = new SourceMessage(); $sourceMessage->setAttributes($params, false); $sourceMessage->save(false); } return $sourceMessage; }