There are voluminous WordPress themes and plugins available in the market with multilingual support. Volunteering plugins/themes translation is really a welcoming contribution that helps WordPress users around the world. There are many ways to translate WordPress theme content, by using translator plugins, manual language configuration and more. In a previous tutorial, we have seen how to translate WordPress theme content using Google Language Translator.
WordPress theme should be translation ready to translate the theme content. Search wordpress.org gallery to download the translation ready themes. The translation ready theme will contain .pot (Portable Object Template) file in a languages folder. This file will contain all the translatable strings. WordPress uses gettext (localization and internationalization) system for translation. I used the popular gettext editor Poedit to create the language mapping files (.po, .mo) to translate the strings to a local language. If you are looking for implementing multi-language to a core PHP (WordPress less) website, refer my linked earlier article.
How to Download and Integrate Translation Ready WordPress Theme
Visit WordPress.org and go to Themes->Feature Filter to search the translation ready theme from the gallery. This filter shows a list of WordPress theme tags with the checkbox option. We need to check the Translation Ready option and apply the filter to narrow down the translation-ready themes to download. Extract the downloaded theme zip folder in the WordPress themes directory and activate it using admin panel.
Creating .po .mo Files for .pot Template using gettext Editor
The translation ready theme will contain language folder consisting of .pot file containing the list of translatable strings. These translatable strings have to be mapped to the target language by creating .po and .mo files using gettext editor. Download Poedit gettext editor and install it on your computer. Poedit download is available for Mac, Windows and Linux machines.
After installing Poedit, run this application and select Create New Translation option or navigate via File->New From POT/PO File…menu to choose your theme’s .pot file.
When we select the .pot file, a Poedit wizard will ask the target language specification. We can specify the target language by its name or by the country language code (eg: en_UK). Poedit will list all the translatable strings from the POT template. By selecting each string, we can add the translation in the target language as chosen. The translation should be saved as a .po file and thereby the machine-readable format will also be created with the .mo extension.
Translate Site Theme Content to the Target Language using WordPress Admin
After creating the .po .mo language files, go to WordPress admin area via Settings->General to choose the Site Language. The site language dropdown will show the list of available target languages from which we can choose our preference. By changing the site language option the theme content will be translated to the specified site language. Previously, the WPLANG constant is used for specifying the default site language. But it is no longer required since it is deprecated as of WordPress 4.0.
Let us see how to convert a WordPress theme to be translation-ready in my next post.
This WordPress code tutorial was published on March 21, 2018.