Posted on Sep 30 2010 by Alistair Barnett in Tutorials
Lately, more and more people are asking us how to translate a WordPress theme into a language other than English. And with an estimated 2 billion people now online, it’s no wonder. Fortunately, it’s a fairly straightforward process, and I’ve boiled it down into 3 simple steps.
This tutorial assumes the WordPress theme to be translated has been localized using the the GNU gettext framework. In other words, the theme is ready to be translated. If your theme has not been localized, you’ll need to go through each theme file and convert all English language text into a gettext function. See here for a short description on how to do that.
POT stands for “Portable Object Template,” and a POT file (aka .po file) is basically a list of all the English-language text found within the files of a localized WordPress theme. You can find links to the POT files for Solostream’s premium wordpress themes in the Solostream support forum here (you’ll just need to login to the forum first).
If you’re using a theme other than a Solostream theme (gasp), check with the theme author to see if they offer a POT file. If they don’t, you can easily create your own POT file with a free program called POEdit (see Creating POT Files).
Once you have the POT file, you’ll need to open it in a program like POEdit, and translate the English language into your preferred language. When complete, you’ll want to save the file twice, as two separate files – a .po file and a .mo file. When you save the files, you must name them according to your language code.
Find a list of language codes at WordPress in your Language. As an example, the language code for English is en_EN, so you would save the translated files as en_EN.po first, then en_EN.mo. When that’s done, simply upload the files to your theme folder.
If your theme does not already include it, you’ll need to add the following line to the very top of your functions.php file (just before the opening
<?php load_theme_textdomain('text_domain'); ?>
Notice “text_domain” above – it’s called the text domain name. You can use any name you want, but you should use the same name that’s used throughout the theme in the gettext function.
So, for example, if your gettext functions look something like this:
<?php _e("About the Author", "wp-inspired"); ?> …
You’ll want to use “wp-inspired” in place of the text_domain above.
Finally, if you haven’t done so already, you’ll need to make sure your wp-config.php file matches your language files. For example, if you’re using a French translation, you’ll need to add the fr_FR.po and fr_FR.mo files to your theme folder, then set your language in wp-config.php, like this:
define ('WPLANG', 'fr_FR');
By the way, your wp-config.php file is located in the main directory where all your core WordPress files are located.
Save your wp-config.php file, upload it to your WordPress installation, and you are ready to go.