Skip to content

Commit f566426

Browse files
committed
feature #32106 [FrameworkBundle] Use default_locale as default value for translator.fallbacks (dunglas)
This PR was merged into the 4.4 branch. Discussion ---------- [FrameworkBundle] Use default_locale as default value for translator.fallbacks | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | yes <!-- please update src/**/CHANGELOG.md files --> | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | n/a | License | MIT | Doc PR | n/a Simplify translator's config: Before: ```yaml default_locale: fr translator: default_path: '%kernel.project_dir%/translations' fallbacks: - fr ``` After: ```yaml default_locale: fr translator: default_path: '%kernel.project_dir%/translations' ``` Commits ------- e0ef35973d [FrameworkBundle] Use default_locale as default value for translator.fallbacks
2 parents dffa6db + d17bed9 commit f566426

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

DependencyInjection/Configuration.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,9 +749,10 @@ private function addTranslatorSection(ArrayNodeDefinition $rootNode)
749749
->fixXmlConfig('path')
750750
->children()
751751
->arrayNode('fallbacks')
752+
->info('Defaults to the value of "default_locale".')
752753
->beforeNormalization()->ifString()->then(function ($v) { return [$v]; })->end()
753754
->prototype('scalar')->end()
754-
->defaultValue(['en'])
755+
->defaultValue([])
755756
->end()
756757
->booleanNode('logging')->defaultValue(false)->end()
757758
->scalarNode('formatter')->defaultValue('translator.formatter.default')->end()

DependencyInjection/FrameworkExtension.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ public function load(array $configs, ContainerBuilder $container)
301301
$this->registerEsiConfiguration($config['esi'], $container, $loader);
302302
$this->registerSsiConfiguration($config['ssi'], $container, $loader);
303303
$this->registerFragmentsConfiguration($config['fragments'], $container, $loader);
304-
$this->registerTranslatorConfiguration($config['translator'], $container, $loader);
304+
$this->registerTranslatorConfiguration($config['translator'], $container, $loader, $config['default_locale']);
305305
$this->registerProfilerConfiguration($config['profiler'], $container, $loader);
306306
$this->registerCacheConfiguration($config['cache'], $container);
307307
$this->registerWorkflowConfiguration($config['workflows'], $container, $loader);
@@ -1079,7 +1079,7 @@ private function createVersion(ContainerBuilder $container, $version, $format, $
10791079
return new Reference('assets.empty_version_strategy');
10801080
}
10811081

1082-
private function registerTranslatorConfiguration(array $config, ContainerBuilder $container, LoaderInterface $loader)
1082+
private function registerTranslatorConfiguration(array $config, ContainerBuilder $container, LoaderInterface $loader, string $defaultLocale)
10831083
{
10841084
if (!$this->isConfigEnabled($container, $config)) {
10851085
$container->removeDefinition('console.command.translation_debug');
@@ -1094,7 +1094,7 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
10941094
$container->setAlias('translator', 'translator.default')->setPublic(true);
10951095
$container->setAlias('translator.formatter', new Alias($config['formatter'], false));
10961096
$translator = $container->findDefinition('translator.default');
1097-
$translator->addMethodCall('setFallbackLocales', [$config['fallbacks']]);
1097+
$translator->addMethodCall('setFallbackLocales', [$config['fallbacks'] ?: [$defaultLocale]]);
10981098

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

Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ protected static function getBundleDefaultConfig()
248248
],
249249
'translator' => [
250250
'enabled' => !class_exists(FullStack::class),
251-
'fallbacks' => ['en'],
251+
'fallbacks' => [],
252252
'logging' => false,
253253
'formatter' => 'translator.formatter.default',
254254
'paths' => [],

0 commit comments

Comments
 (0)