/** * @param TransUnitInterface $transUnit * @param string $locale * @return bool */ public function deleteTranslation(TransUnitInterface $transUnit, $locale) { try { $translation = $transUnit->getTranslation($locale); $this->storage->remove($translation); $this->storage->flush(); return true; } catch (\Exception $e) { return false; } }
/** * {@inheritdoc} */ public function updateTranslation(TransUnitInterface $transUnit, $locale, $content, $flush = false, $merge = false, \DateTime $modifiedOn = null) { $translation = null; $i = 0; $end = $transUnit->getTranslations()->count(); $found = false; while ($i < $end && !$found) { $found = $transUnit->getTranslations()->get($i)->getLocale() == $locale; $i++; } if ($found) { /* @var Translation $translation */ $translation = $transUnit->getTranslations()->get($i - 1); if ($merge) { if ($translation->getContent() == $content) { return null; } if ($translation->getCreatedAt() != $translation->getUpdatedAt() && (!$modifiedOn || $translation->getUpdatedAt() > $modifiedOn)) { return null; } $newTranslation = clone $translation; $this->storage->remove($translation); $this->storage->flush(); $newTranslation->setContent($content); $this->storage->persist($newTranslation); $translation = $newTranslation; } $translation->setContent($content); } if (null !== $translation && $this->storage instanceof PropelStorage) { $this->storage->persist($translation); } if ($flush) { $this->storage->flush(); } return $translation; }