/** * Adds a new translation record based on the language, the translatable resource, and the field and value. * * @param Translatable $resource * @param string $language * @param string $field * @param mixed $value * @return TranslationInterface */ public function add(TranslatableInterface $resource, $language, $field, $value) { $translation = $this->translationRepository->getNew(); $translation->language = $language; $translation->foreign_id = $resource->getId(); $translation->resource = $resource->getResourceName(); $translation->field = $field; $translation->value = $value; return $this->translationRepository->save($translation); }
/** * @param TranslatableInterface $translatable */ public function setTranslatable(TranslatableInterface $translatable = null) { $oldTranslatable = $this->translatable; $this->translatable = $translatable; if ($oldTranslatable !== null) { $oldTranslatable->removeTranslation($this); } if ($translatable !== null) { $translatable->addTranslation($this); } }
/** * {@inheritdoc} */ public function setTranslatable(TranslatableInterface $translatable = null) { if ($translatable === $this->translatable) { return; } $previousTranslatable = $this->translatable; $this->translatable = $translatable; if (null !== $previousTranslatable) { $previousTranslatable->removeTranslation($this); } if (null !== $translatable) { $translatable->addTranslation($this); } }
/** * @param TranslatableInterface $entity */ public function copy(TranslatableInterface $entity) { foreach ($this->translations as $locale => $value) { $entity->setTranslation($value, $locale == '' ? null : $locale); } }