Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 25a50f5

Browse files
committed
bug #15039 [Translation][update cmd] taken account into bundle overrides path. (aitboudad)
This PR was merged into the 2.3 branch. Discussion ---------- [Translation][update cmd] taken account into bundle overrides path. | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Fixed tickets | #14942 (partially) | Tests pass? | yes | License | MIT Commits ------- a8f315b [Translation][update cmd] taken account into bundle overrides path.
2 parents 7a23442 + a8f315b commit 25a50f5

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ protected function configure()
6161
*/
6262
protected function execute(InputInterface $input, OutputInterface $output)
6363
{
64+
$kernel = $this->getContainer()->get('kernel');
65+
6466
// check presence of force or dump-message
6567
if ($input->getOption('force') !== true && $input->getOption('dump-messages') !== true) {
6668
$output->writeln('<info>You must choose one of --force or --dump-messages</info>');
@@ -79,22 +81,36 @@ protected function execute(InputInterface $input, OutputInterface $output)
7981
}
8082

8183
// get bundle directory
82-
$foundBundle = $this->getApplication()->getKernel()->getBundle($input->getArgument('bundle'));
83-
$bundleTransPath = $foundBundle->getPath().'/Resources/translations';
84+
$foundBundle = $kernel->getBundle($input->getArgument('bundle'));
85+
$bundleTransPaths = array(
86+
$foundBundle->getPath().'/Resources/',
87+
sprintf('%s/Resources/%s/', $kernel->getRootDir(), $foundBundle->getName()),
88+
);
89+
8490
$output->writeln(sprintf('Generating "<info>%s</info>" translation files for "<info>%s</info>"', $input->getArgument('locale'), $foundBundle->getName()));
8591

8692
// load any messages from templates
8793
$extractedCatalogue = new MessageCatalogue($input->getArgument('locale'));
8894
$output->writeln('Parsing templates');
8995
$extractor = $this->getContainer()->get('translation.extractor');
9096
$extractor->setPrefix($input->getOption('prefix'));
91-
$extractor->extract($foundBundle->getPath().'/Resources/views/', $extractedCatalogue);
97+
foreach ($bundleTransPaths as $path) {
98+
$path = $path.'views';
99+
if (is_dir($path)) {
100+
$extractor->extract($path, $extractedCatalogue);
101+
}
102+
}
92103

93104
// load any existing messages from the translation files
94105
$currentCatalogue = new MessageCatalogue($input->getArgument('locale'));
95106
$output->writeln('Loading translation files');
96107
$loader = $this->getContainer()->get('translation.loader');
97-
$loader->loadMessages($bundleTransPath, $currentCatalogue);
108+
foreach ($bundleTransPaths as $path) {
109+
$path = $path.'translations';
110+
if (is_dir($path)) {
111+
$loader->loadMessages($path, $currentCatalogue);
112+
}
113+
}
98114

99115
// process catalogues
100116
$operation = $input->getOption('clean')
@@ -133,7 +149,17 @@ protected function execute(InputInterface $input, OutputInterface $output)
133149
// save the files
134150
if ($input->getOption('force') === true) {
135151
$output->writeln('Writing files');
136-
$writer->writeTranslations($operation->getResult(), $input->getOption('output-format'), array('path' => $bundleTransPath));
152+
$bundleTransPath = false;
153+
foreach ($bundleTransPaths as $path) {
154+
$path = $path.'translations';
155+
if (is_dir($path)) {
156+
$bundleTransPath = $path;
157+
}
158+
}
159+
160+
if ($bundleTransPath) {
161+
$writer->writeTranslations($operation->getResult(), $input->getOption('output-format'), array('path' => $bundleTransPath));
162+
}
137163
}
138164
}
139165
}

0 commit comments

Comments
 (0)