/** * Convert a trans unit into an array. * * @param TransUnitInterface $transUnit * @return array */ protected function toArray(TransUnitInterface $transUnit) { $data = array('id' => $transUnit->getId(), 'domain' => $transUnit->getDomain(), 'key' => $transUnit->getKey(), 'translations' => array()); foreach ($transUnit->getTranslations() as $translation) { $data['translations'][] = array('locale' => $translation->getLocale(), 'content' => $translation->getContent()); } return $data; }
/** * Get the proper File for this TransUnit and locale * * @param TransUnitInterface $transUnit * @param string $locale * * @return FileInterface|null */ protected function getTranslationFile(TransUnitInterface &$transUnit, $locale) { $file = null; foreach ($transUnit->getTranslations() as $translationModel) { if (null !== ($file = $translationModel->getFile())) { break; } } //if we found a file if ($file !== null) { //make sure we got the correct file for this locale and domain $name = sprintf('%s.%s.%s', $file->getDomain(), $locale, $file->getExtention()); $file = $this->fileManager->getFor($name, $this->kernelRootDir . DIRECTORY_SEPARATOR . $file->getPath()); } return $file; }
/** * @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; } }