public function formImportPOTranslationSubmitted(Form $form) { $values = $form->getValues(); if ($values->translation->isOk()) { $this->translationFacade->importPOTranslation($values->translation, $this->translation); } }
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(); }
public function createTranslation(\Project $project, $locale) { $translation = new \Translation(); $lang = substr($locale, 0, 2); $pluralRule = Langs::getPluralRule($lang); $pluralsCount = Langs::getPluralsCount($lang); $plurals = $this->getPlurals($locale, $pluralsCount); $language = \Symfony\Component\Intl\Intl::getLocaleBundle()->getLocaleName($locale); $translation->setLang($lang)->setLocale($locale)->setLanguage($language)->setProject($project)->setPluralRule($pluralRule)->setPluralsCount($pluralsCount)->setPluralNumbers($plurals); $translations = $this->prepareTranslationsArray($pluralsCount); foreach ($project->getTemplateMessages() as $messageData) { $message = $this->prepareMessage($messageData, $translations, $pluralsCount); $messageId = $message->getContext() . '.' . $message->getSingular(); $translation->addMessage($messageId, $message); $message->setTranslation($translation); $this->dm->persist($message); } $project->addTranslation($translation); $this->dm->persist($translation); $this->dm->persist($project); $this->dm->flush(); return $translation; }