Skip to content

Commit aaf5196

Browse files
committed
Merge remote-tracking branch 'origin/2.7' into 2.8
Conflicts: src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveDefinitionTemplatesPassTest.php
2 parents ad2c965 + df2a5a8 commit aaf5196

File tree

9 files changed

+132
-138
lines changed

9 files changed

+132
-138
lines changed

Command/TranslationDebugCommand.php

Lines changed: 86 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -106,106 +106,103 @@ protected function execute(InputInterface $input, OutputInterface $output)
106106
$kernel = $this->getContainer()->get('kernel');
107107

108108
// Define Root Path to App folder
109-
$rootPaths = array($kernel->getRootDir());
109+
$transPaths = array($kernel->getRootDir().'/Resources/');
110110

111111
// Override with provided Bundle info
112112
if (null !== $input->getArgument('bundle')) {
113113
try {
114-
$rootPaths = array($kernel->getBundle($input->getArgument('bundle'))->getPath());
114+
$bundle = $kernel->getBundle($input->getArgument('bundle'));
115+
$transPaths = array(
116+
$bundle->getPath().'/Resources/',
117+
sprintf('%s/Resources/%s/', $kernel->getRootDir(), $bundle->getName()),
118+
);
115119
} catch (\InvalidArgumentException $e) {
116120
// such a bundle does not exist, so treat the argument as path
117-
$rootPaths = array($input->getArgument('bundle'));
121+
$transPaths = array($input->getArgument('bundle').'/Resources/');
118122

119-
if (!is_dir($rootPaths[0])) {
120-
throw new \InvalidArgumentException(sprintf('"%s" is neither an enabled bundle nor a directory.</error>', $rootPaths[0]));
123+
if (!is_dir($transPaths[0])) {
124+
throw new \InvalidArgumentException(sprintf('"%s" is neither an enabled bundle nor a directory.', $transPaths[0]));
121125
}
122126
}
123127
} elseif ($input->getOption('all')) {
124128
foreach ($kernel->getBundles() as $bundle) {
125-
$rootPaths[] = $bundle->getPath();
129+
$transPaths[] = $bundle->getPath().'/Resources/';
130+
$transPaths[] = sprintf('%s/Resources/%s/', $kernel->getRootDir(), $bundle->getName());
126131
}
127132
}
128133

129-
foreach ($rootPaths as $rootPath) {
130-
// get bundle directory
131-
$translationsPath = $rootPath.'/Resources/translations';
134+
// Extract used messages
135+
$extractedCatalogue = $this->extractMessages($locale, $transPaths);
132136

133-
$output->writeln(sprintf('Translations in <info>%s</info>', $translationsPath));
137+
// Load defined messages
138+
$currentCatalogue = $this->loadCurrentMessages($locale, $transPaths, $loader);
134139

135-
// Extract used messages
136-
$extractedCatalogue = $this->extractMessages($locale, $rootPath);
140+
// Merge defined and extracted messages to get all message ids
141+
$mergeOperation = new MergeOperation($extractedCatalogue, $currentCatalogue);
142+
$allMessages = $mergeOperation->getResult()->all($domain);
143+
if (null !== $domain) {
144+
$allMessages = array($domain => $allMessages);
145+
}
137146

138-
// Load defined messages
139-
$currentCatalogue = $this->loadCurrentMessages($locale, $translationsPath, $loader);
147+
// No defined or extracted messages
148+
if (empty($allMessages) || null !== $domain && empty($allMessages[$domain])) {
149+
$outputMessage = sprintf('No defined or extracted messages for locale "%s"', $locale);
140150

141-
// Merge defined and extracted messages to get all message ids
142-
$mergeOperation = new MergeOperation($extractedCatalogue, $currentCatalogue);
143-
$allMessages = $mergeOperation->getResult()->all($domain);
144151
if (null !== $domain) {
145-
$allMessages = array($domain => $allMessages);
146-
}
147-
148-
// No defined or extracted messages
149-
if (empty($allMessages) || null !== $domain && empty($allMessages[$domain])) {
150-
$outputMessage = sprintf('<info>No defined or extracted messages for locale "%s"</info>', $locale);
151-
152-
if (null !== $domain) {
153-
$outputMessage .= sprintf(' <info>and domain "%s"</info>', $domain);
154-
}
155-
156-
$output->writeln($outputMessage);
157-
158-
continue;
152+
$outputMessage .= sprintf(' and domain "%s"', $domain);
159153
}
160154

161-
// Load the fallback catalogues
162-
$fallbackCatalogues = $this->loadFallbackCatalogues($locale, $translationsPath, $loader);
155+
$output->warning($outputMessage);
163156

164-
// Display header line
165-
$headers = array('State', 'Domain', 'Id', sprintf('Message Preview (%s)', $locale));
166-
foreach ($fallbackCatalogues as $fallbackCatalogue) {
167-
$headers[] = sprintf('Fallback Message Preview (%s)', $fallbackCatalogue->getLocale());
168-
}
157+
return;
158+
}
169159

170-
// Iterate all message ids and determine their state
171-
$rows = array();
172-
foreach ($allMessages as $domain => $messages) {
173-
foreach (array_keys($messages) as $messageId) {
174-
$value = $currentCatalogue->get($messageId, $domain);
175-
$states = array();
176-
177-
if ($extractedCatalogue->defines($messageId, $domain)) {
178-
if (!$currentCatalogue->defines($messageId, $domain)) {
179-
$states[] = self::MESSAGE_MISSING;
180-
}
181-
} elseif ($currentCatalogue->defines($messageId, $domain)) {
182-
$states[] = self::MESSAGE_UNUSED;
183-
}
160+
// Load the fallback catalogues
161+
$fallbackCatalogues = $this->loadFallbackCatalogues($locale, $transPaths, $loader);
184162

185-
if (!in_array(self::MESSAGE_UNUSED, $states) && true === $input->getOption('only-unused')
186-
|| !in_array(self::MESSAGE_MISSING, $states) && true === $input->getOption('only-missing')) {
187-
continue;
163+
// Display header line
164+
$headers = array('State', 'Domain', 'Id', sprintf('Message Preview (%s)', $locale));
165+
foreach ($fallbackCatalogues as $fallbackCatalogue) {
166+
$headers[] = sprintf('Fallback Message Preview (%s)', $fallbackCatalogue->getLocale());
167+
}
168+
$rows = array();
169+
// Iterate all message ids and determine their state
170+
foreach ($allMessages as $domain => $messages) {
171+
foreach (array_keys($messages) as $messageId) {
172+
$value = $currentCatalogue->get($messageId, $domain);
173+
$states = array();
174+
175+
if ($extractedCatalogue->defines($messageId, $domain)) {
176+
if (!$currentCatalogue->defines($messageId, $domain)) {
177+
$states[] = self::MESSAGE_MISSING;
188178
}
179+
} elseif ($currentCatalogue->defines($messageId, $domain)) {
180+
$states[] = self::MESSAGE_UNUSED;
181+
}
189182

190-
foreach ($fallbackCatalogues as $fallbackCatalogue) {
191-
if ($fallbackCatalogue->defines($messageId, $domain) && $value === $fallbackCatalogue->get($messageId, $domain)) {
192-
$states[] = self::MESSAGE_EQUALS_FALLBACK;
183+
if (!in_array(self::MESSAGE_UNUSED, $states) && true === $input->getOption('only-unused')
184+
|| !in_array(self::MESSAGE_MISSING, $states) && true === $input->getOption('only-missing')) {
185+
continue;
186+
}
193187

194-
break;
195-
}
196-
}
188+
foreach ($fallbackCatalogues as $fallbackCatalogue) {
189+
if ($fallbackCatalogue->defines($messageId, $domain) && $value === $fallbackCatalogue->get($messageId, $domain)) {
190+
$states[] = self::MESSAGE_EQUALS_FALLBACK;
197191

198-
$row = array($this->formatStates($states), $domain, $this->formatId($messageId), $this->sanitizeString($value));
199-
foreach ($fallbackCatalogues as $fallbackCatalogue) {
200-
$row[] = $this->sanitizeString($fallbackCatalogue->get($messageId, $domain));
192+
break;
201193
}
194+
}
202195

203-
$rows[] = $row;
196+
$row = array($this->formatStates($states), $domain, $this->formatId($messageId), $this->sanitizeString($value));
197+
foreach ($fallbackCatalogues as $fallbackCatalogue) {
198+
$row[] = $this->sanitizeString($fallbackCatalogue->get($messageId, $domain));
204199
}
205-
}
206200

207-
$output->table($headers, $rows);
201+
$rows[] = $row;
202+
}
208203
}
204+
205+
$output->table($headers, $rows);
209206
}
210207

211208
private function formatState($state)
@@ -257,45 +254,51 @@ private function sanitizeString($string, $length = 40)
257254

258255
/**
259256
* @param string $locale
260-
* @param string $rootPath
257+
* @param array $transPaths
261258
*
262259
* @return MessageCatalogue
263260
*/
264-
private function extractMessages($locale, $rootPath)
261+
private function extractMessages($locale, $transPaths)
265262
{
266263
$extractedCatalogue = new MessageCatalogue($locale);
267-
if (is_dir($rootPath.'/Resources/views')) {
268-
$this->getContainer()->get('translation.extractor')->extract($rootPath.'/Resources/views', $extractedCatalogue);
264+
foreach ($transPaths as $path) {
265+
$path = $path.'views';
266+
if (is_dir($path)) {
267+
$this->getContainer()->get('translation.extractor')->extract($path, $extractedCatalogue);
268+
}
269269
}
270270

271271
return $extractedCatalogue;
272272
}
273273

274274
/**
275275
* @param string $locale
276-
* @param string $translationsPath
276+
* @param array $transPaths
277277
* @param TranslationLoader $loader
278278
*
279279
* @return MessageCatalogue
280280
*/
281-
private function loadCurrentMessages($locale, $translationsPath, TranslationLoader $loader)
281+
private function loadCurrentMessages($locale, $transPaths, TranslationLoader $loader)
282282
{
283283
$currentCatalogue = new MessageCatalogue($locale);
284-
if (is_dir($translationsPath)) {
285-
$loader->loadMessages($translationsPath, $currentCatalogue);
284+
foreach ($transPaths as $path) {
285+
$path = $path.'translations';
286+
if (is_dir($path)) {
287+
$loader->loadMessages($path, $currentCatalogue);
288+
}
286289
}
287290

288291
return $currentCatalogue;
289292
}
290293

291294
/**
292295
* @param string $locale
293-
* @param string $translationsPath
296+
* @param array $transPaths
294297
* @param TranslationLoader $loader
295298
*
296299
* @return MessageCatalogue[]
297300
*/
298-
private function loadFallbackCatalogues($locale, $translationsPath, TranslationLoader $loader)
301+
private function loadFallbackCatalogues($locale, $transPaths, TranslationLoader $loader)
299302
{
300303
$fallbackCatalogues = array();
301304
$translator = $this->getContainer()->get('translator');
@@ -306,7 +309,12 @@ private function loadFallbackCatalogues($locale, $translationsPath, TranslationL
306309
}
307310

308311
$fallbackCatalogue = new MessageCatalogue($fallbackLocale);
309-
$loader->loadMessages($translationsPath, $fallbackCatalogue);
312+
foreach ($transPaths as $path) {
313+
$path = $path.'translations';
314+
if (is_dir($path)) {
315+
$loader->loadMessages($path, $fallbackCatalogue);
316+
}
317+
}
310318
$fallbackCatalogues[] = $fallbackCatalogue;
311319
}
312320
}

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();

Controller/Controller.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ protected function addFlash($type, $message)
119119
* @param mixed $attributes The attributes
120120
* @param mixed $object The object
121121
*
122-
* @throws \LogicException
123-
*
124122
* @return bool
123+
*
124+
* @throws \LogicException
125125
*/
126126
protected function isGranted($attributes, $object = null)
127127
{
@@ -231,7 +231,7 @@ public function createNotFoundException($message = 'Not Found', \Exception $prev
231231
*
232232
* @return AccessDeniedException
233233
*/
234-
public function createAccessDeniedException($message = 'Access Denied', \Exception $previous = null)
234+
public function createAccessDeniedException($message = 'Access Denied.', \Exception $previous = null)
235235
{
236236
return new AccessDeniedException($message, $previous);
237237
}

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)