Skip to content
Permalink
Browse files

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
-------

e0ef359 [FrameworkBundle] Use default_locale as default value for translator.fallbacks
  • Loading branch information...
fabpot committed Jul 5, 2019
2 parents a71ee27 + e0ef359 commit b515107870a877bead1f7884f99a850fdc84d8b6
@@ -749,9 +749,10 @@ private function addTranslatorSection(ArrayNodeDefinition $rootNode)
->fixXmlConfig('path')
->children()
->arrayNode('fallbacks')
->info('Defaults to the value of "default_locale".')
->beforeNormalization()->ifString()->then(function ($v) { return [$v]; })->end()
->prototype('scalar')->end()
->defaultValue(['en'])
->defaultValue([])
->end()
->booleanNode('logging')->defaultValue(false)->end()
->scalarNode('formatter')->defaultValue('translator.formatter.default')->end()
@@ -301,7 +301,7 @@ public function load(array $configs, ContainerBuilder $container)
$this->registerEsiConfiguration($config['esi'], $container, $loader);
$this->registerSsiConfiguration($config['ssi'], $container, $loader);
$this->registerFragmentsConfiguration($config['fragments'], $container, $loader);
$this->registerTranslatorConfiguration($config['translator'], $container, $loader);
$this->registerTranslatorConfiguration($config['translator'], $container, $loader, $config['default_locale']);
$this->registerProfilerConfiguration($config['profiler'], $container, $loader);
$this->registerCacheConfiguration($config['cache'], $container);
$this->registerWorkflowConfiguration($config['workflows'], $container, $loader);
@@ -1079,7 +1079,7 @@ private function createVersion(ContainerBuilder $container, $version, $format, $
return new Reference('assets.empty_version_strategy');
}
private function registerTranslatorConfiguration(array $config, ContainerBuilder $container, LoaderInterface $loader)
private function registerTranslatorConfiguration(array $config, ContainerBuilder $container, LoaderInterface $loader, string $defaultLocale)
{
if (!$this->isConfigEnabled($container, $config)) {
$container->removeDefinition('console.command.translation_debug');
@@ -1094,7 +1094,7 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
$container->setAlias('translator', 'translator.default')->setPublic(true);
$container->setAlias('translator.formatter', new Alias($config['formatter'], false));
$translator = $container->findDefinition('translator.default');
$translator->addMethodCall('setFallbackLocales', [$config['fallbacks']]);
$translator->addMethodCall('setFallbackLocales', [$config['fallbacks'] ?: [$defaultLocale]]);
$container->setParameter('translator.logging', $config['logging']);
$container->setParameter('translator.default_path', $config['default_path']);
@@ -248,7 +248,7 @@ protected static function getBundleDefaultConfig()
],
'translator' => [
'enabled' => !class_exists(FullStack::class),
'fallbacks' => ['en'],
'fallbacks' => [],
'logging' => false,
'formatter' => 'translator.formatter.default',
'paths' => [],

0 comments on commit b515107

Please sign in to comment.
You can’t perform that action at this time.