Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony translating routes using BeSimple/BeSimpleI18nRoutingBundle duplicate routes

I'm creating a multi language website and I'm using BeSimple/BeSimpleI18nRoutingBundle for route translations. Route in my config looks like that:

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

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

Is there any way of fixing that? Or maybe any better ways of translating routes?

like image 964
Einius Avatar asked Jun 23 '15 19:06

Einius


2 Answers

However in this case I get duplicate route

There is one route per 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 the 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 will be en and not lt.

But I don't think that you should worry about it because the only way that a visitor will visite /lt/about-us is by editing the URL himself.

like image 194
mykiwi Avatar answered Sep 29 '22 08:09

mykiwi


After battle with BeSimple I switched my project to JMSI18nRoutingBundle in 10 minutes. It works well and resolves problem with routes. Firstly: it containes multiple modes of prefixation (with locale) and secondly it allows to translate every route.

like image 44
Karol Wojciechowski Avatar answered Sep 29 '22 08:09

Karol Wojciechowski