setDescription('Dump translation files'); $this ->addArgument('locales', InputArgument::IS_ARRAY, 'The locales for which to extract messages.') ->addOption('dry-run', null, InputOption::VALUE_NONE, 'When specified, changes are _NOT_ persisted to disk.') ->addOption('keep', null, InputOption::VALUE_NONE, 'Define if the updater service should keep the old translation (defaults to false).') ; } protected function doExecute(InputInterface $input, OutputInterface $output) { $builder = new ConfigBuilder(); $builder ->setOutputFormat('xlf') ->setTranslationsDir(__DIR__ . '/../../../../../resources/locales') ->setScanDirs([ $this->container['root.path'].'/lib', $this->container['root.path'].'/templates', // $this->container['root.path'].'/bin', $this->container['root.path'].'/www', // $this->container['root.path'].'/Phraseanet-production-client/src', $this->container['root.path'].'/Phraseanet-production-client/templates', ]) ->setExcludedDirs([ $this->container['root.path'].'/lib/conf.d', $this->container['root.path'].'/www/assets', $this->container['root.path'].'/www/custom', $this->container['root.path'].'/www/include', $this->container['root.path'].'/www/plugins', $this->container['root.path'].'/www/thumbnails', ]) ; if ($input->hasParameterOption('--keep') || $input->hasParameterOption('--keep=true')) { $builder->setKeepOldTranslations(true); } else if ($input->hasParameterOption('--keep=false')) { $builder->setKeepOldTranslations(false); } $locales = $input->getArgument('locales'); if (empty($locales)) { $locales = array_keys($this->container->getAvailableLanguages()); } if (empty($locales)) { throw new \LogicException('No locales were given, and no locales are configured.'); } foreach ($locales as $locale) { $config = $builder->setLocale($locale)->getConfig(); $output->writeln(sprintf('Extracting Translations for locale %s', $locale)); $output->writeln(sprintf('Keep old translations: %s', $config->isKeepOldMessages() ? 'Yes' : 'No')); $output->writeln(sprintf('Output-Path: %s', $config->getTranslationsDir())); $output->writeln(sprintf('Directories: %s', implode(', ', $config->getScanDirs()))); $output->writeln(sprintf('Excluded Directories: %s', $config->getExcludedDirs() ? implode(', ', $config->getExcludedDirs()) : '# none #')); $output->writeln(sprintf('Excluded Names: %s', $config->getExcludedNames() ? implode(', ', $config->getExcludedNames()) : '# none #')); $output->writeln(sprintf('Output-Format: %s', $config->getOutputFormat() ? $config->getOutputFormat() : '# whatever is present, if nothing then '.$config->getDefaultOutputFormat().' #')); $output->writeln(sprintf('Custom Extractors: %s', $config->getEnabledExtractors() ? implode(', ', array_keys($config->getEnabledExtractors())) : '# none #')); $output->writeln('============================================================'); /** @var Updater $updater */ $updater = $this->container['translation-extractor.updater']; $updater->setLogger($logger = new OutputLogger($output)); if (!$input->getOption('verbose')) { $logger->setLevel(OutputLogger::ALL ^ OutputLogger::DEBUG); } if ($input->getOption('dry-run')) { /** @var ChangeSet $changeSet */ $changeSet = $updater->getChangeSet($config); $output->writeln('Added Messages: '.count($changeSet->getAddedMessages())); if ($input->getOption('verbose')){ /** @var Message $message */ foreach($changeSet->getAddedMessages() as $message){ $output->writeln($message->getId(). '-> '.$message->getDesc()); } } if ($config->isKeepOldMessages()) { $output->writeln('Deleted Messages: # none as "Keep Old Translations" is true #'); } else { $output->writeln('Deleted Messages: '.count($changeSet->getDeletedMessages())); if ($input->getOption('verbose')){ foreach($changeSet->getDeletedMessages() as $message){ $output->writeln($message->getId(). '-> '.$message->getDesc()); } } } return 0; } $updater->process($config); } $output->writeln('done!'); return 0; } }