Ejemplo n.º 1
0
 /**
  * @param string $langPackDir       language pack dir in temp folder
  * @param string $projectNamespace  e.g. Oro, OroCRM, etc
  * @param string $outputFormat      xml, yml, etc
  * @param string $locale            en, en_US, fr, etc
  */
 public function dump($langPackDir, $projectNamespace, $outputFormat, $locale)
 {
     $this->preloadExistingTranslations($locale);
     foreach ($this->bundles as $bundle) {
         // skip bundles from other projects
         if ($projectNamespace != $this->getBundlePrefix($bundle->getNamespace())) {
             continue;
         }
         $this->logger->log(LogLevel::INFO, '');
         $this->logger->log(LogLevel::INFO, sprintf('Writing files for <info>%s</info>', $bundle->getName()));
         /** @var MessageCatalogue $currentCatalogue */
         $currentCatalogue = $this->getCurrentCatalog($locale, $bundle->getName());
         $extractedCatalogue = $this->extractViewTranslationKeys($locale, $bundle->getPath());
         $operation = new MergeOperation($currentCatalogue, $extractedCatalogue);
         $messageCatalogue = $operation->getResult();
         $isEmptyCatalogue = $this->validateAndFilter($messageCatalogue);
         if (!$isEmptyCatalogue) {
             $translationsDir = $langPackDir . DIRECTORY_SEPARATOR . $bundle->getName() . DIRECTORY_SEPARATOR . 'translations';
             $this->filesystem->mkdir($translationsDir);
             $this->writer->writeTranslations($messageCatalogue, $outputFormat, ['path' => $translationsDir]);
         } else {
             $this->logger->log(LogLevel::INFO, '    - no files generated');
         }
     }
 }
Ejemplo n.º 2
0
 public function submitFormTranslate(Form $form)
 {
     $values = $form->getValues();
     //existuje preklad ?
     $translatesLocale = $this->row->related('translate_locale')->where('language_id', $this->webLanguage)->fetch();
     if ($translatesLocale) {
         if ($values['translate'] != '') {
             $translatesLocale->update(array('translate' => $values['translate']));
         } else {
             $translatesLocale->delete();
         }
     } else {
         $this->row->related('translate_locale')->insert(array('translate' => $values['translate'], 'language_id' => $this->webLanguage));
     }
     $language = $this->languages->get($this->webLanguage);
     $catalogue = new MessageCatalogue($language['translate_locale']);
     foreach ($this->model->getAll() as $translate) {
         $translatesLocale = $translate->related('translate_locale')->where('language_id', $this->webLanguage)->fetch();
         if ($translatesLocale) {
             $catalogue->set($translate['text'], $translatesLocale['translate']);
         } else {
             $catalogue->set($translate['text'], $translate['text']);
         }
     }
     $this->writer->writeTranslations($catalogue, 'neon', ['path' => $this->context->parameters['appDir'] . '/lang/']);
     $this->flashMessage($this->translator->trans('translate.translated'));
     $this->redirect('this');
 }
 /**
  * @param array       $messageCatalogues
  * @param string      $format
  * @param null|string $path
  */
 public function write(array $messageCatalogues, $format, $path = null)
 {
     $this->translationWriter->addDumper($format, $this->getDumper($format));
     /** @var MessageCatalogue $messageCatalogue */
     foreach ($messageCatalogues as $messageCatalogue) {
         $this->translationWriter->writeTranslations($messageCatalogue, $format, array('path' => $this->getTranslationPath($path)));
     }
 }
Ejemplo n.º 4
0
 public function testDisableBackup()
 {
     $nonBackupDumper = new NonBackupDumper();
     $backupDumper = new BackupDumper();
     $writer = new TranslationWriter();
     $writer->addDumper('non_backup', $nonBackupDumper);
     $writer->addDumper('backup', $backupDumper);
     $writer->disableBackup();
     $this->assertFalse($backupDumper->backup, 'backup can be disabled if setBackup() method does exist');
 }
