Symfony2 twig translate variable values in {% trans %} tag

你。 提交于 2019-12-20 12:25:05

问题


I'm working on a Symfony2 project and have a question from it. In one twig template I receive a variable from controller. It's a string and I need to translate it. But the syntax

{% trans %}{{ post['name'] }}{% endtrans %}

returns error "A message must be a simple text in...".

So is there a way to translate the variable values???


回答1:


Use filters:

{{ post['name']|trans }}


来源:https://stackoverflow.com/questions/9632502/symfony2-twig-translate-variable-values-in-trans-tag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!