eZ Community » Forums » eZ Publish 5 Platform » Using the Twig i18n extension

Using the Twig i18n extension

Using the Twig i18n extension

Thursday 15 May 2014 4:13:25 pm - 3 replies


for a current project, I need to translate some content that isn't handled by the backend, but comes from some REST web service instead. I thought about using gettext for this task; and the Twig i18n extension (http://twig.sensiolabs.org/doc/extensions/i18n.html) seems to come handy for this.

So I was very happy to find that the i18n extension is already delivered with eZ Publish 5 (vendor/twig/extensions/lib/Twig/Extensions/Extension/i18n.php), and it even seems to be already registered - at least, the {% trans %} tag is accepted without an error message.

But where/how may I add configuration - especially: my own PO/MO files - to the system? I've been searching the web and the source code the whole day now, but I didn't find any documentation or even hint about this.

Any help/hint is very appreciated.


Best regards,


Thursday 15 May 2014 4:19:45 pm

Hi Markus

This Twig extension is not activated by default. It's present as a dependency only. However, Symfony has its internal trans implementation. You should check Symfony documentation about translation for what you need happy.gif Emoticon.

Friday 16 May 2014 10:46:12 am

Hi Jérôme,

thank you very much for your fast reply and your hint - it helped me to solve my problem.

For anybody coming across this thread searching for a similar solution: I just had to create a folder 'MyBundle/Resources/translations' and place my translation files there. Of course the file names had to follow the conventions mentioned here, i.e. domain.locale.loader.

I tried with YAML and MO files (both worked), so I guess that all message loaders mentioned in the Symfony docs are available. Just don't forget to clear the cache!

After that, I was able to use the the Twig trans filter like {{ message | trans }} and the trans tag like {% trans %}Hello World!{% endtrans %}.

hth, and best regards,


Modified on Friday 16 May 2014 10:49:59 am by Markus Mahner

Wednesday 27 January 2016 5:09:42 pm


I’m looking for help with a similar proble, I can’t seem to be able to translate anything in twig.

I’m using ez publish community 2014.11, and have set up my siteaccess like this:

                - fre-FR

I have created the following file in my bundle with the translations:


When I use the "translation:debug" symfony command, I can see the translations that are in my file.

When I display $request->getLocale(), it is "fr_FR".

The multilingual content is porperly translated.

But I can’t seem to be able to translate anything in my twig templates I tried both the twig filter and tags. I also tried to directly use the "translator" service from my controllers without success. I tried several names for my translation fil (.fre-FR.ym in case it was the siteaccess language that mattered, .fr.yml, .fre.yml... basically every combination you can think of).

I did clear my cache several times. I now have no idea where to look.


You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from