Ejemplo n.º 5
0
 public function testDisableBackup()
 {
     $dumper = $this->getMock('Symfony\\Component\\Translation\\Dumper\\DumperInterface');
     $dumper->expects($this->never())->method('setBackup');
     $phpDumper = $this->getMock('Symfony\\Component\\Translation\\Dumper\\PhpFileDumper');
     $phpDumper->expects($this->once())->method('setBackup');
     $writer = new TranslationWriter();
     $writer->addDumper('test', $dumper);
     $writer->addDumper('php', $phpDumper);
     $writer->disableBackup();
 }
Ejemplo n.º 6
0
 public function writeTranslationsByModule($module, $messages)
 {
     $currentMessages = $this->getMessagesByModule($module);
     $language = 'en';
     $resource = DRUPAL_ROOT . '/' . drupal_get_path('module', $module) . '/config/translations/';
     $messageCatalogue = new MessageCatalogue($language);
     if ($currentMessages && $currentMessages['messages']) {
         $messageCatalogue->add($currentMessages['messages'], 'console');
     }
     $messageCatalogue->add($messages, 'console');
     $translatorWriter = new TranslationWriter();
     $translatorWriter->addDumper('yaml', new YamlFileDumper());
     $translatorWriter->writeTranslations($messageCatalogue, 'yaml', ['path' => $resource, 'nest-level' => 10, 'indent' => 2]);
 }
 public function missingEvent(MissingTranslationEvent $event)
 {
     return;
     $bundleName = $this->getBundleName($this->request->attributes->get('_controller'));
     $kernel = $this->container->get('kernel');
     // Define Root Path to App folder
     $transPaths = array($kernel->getRootDir() . '/Resources/');
     $currentName = 'app folder';
     // Override with provided Bundle info
     if (null !== $bundleName) {
         try {
             $foundBundle = $kernel->getBundle($bundleName);
             $transPaths = array($foundBundle->getPath() . '/Resources/', sprintf('%s/Resources/%s/', $kernel->getRootDir(), $foundBundle->getName()));
             $currentName = $foundBundle->getName();
         } catch (\InvalidArgumentException $e) {
             // such a bundle does not exist, so treat the argument as path
             $transPaths = array($bundleName . '/Resources/');
             $currentName = $transPaths[0];
             if (!is_dir($transPaths[0])) {
                 //                    throw new \InvalidArgumentException(sprintf('<error>"%s" is neither an enabled bundle nor a directory.</error>', $transPaths[0]));
             }
         }
         // load any existing messages from the translation files
         $currentCatalogue = new MessageCatalogue($event->getLocale());
         $loader = $this->container->get('translation.loader');
         foreach ($transPaths as $path) {
             $path .= 'translations';
             if (is_dir($path)) {
                 $loader->loadMessages($path, $currentCatalogue);
             }
         }
         $currentCatalogue->set($event->getId(), '__' . $event->getId(), $event->getDomain());
         $bundleTransPath = false;
         foreach ($transPaths as $path) {
             $path .= 'translations';
             if (is_dir($path)) {
                 $bundleTransPath = $path;
             }
         }
         if (!$bundleTransPath) {
             $bundleTransPath = end($transPaths) . 'translations';
         }
         $this->writer->writeTranslations($currentCatalogue, 'yml', array('path' => $bundleTransPath, 'default_locale' => $this->container->getParameter('kernel.default_locale')));
     }
 }
