François Lefebvre François Lefebvre - 1 year ago 171
Twig Question

How to config twig and Timber to translate full twig templates with {% trans %} tags

I've been trying to make Timber render and translate templates with {% trans %} tags.

I created a .po tranlation file with poedit and Twig-Gettext-Extractor but cannot find a way to make it work with Timber. I added the i18n internationalization extension to twig via Timber

hook but I could not configure my wordpress theme to work. I tried different things from twig docs and here without success.

Is there someone who uses Timber and twig templates with {% trans %} tags and wants to share its config?

Answer Source

Translating themes with Timber is not really different from the way you’d approach it when you’d develop a normal WordPress theme. You probably don’t need any of the functionality provided by Twig’s i18n Extension. You don’t have to work with {% trans %} tags either.

When I went to translate a Timber theme, I followed the Codex page about Multilingual WordPress and the chapter about Internationalization (i18n) in the Theme Handbook. Since Timber version 1.x you can use most of the common translation functions right in your Twig files. There’s a section about using those in the Text Cookbook in the Timber Documentation.

I guess the only thing you have to make sure when you already have your .po and .mo files in the languages folder of your theme is that you properly use load_theme_textdomain.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download