There’s been a lot of talk recently about the importance of making your theme translatable. It’s also good to remember that it’s worth making your website multilingual. At a recent WordPress Melbourne Developer Meetup, I had the opportunity to talk about creating Multilingual websites with WordPress and WPML and you may be surprised to learn that it’s not as difficult as you might think.
Last month [May 2014], for the first time in history, the non-English downloads of WordPress passed the English downloads. In the future, if we do our job right, the usage of WordPress will democratise publishing. It will resemble every language in the world.
— Matt Mullenweg
With the release of WordPress 4.0, one of the key features is the ability to select your language when you’re installing WordPress. When you do this, WordPress will automatically download and install the appropriate language pack so that your Dashboard will appear in your selected langauge.
There are six basic functions that you should be using when developong your WordPress themes. These are:
__( $text, $domain ) (two underscores)
The most basic translation function. Returns the text in the correct language.
_e( $text, $domain )
The same as __() except it echoes the text instead of returning the value.
_n( $single, $plural, $number, $domain )
Return the plural or single form based on the $number.
_x( $text, $context, $domain )
Used when there’s the chance the text could be found in more than two places, but with different context. Allows you to provide a short description to clarify the text being translated.
_ex( $text, $context, $domain )
The same as _x() except it echoes the text instead of returning the value.
_nx( $single, $plural, $number, $context, $domain )
A hybrid of _n() and _x(). It supports contexts and plurals.
Translating Your Content
Using the awesome WordPress Multilingual Plugin (WPML) plugins, you can easily setup a multilingual website that is both easy to navigate for your site visitors, and also easy to edit from an administrators aspect. Using WPML, you can:
- provide your content in over 40 languages
- give your site visitors handy tools like ‘language switchers’
- access powerful translation management tools
- get easy access to professional translators (for a cost)
- make your WooCommerce store multilingual
- translate theme & plugin texts
After activating the WPML plugin, the first step is to configure it. WPML steps you through this simple 3-step process.
After configuring WPML, the next step is to add your content. Thankfully, WPML makes this process fairly painless. When editing your content, you’re presented with a new Language Panel on the right-hand side of the edit screen. Within the Language Panel you can view what languages the current page has been translated into. You can either switch to one of your translated pages or if need be, create a new page for your translation.
When you view your list of Pages (or Posts) within the Dashboard, WPML makes it easy to see what content has been translated and what hasn’t. Clicking on the small plus symbol allows you to add a new page for translation while clicking the pencil icon will take you directly to the edit page for that specific language.
Once your content has been translated, your visitors will be able to change languages using the various ‘Language Switchers’ that WPML provide. You can have language switchers in the menu, sidebar, below the content and in the footer. You can also add them anywhere in your templates by adding the relevant PHP code. You can also translate your WordPress menus, Widgets and custom Post types, among other things.
This should give the basics for setting up a multilingual site. If you’d like like some more information on making your themes translatable or setting up a multilingual site, then check out the links below. Also, don’t forget to check out my presentation on Slideshare. You can view the slides below or over on Slideshare.
If you’ve created a multilingual site yourself, did you use WPML? Something else? Let me know in the comments below 🙂
Where to Go for Help
Official WordPress Translators Team Blog:
WPML Getting Started Guide:
Translating your Theme: