Skip to content

Commit 8ba9605

Browse files
committed
Merge remote-tracking branch 'origin/2.6' into 2.7
Conflicts: src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php src/Symfony/Component/Validator/Constraints/EmailValidator.php
2 parents d9bc414 + 9a02710 commit 8ba9605

File tree

3 files changed

+62
-28
lines changed

3 files changed

+62
-28
lines changed

Command/TranslationDebugCommand.php

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -96,35 +96,41 @@ protected function execute(InputInterface $input, OutputInterface $output)
9696
$kernel = $this->getContainer()->get('kernel');
9797

9898
// Define Root Path to App folder
99-
$rootPath = $kernel->getRootDir();
99+
$transPaths = array($kernel->getRootDir().'/Resources/');
100100

101101
// Override with provided Bundle info
102102
if (null !== $input->getArgument('bundle')) {
103103
try {
104-
$rootPath = $kernel->getBundle($input->getArgument('bundle'))->getPath();
104+
$bundle = $kernel->getBundle($input->getArgument('bundle'));
105+
$transPaths = array(
106+
$bundle->getPath().'/Resources/',
107+
sprintf('%s/Resources/%s/', $kernel->getRootDir(), $bundle->getName()),
108+
);
105109
} catch (\InvalidArgumentException $e) {
106110
// such a bundle does not exist, so treat the argument as path
107-
$rootPath = $input->getArgument('bundle');
108-
109-
if (!is_dir($rootPath)) {
110-
throw new \InvalidArgumentException(sprintf('"%s" is neither an enabled bundle nor a directory.', $rootPath));
111+
$transPaths = array($input->getArgument('bundle').'/Resources/');
112+
if (!is_dir($transPaths[0])) {
113+
throw new \InvalidArgumentException(sprintf('"%s" is neither an enabled bundle nor a directory.', $transPaths[0]));
111114
}
112115
}
113116
}
114117

115-
// get bundle directory
116-
$translationsPath = $rootPath.'/Resources/translations';
117-
118118
// Extract used messages
119119
$extractedCatalogue = new MessageCatalogue($locale);
120-
if (is_dir($rootPath.'/Resources/views')) {
121-
$this->getContainer()->get('translation.extractor')->extract($rootPath.'/Resources/views', $extractedCatalogue);
120+
foreach ($transPaths as $path) {
121+
$path = $path.'views';
122+
if (is_dir($path)) {
123+
$this->getContainer()->get('translation.extractor')->extract($path, $extractedCatalogue);
124+
}
122125
}
123126

124127
// Load defined messages
125128
$currentCatalogue = new MessageCatalogue($locale);
126-
if (is_dir($translationsPath)) {
127-
$loader->loadMessages($translationsPath, $currentCatalogue);
129+
foreach ($transPaths as $path) {
130+
$path = $path.'translations';
131+
if (is_dir($path)) {
132+
$loader->loadMessages($path, $currentCatalogue);
133+
}
128134
}
129135

130136
// Merge defined and extracted messages to get all message ids
@@ -157,7 +163,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
157163
}
158164

159165
$fallbackCatalogue = new MessageCatalogue($fallbackLocale);
160-
$loader->loadMessages($translationsPath, $fallbackCatalogue);
166+
foreach ($transPaths as $path) {
167+
$path = $path.'translations';
168+
if (is_dir($path)) {
169+
$loader->loadMessages($path, $fallbackCatalogue);
170+
}
171+
}
161172
$fallbackCatalogues[] = $fallbackCatalogue;
162173
}
163174
}

