Symfony 翻译不起作用

Symfony Translation not work

我已经覆盖 app/Resources/FosUserBundle

中的 FosUser 配置文件模板

一切正常,但翻译不工作!

示例:

app/Resources/translations/messages.en.yml中:

foo.bar: baz

app/Resources/FosUserBundle/views/Profile/show_contect.html.twig

 {{ 'foo.bar' | trans }}  --> output: foo.bar

语言环境没有问题:app.request.locale --> en

$ php bin/console debug:translation en

@gp_sflover 建议 symfony 不使用默认消息目录来管理模板,因此您可以添加新文件 FOSUserBundle.en.yml 并强制使用 trans 过滤器进行翻译messages目录如下:

 {{ 'foo.bar' | |trans({}, 'messages') }}

希望对您有所帮助

stated in documentation 一样,您应该将翻译消息文件 messages.en.yml 放入文件夹 app/Resources/FOSUserBundle/translations/