Ejemplo n.º 8
0
 /**
  * @param string $targetLocale
  */
 protected function dumpMessages($targetLocale)
 {
     // load downloaded messages
     $this->logger->notice('Loading downloaded catalogues from "{tmpPath}"', ['tmpPath' => $this->getTmpPath()]);
     $extractedCatalogue = new MessageCatalogue($targetLocale);
     $this->translationLoader->loadMessages($this->getTmpPath(), $extractedCatalogue);
     // Exit if no messages found.
     if (0 === count($extractedCatalogue->getDomains())) {
         $this->logger->warning('No translation found for locale {locale}', ['locale' => $targetLocale]);
         return;
     }
     $this->logger->notice('Writing translation file for locale "{locale}".', ['locale' => $targetLocale]);
     $this->translationWriter->writeTranslations($extractedCatalogue, $this->outputFormat, ['path' => $this->translationsPath]);
 }
Ejemplo n.º 9
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if ($this->validate($input, $output) !== TRUE) {
         return 1;
     }
     $catalogue = new MessageCatalogue($input->getOption('catalogue-language'));
     foreach ($this->scanDirs as $dir) {
         $output->writeln(sprintf('<info>Extracting %s</info>', $dir));
         $this->extractor->extract($dir, $catalogue);
     }
     $this->writer->writeTranslations($catalogue, $this->outputFormat, array('path' => $this->outputDir));
     $output->writeln('');
     $output->writeln(sprintf('<info>Catalogue was written to %s</info>', $this->outputDir));
     return 0;
 }
Ejemplo n.º 10
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if ($this->validate($input, $output) !== TRUE) {
         return 1;
     }
     $this->extractor->addExtractor('php', new PhpExtractor());
     $defaultLocale = null;
     foreach ($this->translator->getFallbackLocales() as $locale) {
         if (is_null($defaultLocale)) {
             $defaultLocale = $locale;
         }
         $catalogue = new MessageCatalogue($locale);
         $output->writeln(sprintf('<info>Locale %s</info>', $locale));
         foreach ($this->scanDirs as $dir) {
             $output->writeln(sprintf('<info>Extracting %s</info>', $dir));
             $this->extractor->extract($dir, $catalogue);
         }
     }
     $this->writer->writeTranslations($catalogue, $this->outputFormat, ['path' => $this->outputDir]);
     $output->writeln('');
     $output->writeln(sprintf('<info>Catalogue was written to %s</info>', $this->outputDir));
     $output->writeln('');
     $output->writeln(sprintf('<info>Zapisuji do DB</info>'));
     $toTranslate = (include dirname(__FILE__) . '/../../../../../temp/lang/messages.' . $defaultLocale . '.php');
     $texts = array('');
     foreach ($toTranslate as $translate) {
         $texts[] = $translate;
         $trans = $this->translates->where('text', $translate)->fetch();
         if (!$trans) {
             $this->translates->insert(array('text' => $translate));
         }
     }
     $this->translates->where('NOT text', $texts)->delete();
     $language = $this->languages->where('translate_locale', $defaultLocale)->fetch();
     $catalogue = new MessageCatalogue($language['translate_locale']);
     foreach ($this->translates->getAll() as $translate) {
         $translatesLocale = $translate->related('translate_locale')->where('language_id', $language['id'])->fetch();
         if ($translatesLocale) {
             $catalogue->set($translate['text'], $translatesLocale['translate']);
         } else {
             $catalogue->set($translate['text'], $translate['text']);
         }
     }
     $this->writer->writeTranslations($catalogue, 'neon', ['path' => $this->langDir]);
     return 0;
 }
 protected function setUpCreator($setDefaultYmlDirs = true)
 {
     $translationWriter = new TranslationWriter();
     $dumper = new YamlFileDumper();
     $translationWriter->addDumper('yml', $dumper);
     $defaultCreator = new DefaultCreator($translationWriter, 'yml', $this->getTranslationFolder());
     if ($setDefaultYmlDirs) {
         $defaultCreator->setDefaultYmlDirs(array(__DIR__ . DIRECTORY_SEPARATOR . 'default.de.yml'));
     }
     return $defaultCreator;
 }
 /**
  * @param $format
  * @return bool
  */
 protected function supportFormat($format)
 {
     $supportedFormats = $this->writer->getFormats();
     return in_array($format, $supportedFormats);
 }