How to Translate Your WordPress Theme Into Any Language

From WordPress 4.0 you’ll be able to select your native language directly from the install screen as shown below.

choose-your-language

This makes it more important than ever to be able to translate your WordPress theme to match the language used on the rest of your site. This post gives you the lowdown on how do to exactly that!

Are All WordPress Themes Translatable?

Not all WordPress themes will be translatable out of the box because it is the theme developers responsibility to implement translation features in the code. So, the first step is to determine whether the theme you are using is translatable. You can do this by checking the theme documentation or by contacting the theme author.

However, this should be largely academic as these days most themes are translatable. If you do come across a theme in the wild that is not translatable then I’d recommend switching to one that does. Immediately!

It goes without saying of course (but I’ll say it anyway) that all our themes are fully translatable and include the necessary translation file(s) to get you started. More on this later.

Are you Speaking my Language?

For a theme to be translatable it must use special functions to wrap text strings contained in the theme, and have a master translation file (a POT file) which is usually found in the theme languages folder.

The translation process utilizes the the POT file shipped with the theme to create an output file with extension .po which is used to display translation phrases in your own language. Let’s do this next.

Introducing Poedit

The program we will be using to translate the theme is Poedit, which is freely available for all major operating systems including Windows, OS X, and Linux. If you haven’t already done so, install Poedit now. Then open it up, and from File the menu select: New catalog from POT file…

poedit_main

  • Note: If you’re using a WPGO theme then the POT file can be found in the languages folder. e.g. The Minn theme languages path is /wp-content/themes/minn-wpgothemes/languages/

Navigate to your own themes languages folder and open the POT file in Poedit. You’ll see the “Catalog properties” dialog box appear. You don’t need to change any of these settings so just go ahead and click OK to close.

poedit-catalogue-properties

You will now be prompted to choose the location and filename for your .po translation file, which is used to store all your theme translations. Make sure you choose to save the .po file in the same directory as the theme POT file.

The default filename will be something like default.po. This is OK for now but you will need to change this later on to be more specific so WordPress knows which file to use for language translation.

For now just go ahead and click Save to close the “Save as…” dialog box. This will create a .po file to your theme languages folder. You may also notice that a .mo file is saved along with the .po file. Make sure that these two files are kept together.

  • Note: If you save your .po file in the parent theme languages folder then that’s fine but you should be aware that it will be overwritten during a theme upgrade. Prevent this by using a child theme and saving the .po file in the child theme languages folder (create one if the folder doesn’t already exist).

All WPGO themes support the .po file being located in the in the parent them languages folder OR the child theme languages folder. If a child theme is active then the child theme languages folder will be checked FIRST. If no language file (that matches the locale set in WP config) is found then it looks in the parent theme languages folder. This means that you can use a custom translation file in a child theme and it won’t ever be overwritten during theme updates!

Creating the Translation Phrases

Now for the fun part! You can start to create theme translations for any phrase used in the theme in your own language! Simply click on a phrase from the list in the main window to get started.

poedit-translate-phrases

  • Tip: In Poedit hit CTRL+F at any time to do a quick search for the phrase you want to translate.

Towards the bottom of the Poedit screen you will see two text boxes. The first one (Source Text) is a read-only box that shows the text of the phrase you just clicked on. The second one (Translation) is where you enter your translations.

As soon as you enter your translated text in the ‘Translation’ text box you will also see it appear in the main window to the right of the original text. Also, for convenience, every translated phrase in the main window has a star added to the very left to make it easy to spot phrases that have already been translated.

poedit-translated-phrase-example

When you have finished editing make sure to save your work by clicking the Save icon.

It’s important that .po (and .mo) filenames match the desired locale as specified in wp-config.php (located in your WordPress root directory). The naming convention is language_COUNTRY.po.

Some examples of .po file names are:
en_US.po
en_UK.po
fr_FR.po

Open up your WordPress wp-config.php file and add the WPLANG PHP constant, if one doesn’t already exist, as follows:

define ('WPLANG', 'en_UK');

In this example I am using the English UK locale so this would require the .po and .mo files to be named as:
en_UK.po
en_UK.mo

The rule of thumb is that whatever your .po and .mo files are called, the WPLANG constant in wp-config.php should be exactly the same (not including the file extension).

If you want to learn more about how WordPress handles language translation then click here to find out more.

Ask any questions regarding theme language translation in the comments. And let us know how you get on translating our themes into your own language!

About David Gwyer

Founder of WPGO themes and lead developer. I love creating themes that are intuitive and easy to use but deceptively powerful! I also enjoy tinkering around with plugins.

Leave a Reply

Your email address will not be published. Required fields are marked *