0

I've a Symfony 4 app that is running fine until I want to define a route with the _locale parameter.

I define two routes for the same action with the following code :

/**
 * @Route("/sites/{id}",
 *    name="site_get",
 *    methods={"GET"},
 *    requirements={"id": "\d+"},
 * )
 * @Route("/{_locale}/sites/{id}",
 *    name="site_get_with_locale",
 *    methods={"GET"},
 *    requirements={"id": "\d+"},
 * )
 */

When I call the url /sites/1 I get the resource but if I call /en/sites/1 I get a 404 error "route not found".

Here are the things I've tried :

  • tried to change /{_locale}/sites/{id} with /{locale}/sites/{id} and the route is working but, obviously, the locale is not changed.
  • tried to set requirements for the _locale parameter but it is no better
  • tried to set the {_locale} parameter as a prefix (in annotations.yaml) with no luck neither
  • I can see the route definition in the debug:router :
site_get.0                                      GET         ANY      ANY    /api/sites/{id}                                                 
site_get_with_locale.0                          GET         ANY      ANY    /api/{_locale}/sites/{id}

Edit 1 : In the profiler for the given failed request /en/sites/1 :

  • the configuration sections shows me thet the Intl locale is fr.
  • In the routing section I don't see the same at in the debug:router command : Routing section in profilter {_locale} is changed into 0 (even if I set requirement for the _locale to fr|en)

Edit 2 : I was using Symfony 4.4.8 but downgrading to 4.4.7 seems to work. I also have the problem with 4.4.10

Any idea of another path to explore?

Thank you,

Vincent

Vincent
  • 384
  • 1
  • 3
  • 11
  • From a code perspective, everything should work. Actually it worked in my test env. Maybe you are lacking php-intl? – Leprechaun Jul 16 '20 at 14:59
  • The app is running inside a docker container with PHP 7.3 with ICU compiled and intl enabled. When going to the profiler page for the `/en/sites/1` request, in the configuration section it shows intl locale => fr. So I assume that php-intl is correctly set up – Vincent Jul 17 '20 at 08:25

0 Answers0