Here's what I want to achieve, followed by a compilation of the knowledge I acquired, with no solution.
In a Symfony2 project, without using a dedicated bundle, I want the first directory in path to define the locale. It must be optional:
- 1. http://www.example.com/user/account => default EN locale, user bundle, account controller, default index action.
- 2. http://www.example.com/fr/user/account => forced FR locale...
- 3. http://www.example.com/en/user/account => forced EN locale (needed option even though EN is the default locale)
As I will have over 100 routes at the end of the project, and considering that locales can be added any time, i need all the locale routing to be written only once.
No chance to achieve that with one routing file. An interesting solution from SF2.1 was the chained routing files, explained by Fabien Potencier himself: one file prefixes the locales and chains to the normal routing. Here we are:
The first file, lists non-locale-aware routes and chains to the locale-aware routing file for all other, normal routes.
-- routing.yml:
sys_ajax:
resource: "@SystemAjax/InternalAjax/get"
prefix: /sysajax
locale_routing:
resource: base_routing.yml
prefix: /{_locale}
defaults:
_locale: fr
-- base_routing.yml:
user:
resource: "@UserBundle/Resources/config/routing.yml"
prefix: /user
@BTUserBundle/Resources/config/routing.yml is a normal bundle routing file.
Ok, so that works for URLs with