How to translate WordPress themes and plugins with Poedit

Yesterday I wrote about how to translate WordPress themes and plugins with Loco Translate and I mentioned also another method, which is by using Poedit.

Poedit is an open source (MIT license) program available for OS X, Windows and Linux. You can download it here.
It does not only work with WordPress, but with anything that uses the gettext package to manage translations.

In this tutorial though, you will learn how to use it to translate your WordPress theme/plugin.

Translating with Poedit

Installing Poedit is easy as is for any other program in Windows, OS X or Linux. Download it from here and go through the installation wizard to install it.

When you are done, open it for the first time. You should see a screen like this:

poedit-open

As you can see, it has a PRO version too. To create a new WordPress project it says that you need to upgrade to PRO, but you don’t really need it, in fact I never used the PRO version and I was always able to translate WordPress projects, only you need some more steps to set up the project.
If you want though, feel free to support the project and upgrade Poedit to the PRO version.

So, click on File > New and choose the language of your translation. Here you have to choose the original language of your project, not the language you want to translate the theme/plugin to. After this, you need to configure the catalog.

It’s worth to mention here what a catalog is. In the first article of this series I explained what are PO and MO files. Now there’s a new file to learn about, it’s the POT file.
A POT file is a catalog for the original language of the project. It has all the strings included in your project, ready to be translated. So a translator can use that catalog to translate the project in his language.

With Poedit, you need to configure the catalog to get it working properly with WordPress. Go to Catalog > Properties and configure the translation properties like in the screenshot below:

catalog-translation-properties

Now save the catalog. It will be saved as a PO file, but don’t worry, you will change the file extension later.
Open again to the catalog properties and click on the tab Source paths and click on the + just below the box Paths. Choose the main folder of your project. If you saved the project in the folder /languages or /i18n inside your project folder (and you really should save it there), the Source paths tab should now look like this:

catalog-source-paths

Click now on the tab Source keywords. Here you have to specify the functions used in your project to translate. In the case of a WordPress project, they are the translation functions, like __(), _e(), _x(), etc.
But you can’t write them like this, there are specific rules to follow, you also have to specify what the functions get as parameters to let Poedit know if the first string in the function is the source text, a comment for the translator, or something else, so add this in the keywords box, by using the + button at the bottom of the box:

__
_e
__ngettext:1,2
_n:1,2
__ngettext_noop:1,2
_n_noop:1,2
_c
_nc:4c,1,2
_x:1,2c
_nx:4c,1,2
_nx_noop:4c,1,2
_ex:1,2c
esc_attr__
esc_attr_e
esc_attr_x:1,2c
esc_html__
esc_html_e
esc_html_x:1,2c

After doing so, your Source keywords should look like this:

catalog-source-keywords

Click on Ok to save the properties and now you are ready to add the project’s strings to the catalog. Click on Extract from sources to scan all the files inside your project.

Poedit will scan each single file in your project (by following the paths and keywords specified in the catalog properties) and will extract all the needed strings, adding them to the catalog.
At the end of the scan you should have something like this (probably with more than two strings only):

catalog-full

Do not translate anything here. This is the project’s catalog, it does not need to be translated. Save it again and open the folder where you saved it.

You will find here a PO and a MO file. Delete the MO file since you don’t need it for a catalog, and rename the PO file changing the extension to POT. The catalog is now ready. From now on, translators will use it to create their translation.

If you want to do it by yourself, open Poedit, click on File > New from POT/PO file, find and select the POT you just created, and then choose the language you want to translate it to. Translate the project and save the file. It will automatically generate a MO file after saving the PO, and your project will use them to show the strings in that language.

Help the community

If you translated a theme/plugin, you can give a huge help to the community by sharing your translation. Don’t keep it only for you, send it to the theme/plugin author and ask him to include it in the next release so also other people who speak your language can use it.


More Posts That You Might Like…


Leave a Reply

Categories

Newsletter

Receive new articles from this blog directly in your inbox!

No spam guaranteed!

Blog at WordPress.com.

%d bloggers like this: