我正在创建一个多语言网站,我正在使用BeSimple / BeSimpleI18nRoutingBundle进行路由翻译.我的配置中的路由看起来像这样:
about:
locales: { en: "/{_locale}/about-us",lt: "/{_locale}/apie-mus" }
defaults: { _controller: BaseBundle:Base:about }
但是在这种情况下,我得到重复的路线,好像我输入/ en / about-us或/ lt / about-us它可以两种方式工作.但在第二种方式它应该是404错误,因为lt locale的路由应该是/ lt / apie-mus,它也可以正常工作.
有没有办法解决这个问题?或者也许有更好的翻译方式?
@H_
502_8@
However in this case I get duplicate route
每种语言有一条路线:
$app/console router:debug
about.en ANY ANY ANY /{_locale}/about-us
about.lt ANY ANY ANY /{_locale}/apie-mus
当您使用URL / lt / about-us时,UrlMatcher将与en版本匹配:
$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
在这种情况下,本地将是en而不是lt.
但我不认为您应该担心它,因为访问者访问/ lt / about-us的唯一方法是自己编辑URL.