Translation with POEdit – Internationalize / Localize WP Themes Guide – Part 3

Now that you made your theme translatable, let’s do the necessary to translate it.

For that you will have to use a translation software, in this guide we’ll use POEdit, so go ahead and download then install it.

We will use POEdit to create a PO (Portable Object) file which will contain all the translatable words & phrases and optionally their translation for a specific language. If you add a translation to the PO file, you can setup POEdit to create a MO (Machine Object) file, which is the machine-readable file (the one we need to upload to the server with the theme).

Note: PO files have .po extension & MO files have .mo as extension.

In this guide we will create the MO file in one go with the PO file for a specific language:

Launch POEdit & before anything else make sure it will automatically save a MO file every time we make or modify & save a PO file: Go to File > Preferences…, in the Preferences box choose the Editor tab, under Behavior see if “Automatically compile .mo file on save” is checked, check it if not.

Now let’s start making the PO file, go on File > New Catalog…

A box will pop-up with 3 tabs:

The first one (Project info) is for general information, enter utf-8 for “Source code charset” & you may want to give your project a name (theme’s name maybe). Fill the other fields if you wish …

The second tab Paths is to give POEdit the path of your theme’s directory (on your hard drive), bad thing is that you can’t just click on browse & find the directory of your theme. To get the path, use Windows Explorer, browse till you enter your theme’s folder then copy the path from the Address Bar, the path may look a bit like this:

C:\Documents and Settings\Something\Desktop\theme-directory

Click the “New item” button (graphic icon of a little square & star), a field will be created, paste in your path & hit Enter.

Go to the third tab named Keywords, there you tell POEdit about the two GetText functions “_e” & “__”. Click the “New item” button, a field will be created, type in “_e” (without the quotes), press Enter then click again on “New item” & type “__” (2 underscores without the quotes). Hit Enter again then click on OK. You’ll be asked to give your catalog (PO file) a name, since we’ll use it for a specific language, use the two letters ISO Code of that language, for example “ar” for Arabic or “fr” for French (without the quotes). A long list of ISO codes here on Wikipedia. Once the name given click on OK.

Note: POEdit will create a MO file named just like your PO file (ar.po & for example).

If you did everything correctly, POEdit should start scanning the theme’s files then show you a box with the results, click on OK.

In POEdit now you can see three rows:

The first one has two columns, one for original strings, the ones in the theme’s files that you wrapped in the second step, the second column is for translation, would be empty still. In this first row you can click & select the strings you want to translate (or change translation later).

The second row shows the original string selected in the 1st row (not editable).

The 3rd row is where you will enter the translation for the string selected.

You know what to do now, make your translation for each string then when finished save your catalog (File > Save or Ctrl+S).

What if for some reason you decided later to modify the strings to translate, create new strings or delete strings? (by editing the PHP files of the theme)

After you edit the files, POEdit allows you to update the translatable strings: Open your PO file then go to Catalog > Update from sources, POEdit will scan the files again & pop-up a box with a list of “New strings” & a list of “Obsolete strings” (the one that you may have removed), you click on OK to update the catalog.

OK, now rest to upload the theme to the server with the MO file included in the directory. Make sure you use WordPress translated to the same language, most likely you will find it in the WordPress in Your Language page.

Comments ( 13 )

Comments are closed.