Description
Symfony version(s) affected: All
Description
When using internationalized routes with _locale as a prefix, the UrlGenerator creates routes with the correct route name but the wrong _locale.
For example:
When there are two routes available:
en: /bug
de: /fehler
Then the CompiledUrlGenerator and UrlGenerator generate /en/fehler for the German route when en is the default locale.
How to reproduce
https://github.com/git-chrisp/symfony-routing-bug
Visit the path /de/fehler. It should show /de/fehler but shows /en/fehler instead as en is the default locale.
This repository is the website skeleton with the following additions:
- DefaultController with one route
- The prefix has been configured in config/routes/annotations.yaml
- One template to show the bug
Possible Solution
In line 59 of the CompiledUrlGenerator (https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Routing/Generator/CompiledUrlGenerator.php):
$parameters['_locale'] = $locale ?? $defaults['_locale'];
Same has to be done in the UrlGenerator: https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Routing/Generator/UrlGenerator.php
Additional context
Please correct me if I'm wrong or my proposed fix doesn't work. Otherwise, I'd gladly create a pull request.