/** * @return \yii\db\ActiveQuery */ public function getMessages() { return $this->hasMany(Message::className(), ['id' => 'id'])->indexBy('language'); }
/** * @param SourceMessage $sourceMessage * @param string $language * @param string $translation * @param $override * @return bool|null */ protected function setTranslation($sourceMessage, $language, $translation, $override) { /** @var Message[] $messages */ $messages = $sourceMessage->messages; if (isset($messages[$language]) && ($override || $messages[$language]->translation === null)) { $messages[$language]->translation = $translation; return $messages[$language]->save(); } elseif (!isset($messages[$language])) { $message = new Message(); $message->language = $language; $message->translation = $translation; $message->id = $sourceMessage->id; return $message->save(); } return null; }