10000 [FrameworkBundle] Add default translations path option and convention by yceruto · Pull Request #24860 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[FrameworkBundle] Add default translations path option and convention #24860

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CHANGELOG
3.4.0
-----

* Added `translator.default_path` option and parameter
* Session `use_strict_mode` is now enabled by default and the corresponding option has been deprecated
* Made the `cache:clear` command to *not* clear "app" PSR-6 cache pools anymore,
but to still clear "system" ones; use the `cache:pool:clear` command to clear "app" pools instead
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,10 @@ private function addTranslatorSection(ArrayNodeDefinition $rootNode)
->end()
->booleanNode('logging')->defaultValue($this->debug)->end()
->scalarNode('formatter')->defaultValue('translator.formatter.default')->end()
->scalarNode('default_path')
->info('The default path used to load translations')
->defaultValue('%kernel.project_dir%/config/translations')
->end()
->arrayNode('paths')
->prototype('scalar')->end()
->end()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,7 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
$translator->addMethodCall('setFallbackLocales', array($config['fallbacks']));

$container->setParameter('translator.logging', $config['logging']);
$container->setParameter('translator.default_path', $config['default_path']);

// Discover translation directories
$dirs = array();
Expand All @@ -1149,11 +1150,15 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder

$dirs[] = dirname(dirname($r->getFileName())).'/Resources/translations';
}
$defaultDir = $container->getParameterBag()->resolveValue($config['default_path']);
$rootDir = $container->getParameter('kernel.root_dir');
foreach ($container->getParameter('kernel.bundles_metadata') as $name => $bundle) {
if ($container->fileExists($dir = $bundle['path'].'/Resources/translations')) {
$dirs[] = $dir;
}
if ($container->fileExists($dir = $defaultDir.'/'.$name)) {
$dirs[] = $dir;
}
if ($container->fileExists($dir = $rootDir.sprintf('/Resources/%s/translations', $name))) {
$dirs[] = $dir;
}
Expand All @@ -1167,6 +1172,9 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
}
}

if ($container->fileExists($defaultDir)) {
$dirs[] = $defaultDir;
}
if ($container->fileExists($dir = $rootDir.'/Resources/translations')) {
$dirs[] = $dir;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ protected static function getBundleDefaultConfig()
'logging' => true,
'formatter' => 'translator.formatter.default',
'paths' => array(),
'default_path' => '%kernel.project_dir%/config/translations',
),
'validation' => array(
'enabled' => !class_exists(FullStack::class),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ framework:
translator:
enabled: true
fallback: fr
default_path: '%kernel.root_dir%/config/translations'
paths: ['%kernel.root_dir%/Fixtures/translations']
validation:
enabled: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,11 @@ public function testTranslator()
$files,
'->registerTranslatorConfiguration() finds translation resources in custom paths'
);
$this->assertContains(
strtr(__DIR__.'/config/translations/test_default.en.xlf', '/', DIRECTORY_SEPARATOR),
$files,
'->registerTranslatorConfiguration() finds translation resources in default path'
);

$calls = $container->getDefinition('translator.default')->getMethodCalls();
$this->assertEquals(array('fr'), $calls[1][1][0]);
Expand Down
0