【发布时间】:2020-11-26 21:55:10
【问题描述】:
我正在尝试利用 Symfony 4 的多语言(或多语言环境)路由模式。
我的应用程序是真正的国际化应用程序,支持超过 25 种不同的语言,尽管翻译是渐进式的,而且许多路线还没有翻译成某些语言。
在这种情况下,我希望他们恢复为默认英语。
我的config/packages/translation.yaml 看起来像这样:
framework:
default_locale: en
translator:
default_path: '%kernel.project_dir%/translations'
fallbacks:
- en
我的路线在routes.yaml 文件中定义。例如:
about_index:
path:
en: /about-us
pl: /o-nas
controller: Symfony\Bundle\FrameworkBundle\Controller\TemplateController
defaults:
template: About/index.html.twig
现在,每当我使用 pl 或 en 语言环境打开网站时 - 一切都按预期工作,但是当我将其设置为 de 时,我会收到 "Unable to generate a URL for the named route "about_index" as such route does not exist." 错误。
当所需区域设置中的路由尚不存在时,我如何强制 Symfony 回退到 en 路径?
【问题讨论】:
标签: php symfony localization yaml url-routing