Skip to content

[Translator] TranslationDebugCommand. If bundle option missed then read translations from kernel.root_dir #14055

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected function configure()
))
->setDefinition(array(
new InputArgument('locale', InputArgument::REQUIRED, 'The locale'),
new InputArgument('bundle', InputArgument::REQUIRED, 'The bundle name'),
new InputArgument('bundle', InputArgument::OPTIONAL, 'The bundle name'),
new InputOption('domain', null, InputOption::VALUE_OPTIONAL, 'The messages domain'),
new InputOption('only-missing', null, InputOption::VALUE_NONE, 'Displays only missing messages'),
new InputOption('only-unused', null, InputOption::VALUE_NONE, 'Displays only unused messages'),
Expand All @@ -54,6 +54,7 @@ protected function configure()
The <info>%command.name%</info> command helps finding unused or missing translation
messages and comparing them with the fallback ones by inspecting the
templates and translation files of a given bundle.
If option missed the command will display information about translations that located in %%kernel.root_dir%%.

You can display information about bundle translations in a specific locale:

Expand Down Expand Up @@ -87,17 +88,17 @@ protected function execute(InputInterface $input, OutputInterface $output)

$locale = $input->getArgument('locale');
$domain = $input->getOption('domain');
$bundle = $this->getContainer()->get('kernel')->getBundle($input->getArgument('bundle'));
$bundlePath = $input->hasOption('bundle') ? $this->getContainer()->get('kernel')->getBundle($input->getArgument('bundle')) : $this->getContainer()->getParameter('kernel.root_dir');
$loader = $this->getContainer()->get('translation.loader');

// Extract used messages
$extractedCatalogue = new MessageCatalogue($locale);
$this->getContainer()->get('translation.extractor')->extract($bundle->getPath().'/Resources/views', $extractedCatalogue);
$this->getContainer()->get('translation.extractor')->extract($bundlePath.'/Resources/views', $extractedCatalogue);

// Load defined messages
$currentCatalogue = new MessageCatalogue($locale);
if (is_dir($bundle->getPath().'/Resources/translations')) {
$loader->loadMessages($bundle->getPath().'/Resources/translations', $currentCatalogue);
if (is_dir($bundlePath.'/Resources/translations')) {
$loader->loadMessages($bundlePath.'/Resources/translations', $currentCatalogue);
}

// Merge defined and extracted messages to get all message ids
Expand Down Expand Up @@ -130,7 +131,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

$fallbackCatalogue = new MessageCatalogue($fallbackLocale);
$loader->loadMessages($bundle->getPath().'/Resources/translations', $fallbackCatalogue);
$loader->loadMessages($bundlePath.'/Resources/translations', $fallbackCatalogue);
$fallbackCatalogues[] = $fallbackCatalogue;
}
}
Expand Down