TWIG:带变量的字符串翻译?

TWIG: Translation of string with variables?

在我的 translation.yml 我有这个变量:

all.in.EN: All In Great Britain

在我的 Twig 中,我有这样的东西:

{% trans %}all.in.{{ countryKey }}{% endtrans %}

这行不通所以我试着把它放在一个变量中:

{% set allInName = 'all.in.{{ countryKey }}' %}
{% trans %}allInName{% endtrans %}

但随后的输出是 allInName 而不是翻译。有人知道我做错了什么吗? 赞!

尝试

{% set allInName = 'all.in.' ~ countryKey %}
{{allInName | trans}}

你可以尝试这样做:

{{ ('all.in.'~countryKey)|trans }}

已经测试过这个作品。 '~'符号是连接,|trans filter translate