以下声明有效:
app_localized:
resource: "../src/Controller/"
type: annotation
prefix:
en: '' # don't prefix URLs for English, the default locale
de: '/de'
es: '/es'
所以我们可以访问以下网址:
但是当支持的语言发生变化时,我不想每年更新这个项目的配置文件。我想声明如下路线:
app_localized:
resource: "../src/Controller/"
type: annotation
prefix:
en: '' # don't prefix URLs for English, the default locale
'*': {_locale}
因此可以访问以下网址:
但遗憾的是这行不通。将语言环境定义为模式也很好:
^[a-z]{2}([-])?([A-Za-z]{2})?$
任何想法如何解决这个问题?
答案 0 :(得分:0)
我通常定义两种路由:一种用于无前缀路由,另一种用于带前缀
这样的事情可能会奏效
app_localized:
resource: "../src/Controller/"
type: annotation
prefix: '/{_locale}'
name_prefix: 'localized_'
app_default:
resource: "../src/Controller/"
type: annotation
prefix: '/'
name_prefix: 'default_'
defaults:
_locale: en