Best practices for Timber and WordPress with multilanguage support Best practices for Timber and WordPress with multilanguage support wordpress wordpress

Best practices for Timber and WordPress with multilanguage support


Multilingual WordPress is a topic where there’s still a lot of debate about how to do it best. So currently there’s probably not a best and most reliable way to do it.

Using multilanguage with Timber is not really different from the way you’d approach it when you build a normal WordPress theme. Be aware that Timber is not the same as Twig. Timber uses Twig, which is a templating engine to make it easier to separate data and logic from you display (HTML) concerns. So if you want to find out how to add multilanguage support, you’d first look how to do it the Timber/WordPress way. You probably don’t need any of the functionality provided by Twig’s i18n Extension, with which you made your first steps.

Read the Codex page about Multilingual WordPress to get started.

You’ll probably want to use a plugin if you want to have content that is pulled from the database translated. Among the popular ones that I have used myself are:

When you have one of those installed and your content ready in multiple languages, then you’re good to go. You don’t really have to change anything in your theme to make the basics work. Adding language switchers or linking to other posts outside of menus is a little different. There you’d have to refer to the documentation of the plugin you’ll be using.

If you have static strings in your theme that you also want to translate, you will have to consider adding internationalization (i18n) to your theme.

Since Timber version 1.x you can use most of the common translation functions right in your Twig files. There’s a guide about internationalization in the Timber Docs.