Skip to content

Commit

Permalink
[FrameworkBundle] Look for translations in %kernel.root_dir%/Resource…
Browse files Browse the repository at this point in the history
…s/%bundle%/translations (fix #4018)
  • Loading branch information
vicb committed Apr 20, 2012
1 parent 539634c commit 3937561
Showing 1 changed file with 13 additions and 7 deletions.
Expand Up @@ -528,26 +528,32 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder

// Discover translation directories
$dirs = array();
foreach ($container->getParameter('kernel.bundles') as $bundle) {
$reflection = new \ReflectionClass($bundle);
$overridePath = $container->getParameter('kernel.root_dir').'/Resources/%s/translations';
foreach ($container->getParameter('kernel.bundles') as $bundle => $class) {
$reflection = new \ReflectionClass($class);
if (is_dir($dir = dirname($reflection->getFilename()).'/Resources/translations')) {
$dirs[] = $dir;
}
if (is_dir($dir = sprintf($overridePath, $bundle))) {
$dirs[] = $dir;
}
}
if (is_dir($dir = $container->getParameter('kernel.root_dir').'/Resources/translations')) {
$dirs[] = $dir;
}

// Register translation resources
if ($dirs) {
$finder = new Finder();
$finder->files()->filter(function (\SplFileInfo $file) {
return 2 === substr_count($file->getBasename(), '.') && preg_match('/\.\w+$/', $file->getBasename());
})->in($dirs);
$finder = Finder::create()
->files()
->filter(function (\SplFileInfo $file) {
return 2 === substr_count($file->getBasename(), '.') && preg_match('/\.\w+$/', $file->getBasename());
})
->in($dirs)
;
foreach ($finder as $file) {
// filename is domain.locale.format
list($domain, $locale, $format) = explode('.', $file->getBasename(), 3);

$translator->addMethodCall('addResource', array($format, (string) $file, $locale, $domain));
}
}
Expand Down

0 comments on commit 3937561

Please sign in to comment.