diff --git a/Command/ExtractCommand.php b/Command/ExtractCommand.php index 8da04b4d..ae5adb9a 100644 --- a/Command/ExtractCommand.php +++ b/Command/ExtractCommand.php @@ -92,13 +92,14 @@ protected function configure() ->addArgument('locale', InputArgument::OPTIONAL, 'The locale ot use. If omitted, we use all configured locales.', false) ->addOption('hide-errors', null, InputOption::VALUE_NONE, 'If we should print error or not') ->addOption('bundle', 'b', InputOption::VALUE_REQUIRED, 'The bundle you want extract translations from.') + ->addArgument('prefixTarget', InputArgument::OPTIONAL, 'The prefix of Target', null) ; } protected function execute(InputInterface $input, OutputInterface $output) { $config = $this->configurationManager->getConfiguration($input->getArgument('configuration')); - + $prefixTarget = $input->getArgument('prefixTarget'); $locales = []; if ($inputLocale = $input->getArgument('locale')) { $locales = [$inputLocale]; @@ -112,7 +113,7 @@ protected function execute(InputInterface $input, OutputInterface $output) 'blacklist_domains' => $config->getBlacklistDomains(), 'whitelist_domains' => $config->getWhitelistDomains(), 'project_root' => $config->getProjectRoot(), - ]); + ], $prefixTarget); $errors = $result->getErrors(); $this->catalogueWriter->writeCatalogues($config, $result->getMessageCatalogues()); diff --git a/Service/Importer.php b/Service/Importer.php index ad0287a0..a89ee245 100644 --- a/Service/Importer.php +++ b/Service/Importer.php @@ -64,9 +64,11 @@ public function __construct(Extractor $extractor, \Twig_Environment $twig) * @var string $project_root The project root will be removed from the source location. * } * + * @param string|null $prefixTarget + * * @return ImportResult */ - public function extractToCatalogues(Finder $finder, array $catalogues, array $config = []) + public function extractToCatalogues(Finder $finder, array $catalogues, array $config = [], string $prefixTarget = null) { $this->processConfig($config); $this->disableTwigVisitors(); @@ -96,6 +98,9 @@ public function extractToCatalogues(Finder $finder, array $catalogues, array $co $meta = $this->getMetadata($result, $key, $domain); $meta->setState('new'); $this->setMetadata($result, $key, $domain, $meta); + if (null !== $prefixTarget) { + $this->setTarget($catalogue, $key, $prefixTarget, $domain, $translation); + } // Add custom translations that we found in the source if (null === $translation) { @@ -163,6 +168,18 @@ private function getMetadata(MessageCatalogue $catalogue, $key, $domain) return new Metadata($catalogue->getMetadata($key, $domain)); } + /** + * @param MessageCatalogue $catalogue + * @param $key + * @param $prefix + * @param $domain + * @param string $translation + */ + private function setTarget(MessageCatalogue $catalogue, $key, $prefix, $domain, $translation = '') + { + $catalogue->set($key, '' !== $translation ? $translation : $prefix.$key, $domain); + } + /** * @param MessageCatalogue $catalogue * @param $key