Routes Symfony 5-国际化路线-带有空或动态区域设置的前缀路线

Routes Symfony 5-国际化路线-带有空或动态区域设置的前缀路线,routes,locale,symfony5,Routes,Locale,Symfony5,以下宣言正在发挥作用: app_localized: resource: "../src/Controller/" type: annotation prefix: en: '' # don't prefix URLs for English, the default locale de: '/de' es: '/es' 因此,我们可以访问以下URL: / /德 /es 但我不想在支持的语言发生变化

以下宣言正在发挥作用:

app_localized:
    resource: "../src/Controller/"
    type: annotation
    prefix:
        en: '' # don't prefix URLs for English, the default locale
        de: '/de'
        es: '/es'
因此,我们可以访问以下URL:

  • /
  • /德
  • /es
但我不想在支持的语言发生变化时,每年都更新这个项目的配置文件。我想声明如下路线:

app_localized:
    resource: "../src/Controller/"
    type: annotation
    prefix:
        en: '' # don't prefix URLs for English, the default locale
        '*': {_locale}
因此,可以访问以下URL:

  • /
  • /德
  • /es
  • /nl
  • /fr
  • 还有更多
但遗憾的是,这不起作用。将区域设置定义为模式也很好:
^[a-z]{2}([-])?([a-Za-z]{2})?$


有什么办法解决这个问题吗?

我通常定义两个路由:一个用于非固定路由,另一个用于前缀路由

像这样的东西可能有用

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