Symfony translates routes using BeSimple / BeSimpleI18nRoutingBundle duplicates routes

I am creating a multilingual website and I am using BeSimple/BeSimpleI18nRoutingBundle to translate the route. The route in my configuration is as follows:

 about: locales: { en: "/{_locale}/about-us", lt: "/{_locale}/apie-mus" } defaults: { _controller: BaseBundle:Base:about } 

However, in this case, I get a repeating route, as if I entered / en / about -us or / lt / about-us, it works both ways. but in the second case it should be 404 error, because the route for lt locale should be / lt / apie -mus, which also works fine.

Is there any way to fix this? Or maybe the best ways to translate routes?

+6
source share
2 answers

However, in this case, I get a repeating route

There is one route for each language:

 $ app/console router:debug about.en ANY ANY ANY /{_locale}/about-us about.lt ANY ANY ANY /{_locale}/apie-mus 

When you are on the URL /lt/about-us , UrlMatcher will match the en version:

 $ app/console router:match /lt/about-us Route "about.en" matches [router] Route "about.en" Name about.en Path /{_locale}/about-us Path Regex #^/(?P<_locale>[^/]++)/about\-us$#s Host ANY Host Regex Scheme ANY Method ANY Class Symfony\Component\Routing\Route Defaults _controller: AppBundle:Default:index _locale: en Requirements NO CUSTOM Options compiler_class: Symfony\Component\Routing\RouteCompiler 

In this case, the local one will be en , not lt .

But I don’t think you should worry about this, because the only way the visitor will see /lt/about-us is to change the URL itself.

+8
source

After the battle with BeSimple, I switched my project to JMSI18nRoutingBundle in 10 minutes. It works well and solves the problem with routes. Firstly: it contains several prefixation modes (with a locale), and secondly, it allows you to translate each route.

+4
source

Source: https://habr.com/ru/post/989641/


All Articles