Most of the WordPress themes are created in English, and even though a big number of themes is translated to other languages, there are still many templates which aren’t translated.
Here I’m going to tell you how you can translate a theme with the help of program Poedit.
Don’t Translate Source Code of a Theme
One of the most frequent mistakes of beginning web developers and end users is translating lines in PHP files of the theme from one language to another. For localization WordPress uses GNU gettext technology, which says a source code has to be written in English. This lets the theme to be translated into any other language, and to share the translation in a specific, separate from the source code, format.
This approach lets translate WordPress themes without altering their source code. At the same time, your translation won’t dissapear after a theme update.
Is a Theme Ready for Translation?
Not all of the WordPress themes can be translated the right way. It depends on the developer: whether he prepared the theme for a translation or not. Preparing a theme for translation deserves a special attention.
However, finding a translation-ready theme is quite easy. In a WordPress theme directory there is a tag ‘Translation-ready’ which means a developer has prepared the theme for translation and you can translate it into your language not interfering into the source code.
Here you can see all translation-ready themes on WordPress.org.
If you’ve chosen a theme not from the official directory, you should look on the developers website if the themes are translation-ready. Keep in mind, downloading themes from non-official sources is potentially dangerours.
.PO & .MO files
After having downloaded a theme, find a directory named ‘Languages’. Inside you’ll see various files containing theme translations and also a template for translation. The name of the file responds to the locale of a specific language.
Translation files have extension .po and .mo: .po files contain translated lines in text format, a theme translator works with these files; mo.files are the same, but compiled, files. The WordPress core works with these files for displaying a translation.
After editing the translation in the .po file, you should compile .po to .mo so the changes are saved. Poedit does that automatically.
Translation of a Theme With the Help of Poedit
Poedit is a translation editor for working with .po and .mo files. Here you can download it.
After opening Poedit, go to ‘File’, create a new catalog from POT file, and select the POT in your theme’s languages folder. Poedit will ask you to fill out the information about what you are translating, after which you should save your new catalog into the same languages directory. Pay particular attention to naming your translation file: you should name it according to the target language and country of the translation: aa_BB.po, where ‘aa’ is a language code and ‘BB’ is a country code. For example, if the language you are translating into is French, your file’s name should be fr_FR.po, but if you are translating into Tagalog for the Philippines, the name will be tl_PH.po.
In order to edit translation, simply open the corresponding .PO file.
Working with Poedit is simple – the source text is on the left, and your translation is on the right. When you save your translation, Poedit automatically compiles your translation and creates both .MO and .PO files in the language folder.
Setting Up a Translated Theme
Use FTP to open the wp_config file, find a line containing WPLANG and add this:
define (‘WPLANG’, ‘aa_BB’);
By doing this you let your WordPress know you want it to use these translation files.
Note: after these changes, your website will be displayed in the language into which you’ve made a translation, but your dashboard will still be in WordPress default language, as you’ve made changes to front-end only.
Share Your Work with WordPress Pals
After completing the translation, you can get in touch with the theme developer and send him or her .PO and .MO files. The translation may get to the next theme update and other users will be able to enjoy the theme in the language you’ve translated it into.