I18n the WordPress way

I’m currently in the process of building a WordPress site that will be internationalised for several languages.

I’m already using WordPress’ built in __(); and _e(); functions for anything that isn’t editable in the CMS, I was wondering if there were any other things to look out for, or best practices to follow.

We’ll be using Multisite with domain mapping to serve the various languages to different territories, but are there any other solutions out there that handle i18n better.

The writeup

Having so many others who had worked on i18n WordPress was great and made me consider a few things I hadn’t considered. Luckily I wasn’t going to far wrong, I had prepared some slides but arrived late so went with the markerboard instead.

Everything I had learnt so far was from the WordPress Codex page which is a great place to start.

Essentially all you have to do is wrap any strings you want to be available for i10n in the WordPress functions:

__('Returns hello world', 'my-namespace');
 _e('Echoes hello world', 'my-namespace');
_x('Context', 'Gives a translator some context to the string, to differentiate between a noun or verb for example', 'my-namespace');
_n('Single', 'Plural', 3, 'my-namespace'); 

You then run your theme or plugin through a tool that generates a .pot file that in turn can be used by a translator to generate a .mo file for each language. WordPress offers a tool to do this, but I couldn’t get it working so used an online tool instead.

One thing I hadn’t considered was the slugs of Custom Post Types, but luckily you can use the slug parameter when you register them.

When I came to actually translating strings I found you need to create a languages dir in wp-content that contains an .mo file of the language you want to use, it doesn’t have to contain anything, but as soon as you put one there WordPress will give you the option to use that language.

Vote for this

4 voted vote

2 thoughts on “I18n the WordPress way

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>