How to translate concatenated string in twig template using Symfony2 translator How to translate concatenated string in twig template using Symfony2 translator symfony symfony

How to translate concatenated string in twig template using Symfony2 translator


The solution is to put the string into parentheses as described here:

works:

{{ 'hello.world' | trans }}

doesn't work:

{{ 'hello.' ~ 'world' | trans }}

works:

{{ ('hello.' ~ 'world') | trans }}


to translate contact strings you have to make this thing:

{{ ("some string " ~ entity.type ~ " another string")|trans }}

But try writing string to translate like params:eg:

some.funny.string


Is it an associative array, right? Then you should be looping over key=>value pair

<select name="tag" required="required">    {% for key,tag in tag_list %}      <option value="{{ key }}">{{ tag | trans(domain='mydomain') }}</option>    {% endfor %}</select>

Or is your array deeper:

<select name="tag" required="required">    {% for tag in tag_list %}      {% for key,value in tag %}        <option value="{{ key }}">{{ value | trans(domain='mydomain') }}</option>      {% endfor %}    {% endfor %}</select>