Ejemplo n.º 1
0
 private function buildFiles(\Project $project)
 {
     $translations = $project->getTranslations();
     $builder = new KdybyTranslationBuilder();
     $files = [];
     foreach ($translations as $translation) {
         $mask = '%s.' . $translation->getLocale() . '.neon';
         $dictionaryData = $this->translationFacade->getDictionaryData($translation);
         $outputFiles = $builder->build($mask, $dictionaryData);
         $files = array_merge($files, $outputFiles);
     }
     $zip = new ZipStream(sprintf('%s.zip', $project->getName()));
     foreach ($files as $fileName => $messages) {
         $data = Neon::encode($messages, Neon::BLOCK);
         $zip->addFile($fileName, $data);
     }
     $zip->finish();
 }
Ejemplo n.º 2
0
 public function handleDownloadTranslation()
 {
     $dictionaryData = $this->translationFacade->getDictionaryData($this->translation);
     $builder = new KdybyTranslationBuilder();
     $mask = '%s.' . $this->translation->getLocale() . '.neon';
     $outputFiles = $builder->build($mask, $dictionaryData);
     if (count($outputFiles) === 1) {
         $name = key($outputFiles);
         $neon = Neon::encode(current($outputFiles), Neon::BLOCK);
         $response = new TextDownloadResponse($neon, $name, 'text/x-neon', 'UTF-8');
         $this->sendResponse($response);
         $this->terminate();
     } else {
         $zip = new ZipStream(sprintf('%s - %s.zip', $this->translation->getProject()->getName(), $this->translation->getLocale()));
         foreach ($outputFiles as $fileName => $data) {
             $neon = Neon::encode($data, Neon::BLOCK);
             $zip->addFile($fileName, $neon);
         }
         $zip->finish();
     }
 }