From 730a394a97c34a9c59044e1f565b2688db024a72 Mon Sep 17 00:00:00 2001 From: Dominik Hajduk Date: Wed, 28 Mar 2018 16:01:46 +0200 Subject: [PATCH 1/4] Add information about internationalized routing --- routing.rst | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/routing.rst b/routing.rst index 40a3946bcd1..a3d68dc227f 100644 --- a/routing.rst +++ b/routing.rst @@ -675,10 +675,40 @@ route:: Translating Routes ------------------ -Symfony doesn't support defining routes with different contents depending on the -user language. In those cases, you can define multiple routes per controller, -one for each supported language; or use any of the bundles created by the -community to implement this feature, such as `JMSI18nRoutingBundle`_ and +Symfony support for internationalized routes depending on the user locale. + +For YAML configuration you can define an array in the `path` option to define +a different path per locale: + +.. code-block:: yaml + + contact: + controller: App\Controller\ContactController::send + path: + en: /send-us-an-email + nl: /stuur-ons-een-email + +This option is available as well for XML and annotations: + + namespace Acme\DatabaseConfiguration; + + use Symfony\Component\Config\Definition\ConfigurationInterface; + use Symfony\Component\Config\Definition\Builder\TreeBuilder; + + class DatabaseConfiguration implements ConfigurationInterface + { + public function getConfigTreeBuilder() + { + $treeBuilder = new TreeBuilder(); + $rootNode = $treeBuilder->root('database'); + + // ... add node definitions to the root of the tree + + return $treeBuilder; + } + } + +For more advanced needs you can look on community bundles such as `JMSI18nRoutingBundle`_ and `BeSimpleI18nRoutingBundle`_. Keep Going! From 6f0e1b2d787d6fb8e55960cc2bc0ac53e0f5f2a1 Mon Sep 17 00:00:00 2001 From: Dominik Hajduk Date: Wed, 28 Mar 2018 20:59:32 +0200 Subject: [PATCH 2/4] Reword routing internationalisation --- routing.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routing.rst b/routing.rst index a3d68dc227f..d5e3dafdcf0 100644 --- a/routing.rst +++ b/routing.rst @@ -677,7 +677,7 @@ Translating Routes Symfony support for internationalized routes depending on the user locale. -For YAML configuration you can define an array in the `path` option to define +For YAML configuration you can define an array in the `path` option to add a different path per locale: .. code-block:: yaml From 69c58e5fef6328794a30d0687adeb4cc2df1c92f Mon Sep 17 00:00:00 2001 From: Dominik Hajduk Date: Wed, 28 Mar 2018 21:04:59 +0200 Subject: [PATCH 3/4] Add proper code block --- routing.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/routing.rst b/routing.rst index d5e3dafdcf0..00ef9ca2f10 100644 --- a/routing.rst +++ b/routing.rst @@ -690,6 +690,8 @@ a different path per locale: This option is available as well for XML and annotations: +.. code-block:: php + namespace Acme\DatabaseConfiguration; use Symfony\Component\Config\Definition\ConfigurationInterface; From edb2e278e89e5f0a913d7698455fdcba32d79aaf Mon Sep 17 00:00:00 2001 From: Dominik Hajduk Date: Wed, 28 Mar 2018 21:10:12 +0200 Subject: [PATCH 4/4] FIx php annotation example --- routing.rst | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/routing.rst b/routing.rst index 00ef9ca2f10..362c3c028cf 100644 --- a/routing.rst +++ b/routing.rst @@ -690,23 +690,21 @@ a different path per locale: This option is available as well for XML and annotations: -.. code-block:: php +.. code-block:: php-annotations - namespace Acme\DatabaseConfiguration; + use Symfony\Component\Routing\Annotation\Route; - use Symfony\Component\Config\Definition\ConfigurationInterface; - use Symfony\Component\Config\Definition\Builder\TreeBuilder; - - class DatabaseConfiguration implements ConfigurationInterface + class ContactController { - public function getConfigTreeBuilder() + /** + * @Route({ + * "en": "/send-us-an-email", + * "nl": "/stuur-ons-een-email" + * }, name="contact") + */ + public function send() { - $treeBuilder = new TreeBuilder(); - $rootNode = $treeBuilder->root('database'); - - // ... add node definitions to the root of the tree - - return $treeBuilder; + // ... } }