Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Command/ExtractCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add 2 arguments. One should be prefix and one key-as-translation or something similar.

;
}

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];
Expand All @@ -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());
Expand Down
19 changes: 18 additions & 1 deletion Service/Importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not put it in $config?

{
$this->processConfig($config);
$this->disableTwigVisitors();
Expand Down Expand Up @@ -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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be a translation in $meta. Do this after the if (null === $translation) block.

}

// Add custom translations that we found in the source
if (null === $translation) {
Expand Down Expand Up @@ -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
Expand Down