/**
  * {@inheritdoc}
  */
 public function create($name, $path, $flush = false)
 {
     $path = $this->getFileRelativePath($path);
     $class = $this->storage->getModelClass('file');
     $file = new $class();
     $file->setName($name);
     $file->setPath($path);
     $file->setHash($this->generateHash($name, $path));
     $this->storage->persist($file);
     if ($flush) {
         $this->storage->flush();
     }
     return $file;
 }
 /**
  * {@inheritdoc}
  */
 public function process(FormInterface $form, Request $request)
 {
     $valid = false;
     if ($request->isMethod('POST')) {
         $form->handleRequest($request);
         if ($form->isValid()) {
             $transUnit = $form->getData();
             $translations = $transUnit->filterNotBlankTranslations();
             // only keep translations with a content
             // link new translations to a file to be able to export them.
             foreach ($translations as $translation) {
                 if (!$translation->getFile()) {
                     $file = $this->fileManager->getFor(sprintf('%s.%s.yml', $transUnit->getDomain(), $translation->getLocale()), $this->rootDir . '/Resources/translations');
                     if ($file instanceof FileInterface) {
                         $translation->setFile($file);
                     }
                 }
             }
             if ($transUnit instanceof PropelTransUnit) {
                 // The setTranslations() method only accepts PropelCollections
                 $translations = new \PropelObjectCollection($translations);
             }
             $transUnit->setTranslations($translations);
             $this->storage->persist($transUnit);
             $this->storage->flush();
             $valid = true;
         }
     }
     return $valid;
 }
 /**
  * {@inheritdoc}
  */
 public function updateTranslationsContent(TransUnitInterface $transUnit, array $translations, $flush = false)
 {
     foreach ($translations as $locale => $content) {
         if (!empty($content)) {
             if ($transUnit->hasTranslation($locale)) {
                 $this->updateTranslation($transUnit, $locale, $content);
                 if ($this->storage instanceof PropelStorage) {
                     $this->storage->persist($transUnit);
                 }
             } else {
                 //We need to get a proper file for this translation
                 $file = $this->getTranslationFile($transUnit, $locale);
                 $this->addTranslation($transUnit, $locale, $content, $file);
             }
         }
     }
     if ($flush) {
         $this->storage->flush();
     }
 }