Skip to content

Commit 9b2c09f

Browse files
committed
[Translation][update cmd] taken account into bundle overrides path.
1 parent f3b193d commit 9b2c09f

File tree

1 file changed

+32
-9
lines changed

1 file changed

+32
-9
lines changed

Command/TranslationUpdateCommand.php

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ protected function configure()
6767
*/
6868
protected function execute(InputInterface $input, OutputInterface $output)
6969
{
70+
$kernel = $this->getContainer()->get('kernel');
71+
7072
// check presence of force or dump-message
7173
if ($input->getOption('force') !== true && $input->getOption('dump-messages') !== true) {
7274
$output->writeln('<info>You must choose one of --force or --dump-messages</info>');
@@ -85,32 +87,43 @@ protected function execute(InputInterface $input, OutputInterface $output)
8587
}
8688

8789
// Define Root Path to App folder
88-
$rootPath = $this->getApplication()->getKernel()->getRootDir();
89-
$currentName = "app folder";
90+
$transPaths = array($kernel->getRootDir().'/Resources/');
91+
$currentName = 'app folder';
9092

9193
// Override with provided Bundle info
9294
if (null !== $input->getArgument('bundle')) {
93-
$foundBundle = $this->getApplication()->getKernel()->getBundle($input->getArgument('bundle'));
94-
$rootPath = $foundBundle->getPath();
95+
$foundBundle = $kernel->getBundle($input->getArgument('bundle'));
96+
$transPaths = array(
97+
$foundBundle->getPath().'/Resources/',
98+
sprintf('%s/Resources/%s/', $kernel->getRootDir(), $foundBundle->getName()),
99+
);
95100
$currentName = $foundBundle->getName();
96101
}
97102

98-
// get bundle directory
99-
$translationsPath = $rootPath.'/Resources/translations';
100103
$output->writeln(sprintf('Generating "<info>%s</info>" translation files for "<info>%s</info>"', $input->getArgument('locale'), $currentName));
101104

102105
// load any messages from templates
103106
$extractedCatalogue = new MessageCatalogue($input->getArgument('locale'));
104107
$output->writeln('Parsing templates');
105108
$extractor = $this->getContainer()->get('translation.extractor');
106109
$extractor->setPrefix($input->getOption('prefix'));
107-
$extractor->extract($rootPath.'/Resources/views/', $extractedCatalogue);
110+
foreach ($transPaths as $path) {
111+
$path = $path.'views';
112+
if (is_dir($path)) {
113+
$extractor->extract($path, $extractedCatalogue);
114+
}
115+
}
108116

109117
// load any existing messages from the translation files
110118
$currentCatalogue = new MessageCatalogue($input->getArgument('locale'));
111119
$output->writeln('Loading translation files');
112120
$loader = $this->getContainer()->get('translation.loader');
113-
$loader->loadMessages($translationsPath, $currentCatalogue);
121+
foreach ($transPaths as $path) {
122+
$path = $path.'translations';
123+
if (is_dir($path)) {
124+
$loader->loadMessages($path, $currentCatalogue);
125+
}
126+
}
114127

115128
// process catalogues
116129
$operation = $input->getOption('clean')
@@ -153,7 +166,17 @@ protected function execute(InputInterface $input, OutputInterface $output)
153166
// save the files
154167
if ($input->getOption('force') === true) {
155168
$output->writeln('Writing files');
156-
$writer->writeTranslations($operation->getResult(), $input->getOption('output-format'), array('path' => $translationsPath, 'default_locale' => $this->getContainer()->getParameter('kernel.default_locale')));
169+
$bundleTransPath = false;
170+
foreach ($transPaths as $path) {
171+
$path = $path.'translations';
172+
if (is_dir($path)) {
173+
$bundleTransPath = $path;
174+
}
175+
}
176+
177+
if ($bundleTransPath) {
178+
$writer->writeTranslations($operation->getResult(), $input->getOption('output-format'), array('path' => $bundleTransPath));
179+
}
157180
}
158181
}
159182
}

0 commit comments

Comments
 (0)