merged branch vicb/translation/override (PR #4030)
Commits
-------
3937561
[FrameworkBundle] Look for translations in %kernel.root_dir%/Resources/%bundle%/translations (fix #4018)
Discussion
----------
[FrameworkBundle] Look for translations in %kernel.root_dir%/Resources/%...
...bundle%/translations (fix #4018)
I will submit a PR to the docs.
This commit is contained in:
commit
76a42c89ba
@ -528,11 +528,15 @@ class FrameworkExtension extends Extension
|
|||||||
|
|
||||||
// Discover translation directories
|
// Discover translation directories
|
||||||
$dirs = array();
|
$dirs = array();
|
||||||
foreach ($container->getParameter('kernel.bundles') as $bundle) {
|
$overridePath = $container->getParameter('kernel.root_dir').'/Resources/%s/translations';
|
||||||
$reflection = new \ReflectionClass($bundle);
|
foreach ($container->getParameter('kernel.bundles') as $bundle => $class) {
|
||||||
|
$reflection = new \ReflectionClass($class);
|
||||||
if (is_dir($dir = dirname($reflection->getFilename()).'/Resources/translations')) {
|
if (is_dir($dir = dirname($reflection->getFilename()).'/Resources/translations')) {
|
||||||
$dirs[] = $dir;
|
$dirs[] = $dir;
|
||||||
}
|
}
|
||||||
|
if (is_dir($dir = sprintf($overridePath, $bundle))) {
|
||||||
|
$dirs[] = $dir;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (is_dir($dir = $container->getParameter('kernel.root_dir').'/Resources/translations')) {
|
if (is_dir($dir = $container->getParameter('kernel.root_dir').'/Resources/translations')) {
|
||||||
$dirs[] = $dir;
|
$dirs[] = $dir;
|
||||||
@ -540,14 +544,16 @@ class FrameworkExtension extends Extension
|
|||||||
|
|
||||||
// Register translation resources
|
// Register translation resources
|
||||||
if ($dirs) {
|
if ($dirs) {
|
||||||
$finder = new Finder();
|
$finder = Finder::create()
|
||||||
$finder->files()->filter(function (\SplFileInfo $file) {
|
->files()
|
||||||
return 2 === substr_count($file->getBasename(), '.') && preg_match('/\.\w+$/', $file->getBasename());
|
->filter(function (\SplFileInfo $file) {
|
||||||
})->in($dirs);
|
return 2 === substr_count($file->getBasename(), '.') && preg_match('/\.\w+$/', $file->getBasename());
|
||||||
|
})
|
||||||
|
->in($dirs)
|
||||||
|
;
|
||||||
foreach ($finder as $file) {
|
foreach ($finder as $file) {
|
||||||
// filename is domain.locale.format
|
// filename is domain.locale.format
|
||||||
list($domain, $locale, $format) = explode('.', $file->getBasename(), 3);
|
list($domain, $locale, $format) = explode('.', $file->getBasename(), 3);
|
||||||
|
|
||||||
$translator->addMethodCall('addResource', array($format, (string) $file, $locale, $domain));
|
$translator->addMethodCall('addResource', array($format, (string) $file, $locale, $domain));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user