Command/TranslationUpdateCommand.php

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ protected function configure()
6969
protected function execute(InputInterface $input, OutputInterface $output)
7070
{
7171
$output = new SymfonyStyle($input, $output);
72+
$kernel = $this->getContainer()->get('kernel');
73+
7274
// check presence of force or dump-message
7375
if ($input->getOption('force') !== true && $input->getOption('dump-messages') !== true) {
7476
$output->error('You must choose one of --force or --dump-messages');
@@ -87,44 +89,54 @@ protected function execute(InputInterface $input, OutputInterface $output)
8789
$kernel = $this->getContainer()->get('kernel');
8890

8991
// Define Root Path to App folder
90-
$rootPath = $kernel->getRootDir();
92+
$transPaths = array($kernel->getRootDir().'/Resources/');
9193
$currentName = 'app folder';
9294

9395
// Override with provided Bundle info
9496
if (null !== $input->getArgument('bundle')) {
9597
try {
9698
$foundBundle = $kernel->getBundle($input->getArgument('bundle'));
97-
$rootPath = $foundBundle->getPath();
99+
$transPaths = array(
100+
$foundBundle->getPath().'/Resources/',
101+
sprintf('%s/Resources/%s/', $kernel->getRootDir(), $foundBundle->getName()),
102+
);
98103
$currentName = $foundBundle->getName();
99104
} catch (\InvalidArgumentException $e) {
100105
// such a bundle does not exist, so treat the argument as path
101-
$rootPath = $input->getArgument('bundle');
102-
$currentName = $rootPath;
106+
$transPaths = array($input->getArgument('bundle').'/Resources/');
107+
$currentName = $transPaths[0];
103108

104-
if (!is_dir($rootPath)) {
105-
throw new \InvalidArgumentException(sprintf('<error>"%s" is neither an enabled bundle nor a directory.</error>', $rootPath));
109+
if (!is_dir($transPaths[0])) {
110+
throw new \InvalidArgumentException(sprintf('<error>"%s" is neither an enabled bundle nor a directory.</error>', $transPaths[0]));
106111
}
107112
}
108113
}
109114

110115
$output->title('Symfony translation update command');
111-
112-
// get bundle directory
113-
$translationsPath = $rootPath.'/Resources/translations';
114116
$output->text(sprintf('Generating "<info>%s</info>" translation files for "<info>%s</info>"', $input->getArgument('locale'), $currentName));
115117

116118
// load any messages from templates
117119
$extractedCatalogue = new MessageCatalogue($input->getArgument('locale'));
118120
$output->text('Parsing templates');
119121
$extractor = $this->getContainer()->get('translation.extractor');
120122
$extractor->setPrefix($input->getOption('prefix'));
121-
$extractor->extract($rootPath.'/Resources/views/', $extractedCatalogue);
123+
foreach ($transPaths as $path) {
124+
$path = $path.'views';
125+
if (is_dir($path)) {
126+
$extractor->extract($path, $extractedCatalogue);
127+
}
128+
}
122129

123130
// load any existing messages from the translation files
124131
$currentCatalogue = new MessageCatalogue($input->getArgument('locale'));
125132
$output->text('Loading translation files');
126133
$loader = $this->getContainer()->get('translation.loader');
127-
$loader->loadMessages($translationsPath, $currentCatalogue);
134+
foreach ($transPaths as $path) {
135+
$path = $path.'translations';
136+
if (is_dir($path)) {
137+
$loader->loadMessages($path, $currentCatalogue);
138+
}
139+
}
128140

129141
// process catalogues
130142
$operation = $input->getOption('clean')
@@ -150,7 +162,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
150162
array_map(function ($id) {
151163
return sprintf('<fg=green>%s</>', $id);
152164
}, $newKeys),
153-
array_map(function($id) {
165+
array_map(function ($id) {
154166
return sprintf('<fg=red>%s</>', $id);
155167
}, array_keys($operation->getObsoleteMessages($domain)))
156168
));
@@ -168,7 +180,18 @@ protected function execute(InputInterface $input, OutputInterface $output)
168180
// save the files
169181
if ($input->getOption('force') === true) {
170182
$output->text('Writing files');
171-
$writer->writeTranslations($operation->getResult(), $input->getOption('output-format'), array('path' => $translationsPath, 'default_locale' => $this->getContainer()->getParameter('kernel.default_locale')));
183+
184+
$bundleTransPath = false;
185+
foreach ($transPaths as $path) {
186+
$path = $path.'translations';
187+
if (is_dir($path)) {
188+
$bundleTransPath = $path;
189+
}
190+
}
191+
192+
if ($bundleTransPath) {
193+
$writer->writeTranslations($operation->getResult(), $input->getOption('output-format'), array('path' => $bundleTransPath, 'default_locale' => $this->getContainer()->getParameter('kernel.default_locale')));
194+
}
172195
}
173196

174197
$output->newLine();

DependencyInjection/FrameworkExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ private function registerSessionConfiguration(array $config, ContainerBuilder $c
444444
/**
445445
* Loads the request configuration.
446446
*
447-
* @param array $config A session configuration array
447+
* @param array $config A request configuration array
448448
* @param ContainerBuilder $container A ContainerBuilder instance
449449
* @param XmlFileLoader $loader An XmlFileLoader instance
450450
*/

0 commit comments

Comments
 (0)