/**
  * @param MissingTranslationEvent $event
  */
 public static function missingTranslation(MissingTranslationEvent $event)
 {
     $driver = Yii::$app->getDb()->getDriverName();
     $caseInsensitivePrefix = $driver === 'mysql' ? 'binary' : '';
     $sourceMessage = SourceMessage::find()->where('category = :category and message = ' . $caseInsensitivePrefix . ' :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();
     $sourceMessage->saveMessages();
 }
Exemplo n.º 2
0
 /**
  * @param MissingTranslationEvent $event
  */
 public static function missingTranslation(MissingTranslationEvent $event)
 {
     $i18n = Yii::$app->getI18n();
     if (isset($i18n->excludedCategories)) {
         $excludeCategories = $i18n->excludedCategories;
     } else {
         $excludeCategories = [];
     }
     $driver = Yii::$app->getDb()->getDriverName();
     $caseInsensitivePrefix = $driver == 'mysql' ? 'binary' : '';
     if (!in_array($event->category, $excludeCategories)) {
         $sourceMessage = SourceMessage::find()->where('category = :category and message = ' . $caseInsensitivePrefix . ' :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();
         $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;
 }