diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
index a2016b38c4857..65cf6e55995ed 100644
--- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
+++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
@@ -669,6 +669,7 @@ private function addTranslatorSection(ArrayNodeDefinition $rootNode)
->{!class_exists(FullStack::class) && class_exists(Translator::class) ? 'canBeDisabled' : 'canBeEnabled'}()
->fixXmlConfig('fallback')
->fixXmlConfig('path')
+ ->fixXmlConfig('enabled_locale')
->children()
->arrayNode('fallbacks')
->info('Defaults to the value of "default_locale".')
@@ -689,12 +690,6 @@ private function addTranslatorSection(ArrayNodeDefinition $rootNode)
->arrayNode('enabled_locales')
->prototype('scalar')
->defaultValue([])
- ->beforeNormalization()
- ->always()
- ->then(function ($config) {
- return array_unique((array) $config);
- })
- ->end()
->end()
->end()
->end()
diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
index 8b20c27f4db32..09d141b2d234f 100644
--- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
+++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
@@ -354,7 +354,7 @@ public function load(array $configs, ContainerBuilder $container)
$this->registerProfilerConfiguration($config['profiler'], $container, $loader);
$this->registerWorkflowConfiguration($config['workflows'], $container, $loader);
$this->registerDebugConfiguration($config['php_errors'], $container, $loader);
- $this->registerRouterConfiguration($config['router'], $container, $loader);
+ $this->registerRouterConfiguration($config['router'], $container, $loader, $config['translator']['enabled_locales'] ?? []);
$this->registerAnnotationsConfiguration($config['annotations'], $container, $loader);
$this->registerPropertyAccessConfiguration($config['property_access'], $container, $loader);
$this->registerSecretsConfiguration($config['secrets'], $container, $loader);
@@ -845,7 +845,7 @@ private function registerDebugConfiguration(array $config, ContainerBuilder $con
}
}
- private function registerRouterConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader)
+ private function registerRouterConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader, array $enabledLocales = [])
{
if (!$this->isConfigEnabled($container, $config)) {
$container->removeDefinition('console.command.router_debug');
@@ -864,6 +864,11 @@ private function registerRouterConfiguration(array $config, ContainerBuilder $co
$container->getDefinition('routing.loader')->replaceArgument(1, ['utf8' => true]);
}
+ if ($enabledLocales) {
+ $enabledLocales = implode('|', array_map('preg_quote', $enabledLocales));
+ $container->getDefinition('routing.loader')->replaceArgument(2, ['_locale' => $enabledLocales]);
+ }
+
$container->setParameter('router.resource', $config['resource']);
$router = $container->findDefinition('router.default');
$argument = $router->getArgument(2);
diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml
index 96ac2c72b4b23..bf739e71ab467 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml
+++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml
@@ -48,6 +48,7 @@
+
diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd b/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd
index 97c392812e9f2..23a13677cce9c 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd
+++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd
@@ -169,6 +169,7 @@
+
diff --git a/src/Symfony/Bundle/FrameworkBundle/Routing/DelegatingLoader.php b/src/Symfony/Bundle/FrameworkBundle/Routing/DelegatingLoader.php
index f25bdf32d77b1..36533e12f08a8 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Routing/DelegatingLoader.php
+++ b/src/Symfony/Bundle/FrameworkBundle/Routing/DelegatingLoader.php
@@ -29,10 +29,12 @@ class DelegatingLoader extends BaseDelegatingLoader
{
private $loading = false;
private $defaultOptions;
+ private $defaultRequirements;
- public function __construct(LoaderResolverInterface $resolver, array $defaultOptions = [])
+ public function __construct(LoaderResolverInterface $resolver, array $defaultOptions = [], array $defaultRequirements = [])
{
$this->defaultOptions = $defaultOptions;
+ $this->defaultRequirements = $defaultRequirements;
parent::__construct($resolver);
}
@@ -73,6 +75,9 @@ public function load($resource, string $type = null)
if ($this->defaultOptions) {
$route->setOptions($route->getOptions() + $this->defaultOptions);
}
+ if ($this->defaultRequirements) {
+ $route->setRequirements($route->getRequirements() + $this->defaultRequirements);
+ }
if (!\is_string($controller = $route->getDefault('_controller'))) {
continue;
}
diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php
index 813b51541e38a..b11b5e08dcb96 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php
+++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php
@@ -50,6 +50,7 @@
'fallback' => 'fr',
'paths' => ['%kernel.project_dir%/Fixtures/translations'],
'cache_dir' => '%kernel.cache_dir%/translations',
+ 'enabled_locales' => ['fr', 'en']
],
'validation' => [
'enabled' => true,
diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml
index aaeeba580a268..10a646049d766 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml
+++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml
@@ -28,6 +28,8 @@
%kernel.project_dir%/Fixtures/translations
+ fr
+ en
diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml
index fff49e7528180..5ad80a2da4db2 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml
+++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml
@@ -41,6 +41,7 @@ framework:
default_path: '%kernel.project_dir%/translations'
cache_dir: '%kernel.cache_dir%/translations'
paths: ['%kernel.project_dir%/Fixtures/translations']
+ enabled_locales: [fr, en]
validation:
enabled: true
annotations:
diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php
index 6f1c924f361ce..7ac19bcd18ed0 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php
+++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php
@@ -458,6 +458,8 @@ public function testRouter()
$this->assertEquals($container->getParameter('kernel.project_dir').'/config/routing.xml', $container->getParameter('router.resource'), '->registerRouterConfiguration() sets routing resource');
$this->assertEquals('%router.resource%', $arguments[1], '->registerRouterConfiguration() sets routing resource');
$this->assertEquals('xml', $arguments[2]['resource_type'], '->registerRouterConfiguration() sets routing resource type');
+
+ $this->assertSame(['_locale' => 'fr|en'], $container->getDefinition('routing.loader')->getArgument(2));
}
public function testRouterRequiresResourceOption()
diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Routing/DelegatingLoaderTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Routing/DelegatingLoaderTest.php
index de7f91ee637a7..13a7f5547c0ed 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Tests/Routing/DelegatingLoaderTest.php
+++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Routing/DelegatingLoaderTest.php
@@ -32,13 +32,13 @@ public function testLoadDefaultOptions()
$routeCollection = new RouteCollection();
$routeCollection->add('foo', new Route('/', [], [], ['utf8' => false]));
- $routeCollection->add('bar', new Route('/', [], [], ['foo' => 123]));
+ $routeCollection->add('bar', new Route('/', [], ['_locale' => 'de'], ['foo' => 123]));
$loader->expects($this->once())
->method('load')
->willReturn($routeCollection);
- $delegatingLoader = new DelegatingLoader($loaderResolver, ['utf8' => true]);
+ $delegatingLoader = new DelegatingLoader($loaderResolver, ['utf8' => true], ['_locale' => 'fr|en']);
$loadedRouteCollection = $delegatingLoader->load('foo');
$this->assertCount(2, $loadedRouteCollection);
@@ -48,6 +48,7 @@ public function testLoadDefaultOptions()
'utf8' => false,
];
$this->assertSame($expected, $routeCollection->get('foo')->getOptions());
+ $this->assertSame(['_locale' => 'fr|en'], $routeCollection->get('foo')->getRequirements());
$expected = [
'compiler_class' => 'Symfony\Component\Routing\RouteCompiler',
@@ -55,5 +56,6 @@ public function testLoadDefaultOptions()
'utf8' => true,
];
$this->assertSame($expected, $routeCollection->get('bar')->getOptions());
+ $this->assertSame(['_locale' => 'de'], $routeCollection->get('bar')->getRequirements());
}
}