Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Translating using variables in Symfony2 + Twig is possible?

The first output the string not translated:

{{ chart.name~'.short'|trans({}, "charts") }}

This one works (is the same text that chart.name~'.short' should output):

{{ 'charts.region.area.short'|trans({}, "charts") }}

Am i missing something? It seems it's impossible to translating dynamic text in Twig?

EDIT: working setting a variable (why?):

{% set name = chart.name ~ '.short' %}
{{ name|trans({}, "charts") }}
like image 281
gremo Avatar asked Oct 11 '11 17:10

gremo


1 Answers

Symfony/Twig is trying to translate .short and concatenate it with contents of chart.name. Use parentheses to get the expected output:

{{ (chart.name~'.short')|trans({}, "charts") }}
like image 183
Czechnology Avatar answered Sep 18 '22 21:09

Czechnology