コード例 #1
0
 public function formImportPOTranslationSubmitted(Form $form)
 {
     $values = $form->getValues();
     if ($values->translation->isOk()) {
         $this->translationFacade->importPOTranslation($values->translation, $this->translation);
     }
 }
コード例 #2
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();
 }
コード例 #3
0
ファイル: Project.php プロジェクト: bazo/translation-ui
 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;
 }