Example #1
0
 /**
  * @param MissingTranslationEvent $event
  */
 public static function missingTranslation(MissingTranslationEvent $event)
 {
     $sourceMessage = SourceMessage::find()->where('category = :category and message = binary :message', [':category' => $event->category, ':message' => $event->message])->with('messages')->one();
     if (!$sourceMessage) {
         $sourceMessage = new SourceMessage();
         $sourceMessage->setAttributes(['category' => $event->category, 'message' => $event->message], false);
         $sourceMessage->save(false);
     }
     $sourceMessage->initMessages();
     $messages = $sourceMessage->saveMessages();
     //        $missingTranslations = Yii::$app->cache->get(self::MISSING_TRANSLATIONS_KEY);
     //        $missingTranslations[] = [
     //            'category' => $event->category,
     //            'message' => $event->message,
     //            'messages' => $messages,
     //        ];
     //        Yii::$app->cache->set(self::MISSING_TRANSLATIONS_KEY, $missingTranslations);
 }
 /**
  * @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;
 }