WordPress L10n: How to Translate Your Plugin

Tweet

In the first part of this series on WordPress plugin i18n and l10n, we learned how to internationalize a WordPress plugin.

This second (and concluding) part will be a walk-through on making a plugin ready for translation, as well as learning how to localize or translate a plugin into a new language.

The process of making a plugin ready for translation is fairly straight-forward. First of all, you’ll need to generate a .pot file. This file is used by translators to translate your plugin into a new language.

This .pot file contains the original strings (in English) of your plugin.

Here is an example POT file entry:

#: plugin-name.php:123
msgid "Welcome to SitePoint"
msgstr ""

A translator looking to translate the text Welcome to SitePoint (at line 123 in your plugin file) into German will add the translation between the quotation marks.

#: plugin-name.php:123
msgid "Welcome to SitePoint"
msgstr "Willkommen auf SitePoint"

Generating POT file

As previously mentioned, the POT file is the one that is handed to translators, so that they can do their work.

Take note: before generating your plugin POT file, ensure you’ve internationalized your plugin.

There are a couple of ways to generate a POT file for your plugin.

Plugin Repository Admin Tools

The official WordPress plugin repository has a tool for generating the POT file of a plugin which is located at the Admin page of every plugin listing.

To access the Admin page of your plugin, login to the plugin repository and click the green Admin button on the sidebar.

Admin Tools

Follow the short guide below to see how easy it is to generate POT files using the admin tool.

  • Click on Continue in the Generate POT file section.
    POT File
  • Then click on Get POT to download the POT file.

POT File

Poedit

There are a number of Gettext translation editors but Poedit is popular among the WordPress faithful.

The pro version allows you to create the PO/POT file with one click.

If you don’t have the pro version you can easily get this Blank POT and use it as the base of your POT file.

Once you have placed the blank POT in the languages folder of your plugin, double-click on it and open it with Poedit.

Click Update in Poedit to update the POT file with your plugin strings.

Poedit

Finally, click File > Save or Ctrl + S to save the changes.

If you own a Pro version of this tool, generating the POT file is as easy as following the steps below.

  • Click File > New WordPress translation and select your plugin folder.
  • Poedit will skim over your plugin files and extract the translatable string.
  • Select the language of the translation from the pop-up dialog box.
  • Ctrl + S and explicitly save the file as .pot.
  • You can save the file as .po and afterwards rename it to .POT.

Language Selection

A PO and a POT file are similar in that they have the same content format. The subtle differences between them are:

  • It is the .pot file that is used by a translator and not the PO file.
  • It is from the resulting .po translation file a .mo file is compiled.

It is a good idea to offer the POT file along with your plugin, so that translators won’t have to ask you specifically about it.

Plugin L10n

Localization describes the subsequent process of translating an internationalized plugin into a new language.

How to Localize a Plugin

To localize a plugin, grab the plugin POT file, open it in a text editor, and enter the translation of every string at their respective msgstr sections, in between the quotation marks.

Save the file in this format my-plugin-{locale}.po where the {locale} is the language code and/or country code that you defined in the constant WPLANG in the file wp-config.php. For example, the locale for German is de_DE. The my-plugin is the text domain of the plugin.

Remember, it is from the .po file that the resultant .mo file (used by WordPress in translating a plugin) is generated.

Let’s see how to generate the MO file from the PO file.

Online PO to MO converter tool

There are a couple of online tools that convert a .po file to a .mo file. Personally, I use the tool at tools.konstruktors.com.

PO to MO Converter

To generate a MO from a PO file, upload the .pot file. The tool will automatically convert the file, and provide you an .mo file for download.

Using Poedit for L10n

Poedit provides a simple interface for translating plugin strings or texts and can also generate the required MO file from a PO file.

To localize or translate a plugin into a new language using Poedit, follow the guide below.

  1. Open the plugin .pot file with Poedit.
  2. Click on the translatable strings and enter their respective translation in the text area labeled Translation.
    Poedit
  3. When you are done with the translation, save the file in this format my-plugin-{locale}.po. E.g. espw-plugin-de_DE.po where espw-plugin is the text domain and de_DE as the locale.

On saving the PO file, the MO file is automatically generated.

If a translator sends your plugin translation file (the MO and PO files) to you, copy the MO (.mo) file to your plugin language folder for use by WordPress.

When a user operating a Localized version of WordPress uses your plugin, the plugin will then be in their language.

Wrap Up

If you want your plugin to reach the widest possible audience, internationalize it and make it translation ready.

Although you might only be proficient in one language, if you make your plugin ready for translation, it opens up the possibility for people to voluntarily translate your plugin.

If you have any questions, suggestions or contributions, I would be happy to hear them in the comments.

Free book: Jump Start HTML5 Basics

Grab a free copy of one our latest ebooks! Packed with hints and tips on HTML5's most powerful new features.

No Reader comments