InkThemes Blog

How To Create a PO File of Your Themes i.e. Translation of WordPress Theme In Multiple Languages

Hello friends, till now in my previous posts we have too many times discussed about different WordPress themes and different plugins. This time my post is quite different and is about how you can translate a WordPress theme into some other languages. Though English is a well known common language but still if you want your WordPress theme to be localized into your native language then why to wait for it, just keep on reading follow some of the easy steps as guided here, and congratulate yourself that you have done it.

Before going to the deep of this post, let us first discuss about 3 important and helpful files – .PO, .MO and .POT files.

.PO stands for Portable Object.

.MO stands for Machine Object.

.POT stands for Portable Object Table.

Mechanism/Working :

Actually what we need to do is open a .POT file in a gettext file editor POedit, then translate each line of English text into your selected language (The language you wish to be displayed) and after it save this file with an extension .PO, once it is saved with such extension it automatically forms a .MO file. A .MO file is a compiled format of .PO file.

After this process you need to go to “wp_config.php” file and edit it according to the guidelines given below, save and close it.

That’s it, now when you refresh your site, it will be changed and will be looking according to your translation. This was an overview about WHAT you need to do? Below are some guidelines that will explain  you HOW you need to do?

Guidelines To Translate :

Now if you are already with your .POT file then its well and good otherwise follow this link to do so, by default all the theme owners/developers provide themes with .pot file. This file can be found under the folder “Languages”.

Creating a .PO file -

PO (Portable Object ) is a list of all the English-language text found within the files of a localized WordPress theme translated into desired language.

To create a .PO file download POedit (According to your operating system)

POedit - An open source program for Windows, Mac OS X and UNIX/Linux which provides an easy-to-use GUI for editing PO files and generate MO files.

Once you downloaded and installed it, you need to run/open it on your computer, and then edit your .POT file in it.

This can be done by following step by step procedure mentioned below -

  1. Download the official WordPress POT file
  2. Open this  file in Poedit. (As shown in the image below)

po1

3. A new pop up dialog box containing few options will be displayed which is optional as shown below -

po2

4. Now either click on “OK” and save it or click on “Cancel” and move further, you will view a screen as shown below -

po3

5. Now simply open Google Translator and translate the English language text into the desired language. For an example here I am translating it into french. ( As shown in the images below). Here you first need to copy the text one by one and translate it, then again copy the translated text in the POedit’s translation space.

po4

po5

6. The translation of theme is started now and will display the translated text in front of the original text.

po6

7. Go to File → Save as… to save your translations in a PO file.

8. When you save this as .PO file, open it and then again close it. This will generate a .MO file as shown below.Or you can set your Poedit to always compile a MO file when saving changes by clicking File → Preferences and on the Editor tab check the Automatically compile .mo file on save box.

po6_001

The naming of your .mo files is very important and must match the desired locale otherwise it won’t work. The naming convention is based on the language code (e.g. pt for Portuguese) followed by the country code (e.g. _BR for Brazil). So, the Brazilian Portuguese file would be called pt_BR.mo. See the complete list of language codes and country codes to find your exact locale.

9. Now after renaming your both the files to the exact language and country code, copy the files to Language folder and then open wp_config file and edit a short line code in it.

po7

Open your file and replace the code

define (‘WPLANG’, ‘en_EN’);

to define (‘WPLANG’, ‘fr_FR’); and save it and close it.

Finally you have done it and now refresh your theme/site again, it will be displayed in the new language. Congratulate yourself now. That was all about how you can translate your theme into some other language.

Hope you find this article helpful, let me know through suggestions and comments.

Comments & Responses

  1. Hi,

    Thanks for this usefull info i like your post very much.

    i have some dubt please provide me more info for wp language translation..

    i want to know how i can keep multi language template with in single wordpress theme like i want two language translation on my site for this i provide two language button on front page like english and french.

    when we press enlish it display english language wordpress theme.
    when we press button it display french lanugage theme.

    want to know is it possible in wp theme if possible then how i can do it.

    how to keep multi lanugage template in one wordpress ite..

    looking forward for your precious info..

    once again thanks for this usefull info..

    Thanks

  2. This is really helpful in editing existing file,
    But how to make a new file for my new theme/plugin
    I added all code in __() and _e()
    but at last what to do in poedit to set these all things in a po/pot/mo files to edit.
    Please help.

  3. Hi,

    Nice tutorial ;) I have a query as follows:

    I need to translate the site into multiple languages, would you be so kind and guide me through that, I understand what you have described above, but I believe that is only for changing the language from English to whatever other language you like, I need to have the site made into multiple languages.

    Thanks
    :)

  4. It would be nice to get instructions for “where to position the new generated .po / .mo file pair”, as there are different options to place them:
    1.into “mytheme/languages”?
    2. at the theme main directory?
    3. Elsewhere into wordpress?

    Furthemore, it is necessary to indicate which name it has to carry, as example for spanish:
    1. default.mo … .po?
    2. mytheme_es_ES.mo … .po?
    3. es_Es.mo … .po?

Leave a Reply

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