Example #1
0
 /**
  * @param TranslatorConfig $config
  * @param Translator       $translator
  * @return void
  */
 public function perform(TranslatorConfig $config, Translator $translator)
 {
     if (!$config->hasDumper($this->option('dumper'))) {
         $this->writeln("<fg=red>Undefined dumper '{$this->option('dumper')}'.</fg=red>");
         return null;
     }
     $catalogue = $translator->getCatalogue($this->argument('locale'))->loadDomains();
     if ($this->option('fallback')) {
         //Let's merge with fallback locale
         $fallbackCatalogue = $translator->getCatalogue($config->fallbackLocale())->loadDomains();
         //Soft merge
         $catalogue->mergeFrom($fallbackCatalogue->toMessageCatalogue(), false);
     }
     //Pre-loading all domains
     $messageCatalogue = $catalogue->toMessageCatalogue();
     if ($this->isVerbosity() && !empty($catalogue->getDomains())) {
         $this->writeln("<info>Dumping domain(s):</info> " . join(',', $catalogue->getDomains()));
     }
     $dumper = $config->dumperClass($this->option('dumper'));
     /**
      * @var DumperInterface $dumper
      */
     $dumper = new $dumper();
     $dumper->dump($messageCatalogue, ['path' => $this->argument('path'), 'default_locale' => $config->defaultLocale(), 'xliff_version' => '2.0']);
     $this->writeln("Dump successfully completed.");
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function loadLocale($locale)
 {
     $domains = [];
     $finder = new Finder();
     $finder->in($this->config->localeDirectory($locale));
     /**
      * @var SplFileInfo $file
      */
     foreach ($finder->getIterator() as $file) {
         $this->logger()->info("Found locale domain file '{file}'", ['file' => $file->getFilename()]);
         //Per application agreement domain name must present in filename
         $domain = strstr($file->getFilename(), '.', true);
         if ($this->config->hasLoader($file->getExtension())) {
             $loader = $this->config->loaderClass($file->getExtension());
             $domains[$domain] = $this->loadCatalogue($locale, $domain, $file, new $loader());
         }
     }
     return $domains;
 }
Example #3
0
 /**
  * Load catalogue data from source.
  *
  * @param string $locale
  * @return Catalogue
  */
 protected function loadCatalogue($locale)
 {
     $catalogue = new Catalogue($locale, $this->memory);
     if (array_key_exists($locale, $this->loadedLocales) && $this->config->cacheLocales()) {
         //Has been loaded
         return $catalogue;
     }
     $benchmark = $this->benchmark('load', $locale);
     try {
         //Loading catalogue data from source
         foreach ($this->source->loadLocale($locale) as $messageCatalogue) {
             $catalogue->mergeFrom($messageCatalogue);
         }
         //To remember that locale already loaded
         $this->loadedLocales[$locale] = $catalogue->getDomains();
         $this->memory->saveData(static::MEMORY, $this->loadedLocales);
         //Saving domains memory
         $catalogue->saveDomains();
     } finally {
         $this->benchmark($benchmark);
     }
     return $catalogue;
 }
Example #4
0
 /**
  * @param Translator       $translator
  * @param TranslatorConfig $config
  */
 public function __construct(Translator $translator, TranslatorConfig $config)
 {
     $this->translator = $translator;
     //Indexation into fallback (root) locale
     $this->catalogue = $translator->getCatalogue($config->fallbackLocale());
 }