private function saveTranslations($translations = [])
{
/** @var ActiveRecord $owner */
$owner = $this->owner;
foreach ($this->languages as $lang) {
$defaultLanguage = $lang == $this->defaultLanguage;
if (!isset($translations[$lang])) {
/** @var ActiveRecord $translation */
$translation = new $this->langClassName();
$translation->{$this->languageField} = $lang;
$translation->{$this->langForeignKey} = $owner->getPrimaryKey();
} else {
$translation = $translations[$lang];
}
$save = false;
foreach ($this->attributes as $attribute) {
$value = $defaultLanguage ? $owner->{$attribute} : $this->getLangAttribute($this->getAttributeName($attribute, $lang));
if ($value !== null) {
$field = $this->localizedPrefix . $attribute;
$translation->{$field} = $value;
$save = true;
}
}
if ($translation->isNewRecord && !$save) {
continue;
}
$translation->save();
}
}