Beispiel #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.");
 }
Beispiel #2
0
 /**
  * @param TranslatorConfig     $config
  * @param HippocampusInterface $memory
  * @param SourceInterface      $source
  * @param MessageSelector      $selector
  */
 public function __construct(TranslatorConfig $config, HippocampusInterface $memory, SourceInterface $source, MessageSelector $selector = null)
 {
     $this->config = $config;
     $this->memory = $memory;
     $this->source = $source;
     $this->selector = $selector;
     //List of known and loaded locales
     $this->loadedLocales = (array) $this->memory->loadData(static::MEMORY);
     $this->locale = $this->config->defaultLocale();
     $this->fallbackCatalogue = $this->loadCatalogue($this->config->fallbackLocale());
 }