I'm using the Slim PHP micro framework with Twig and the translation extension i18n.
I have a need to output translated country names, and would prefer to do it using the translation extension rather than building an array and fetching the name manually in PHP.
So I tried this in my Twig template:
{% set country="trans-country-name("~isoCountryCode~")" %}
{% trans %}
This is a list of all the numbers in {{country}}.
{% endtrans %}
and this in my .po file:
msgid "This is a list of all the numbers in %country%."
msgstr "Detta är en lista över samtliga nummer i %country%."
msgid "trans-country-name(NO)"
msgstr "Norge"
I was hoping that this would result in
"Detta är en lista över samtliga nummer i Norge."
but instead I just get
"Detta är en lista över samtliga nummer i trans-country-name(NO)."
Is it possible to have the translation extension parse trans-country-name(NO) as text to be translated?
I think I was going about it sort of backwards. The solution seems obvious in hindsight - simply use the
| transfilter on thecountryvariable first, and then just use that straight in the text to be translated.Twig template:
.pofileMy final solution was to scrap the country code in favour of simply using the country names directly instead: