I have a translation yml file like this:
tag:
myfirsttag: Tag number one
secondtag: Tag number two
....
and twig template like
<select name="tag" required="required">
{% for tag in tag_list %}
<option value="{{ tag }}">{{ "tag." ~ tag | trans(domain='mydomain') }}</option>
{% endfor %}
</select>
So here is the problem. Items in select are rendered like "tag.myfirsttag", not translated. If I replace "tag." ~ tag
with hardcoded string like "tag.myfirsttag"
it works well. So obviously it is related to concatenation but official docs doesn't say anything about it.
To be more clear and simple
I can translate
{{ "hello.world" | trans(domain='mydomain') }}
but can't translate
{{ "hello." ~ "world" | trans(domain='mydomain') }}
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 }}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With