Internationalizing Your WordPress Plugin

We call “internationalization” to the process of setting up software so that it can be used in different languages. In my case I had a plugin with text strings in English and I wanted to add a Portuguese translation. In wp-config.php I set up the WPLANG variable to pt_PT:

define ('WPLANG', 'pt_PT');

I then used poEdit, a localization tool that works with Mac OS X and that can be downloaded from the poEdit download page. In poEdit, from the File menu select ‘New Catalog’. Fill in the information there and in the ‘Paths’ tab put the plugin directory. In the ‘Keywords’ tab add the missing entries so it looks like this:

At this point it should recognize all the text strings in your code and present a screen where you can add the translations. After that be sure to save the file as pluginname-pt_PT.po, preferably in a directory called ‘translations’ or ‘locales’ (but anything will do). After that you’re all set. In your code you should load the translation like this:

load_plugin_textdomain ( 'your-plugin-name' , FALSE , '/your-plugin-name/translations' );

And strings should have the form:

_e('Choose a Category','your-plugin-name');

That’s it. Let me know if you run into troubles :)

Resources & Further Reading for the Geeks: