Skip to content

Commit

Permalink
[Routing] Document the effect of setting locale on a route with loc…
Browse files Browse the repository at this point in the history
…ale prefixes
  • Loading branch information
nicwortel authored and javiereguiluz committed Jun 21, 2024
1 parent ef7b670 commit 55215ca
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions routing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2416,6 +2416,54 @@ with a locale. This can be done by defining a different prefix for each locale
;
};
.. tip::

If the special :ref:`_locale <routing-locale-parameter>` routing parameter
is set on any of the imported routes, that route will only be available
with the prefix for that locale. This is useful when you want to import
a collection of routes which contains a route that should only exist
in one of the locales:

.. configuration-block::

.. code-block:: php-annotations
// src/Controller/CompanyController.php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class CompanyController extends AbstractController
{
/**
* @Route("/about-us/en-only", locale="en", name="about_us")
*/
public function about(): Response
{
// ...
}
}
.. code-block:: php-attributes
// src/Controller/CompanyController.php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class CompanyController extends AbstractController
{
#[Route('/about-us/en-only', locale: 'en', name: 'about_us')]
public function about(): Response
{
// ...
}
}
Another common requirement is to host the website on a different domain
according to the locale. This can be done by defining a different host for each
locale.
Expand Down

0 comments on commit 55215ca

Please sign in to comment.