private function updateWithInput(InputInterface $input, ConfigBuilder $builder) { if ($bundle = $input->getOption('bundle')) { if ('@' === $bundle[0]) { $bundle = substr($bundle, 1); } $bundle = $this->getApplication()->getKernel()->getBundle($bundle); $builder->setTranslationsDir($bundle->getPath() . '/Resources/translations'); $builder->setScanDirs(array($bundle->getPath())); } if ($dirs = $input->getOption('dir')) { $builder->setScanDirs($dirs); } if ($outputDir = $input->getOption('output-dir')) { $builder->setTranslationsDir($outputDir); } if ($outputFormat = $input->getOption('output-format')) { $builder->setOutputFormat($outputFormat); } if ($input->getOption('ignore-domain')) { foreach ($input->getOption('ignore-domain') as $domain) { $builder->addIgnoredDomain($domain); } } if ($input->getOption('domain')) { foreach ($input->getOption('domain') as $domain) { $builder->addDomain($domain); } } if ($excludeDirs = $input->getOption('exclude-dir')) { $builder->setExcludedDirs($excludeDirs); } if ($excludeNames = $input->getOption('exclude-name')) { $builder->setExcludedNames($excludeNames); } if ($format = $input->getOption('default-output-format')) { $builder->setDefaultOutputFormat($format); } if ($enabledExtractors = $input->getOption('enable-extractor')) { foreach ($enabledExtractors as $alias) { $builder->enableExtractor($alias); } } if ($disabledExtractors = $input->getOption('disable-extractor')) { foreach ($disabledExtractors as $alias) { $builder->disableExtractor($alias); } } if ($input->hasParameterOption('--keep') || $input->hasParameterOption('--keep=true')) { $builder->setKeepOldTranslations(true); } else { if ($input->hasParameterOption('--keep=false')) { $builder->setKeepOldTranslations(false); } } if ($loadResource = $input->getOption('external-translations-dir')) { $builder->setLoadResources($loadResource); } if ($addDate = $input->getOption('add-date')) { $builder->setOutputOption('xlf', 'add_date', (bool) $addDate); } if ($addFileRefs = $input->getOption('add-filerefs')) { $builder->setOutputOption('xlf', 'add_filerefs', (bool) $addFileRefs); } }
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']); 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 <info>%s</info>', $locale)); $output->writeln(sprintf('Keep old translations: <info>%s</info>', $config->isKeepOldMessages() ? 'Yes' : 'No')); $output->writeln(sprintf('Output-Path: <info>%s</info>', $config->getTranslationsDir())); $output->writeln(sprintf('Directories: <info>%s</info>', implode(', ', $config->getScanDirs()))); $output->writeln(sprintf('Excluded Directories: <info>%s</info>', $config->getExcludedDirs() ? implode(', ', $config->getExcludedDirs()) : '# none #')); $output->writeln(sprintf('Excluded Names: <info>%s</info>', $config->getExcludedNames() ? implode(', ', $config->getExcludedNames()) : '# none #')); $output->writeln(sprintf('Output-Format: <info>%s</info>', $config->getOutputFormat() ? $config->getOutputFormat() : '# whatever is present, if nothing then ' . $config->getDefaultOutputFormat() . ' #')); $output->writeln(sprintf('Custom Extractors: <info>%s</info>', $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; }
/** * Set default values to handle rescan process * * @param string $bundleName * @param ConfigBuilder $builder * @return boole */ private function updateWithInput($bundleName, ConfigBuilder $builder) { $bundle = $this->kernel->getBundle($bundleName); $builder->setTranslationsDir($bundle->getPath() . '/Resources/translations'); $builder->setScanDirs(array($bundle->getPath())); $outputFormat = 'xliff'; $builder->setOutputFormat($outputFormat); return true; }