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.
http://codex.wordpress.org/Function_Reference/_2
_e( $text, $domain )
The same as __() except it echoes the text instead of returning the value.
http://codex.wordpress.org/Function_Reference/_e
_n( $single, $plural, $number, $domain )
Return the plural or single form based on the $number.
http://codex.wordpress.org/Function_Reference/_n
_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.
http://codex.wordpress.org/Function_Reference/_x
_ex( $text, $context, $domain )
The same as _x() except it echoes the text instead of returning the value.
http://codex.wordpress.org/Function_Reference/_ex
_nx( $single, $plural, $number, $context, $domain )
A hybrid of _n() and _x(). It supports contexts and plurals.
http://codex.wordpress.org/Function_Reference/_nx
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
Translating WordPress:
http://codex.wordpress.org/Translating_WordPress
Official WordPress Translators Team Blog:
http://make.wordpress.org/polyglots
WPML Getting Started Guide:
http://wpml.org/documentation/getting-started-guide
Translating your Theme:
http://code.tutsplus.com/tutorials/translating-your-theme–wp-25014
Thanks for the quick tour of WPML Anthony! I’m curious to know how the data is saved – as separate posts or as post meta? And what happens when you deactivate the plugin?
Hi David! Good question! The content is saved as separate data, in the Posts table. There are also a number of tables that WPML creates which it uses as well, to manage the various languages. The WPML site has a good page that provides some further information on their WPML specific tables.
It’s quite good the way it works, as you can see in the screenshot above, when you view your list of Pages (or Posts), you only see the English (or default language) version of the page, even though the content is still stored in the Posts table.
If you disable the plugin though, the translated content will then appear in the page list. And obviously, since the translated content is still in the database in the Posts table, you can still access it if you know the URL.
Thanks for the question.