How to internationalise a wordpress plugin

If you want your plugin to have a greater reach why not internationalise it – hopefully people will soon start translating it for you!

Here’s what to do!

Step 1

set up the plugin to load the translation files with this code, changing “your-plugin-name” as needed.

That means that wordpress will load the right translation file from your plugins languages directory.

Step2

Change all the output text in your plugin to use the internationalised versions

so $foo= ‘Blah Blah’; becomes $foo=__(‘Blah Blah’,’your-plugin-name’);
and
echo ‘Blah Blah’; becomes _e(‘Blah Blah’,’your-plugin-name’);
Thoroughly test your plugin at this stage!

Step 3

Set up the initial default translation file defautlt.po in the languages folder.
Download and install poedit from http://www.poedit.net/download.php
The instructions are about as useful as a chocolate teapot, hence this blog post.

Once you have installed the Poedit program, open it.
poedit-first-screen
Click on File then New catalog…
poedit-new-catlog-first-tab
Fill out the Project Name at least and then click on the Sources Path tab.
This is where everyone goes wrong on Windows computers! The base path needs to be the full path to your plugin root directory not “.” e.g. C:\xampp\htdocs\wordpress\wp-content\plugins\church-admin
Then you can add the sub directories in the paths section by clickingthe second icon from the left (dotted box type icon).

Next click on the Sources Keywords tab and select each of the current ones and delete them.
Add __ and _e and then press ok

With any luck you will not get the annoying “Updating the catalog failed error” which happens when you don’t do the full windows path.
poedit-error

Now you can save the file as default.po in the languages folder of your plugin.

Click on Update at the top and it will search your php files finding words that will need to be translated

poedit-done

Click save to save it!
Then commit the default.po file and language directory using your SVN programme and let your user base now of the update, by announcing it readme.txt, your facebook plugin page, twitter account….

Hope that helps. A future post will be how to translate your favourite wordpress plugin!

Leave a Reply

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