Symfony2 twig translate variable values in {% tran

2020-05-27 02:14发布

问题:

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 }}