From e45736e5a79a2624b2ab86aadbfaf3e93424b858 Mon Sep 17 00:00:00 2001 From: Kevin Bond Date: Thu, 31 May 2018 09:56:26 -0400 Subject: [PATCH 1/2] [Routing] add documentation for prefixing i18n routes with a locale --- routing.rst | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/routing.rst b/routing.rst index 68daa866c4f..9d4c4e98789 100644 --- a/routing.rst +++ b/routing.rst @@ -210,6 +210,37 @@ should be used during the request. Defining routes this way also eliminated the need for duplicate registration of routes which minimizes the risk for any bugs caused by definition inconsistency. +A common requirement for internationalized applications is to prefix all routes +with a locale. This can be done by prefixing all your routes. + +.. configuration-block:: + + .. code-block:: yaml + + # config/routes/annotations.yaml + controllers: + resource: '../src/Controller/' + type: annotation + prefix: + en: '/en' + fr: '/fr' + es: '/es' + +You can even have your default locale unprefixed: + +.. configuration-block:: + + .. code-block:: yaml + + # config/routes/annotations.yaml + controllers: + resource: '../src/Controller/' + type: annotation + prefix: + en: '' # empty string (default locale) + fr: '/fr' + es: '/es' + .. _routing-requirements: Adding {wildcard} Requirements From c70d200faf5c65ab0150d0a36e3b8933cf7700f8 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Thu, 31 May 2018 16:17:04 +0200 Subject: [PATCH 2/2] Simplified --- routing.rst | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/routing.rst b/routing.rst index 9d4c4e98789..69f5b5a9330 100644 --- a/routing.rst +++ b/routing.rst @@ -211,7 +211,8 @@ need for duplicate registration of routes which minimizes the risk for any bugs caused by definition inconsistency. A common requirement for internationalized applications is to prefix all routes -with a locale. This can be done by prefixing all your routes. +with a locale. This can be done by defining a different prefix for each locale +(and setting an empty prefix for your default locale if you prefer it): .. configuration-block:: @@ -222,22 +223,7 @@ with a locale. This can be done by prefixing all your routes. resource: '../src/Controller/' type: annotation prefix: - en: '/en' - fr: '/fr' - es: '/es' - -You can even have your default locale unprefixed: - -.. configuration-block:: - - .. code-block:: yaml - - # config/routes/annotations.yaml - controllers: - resource: '../src/Controller/' - type: annotation - prefix: - en: '' # empty string (default locale) + en: '' # don't prefix URLs for English, the default locale fr: '/fr' es: '/es'