Skip to content

[Routing] Document the effect of setting locale on a route with locale prefixes #19825

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading