Is WordPress capable of handling the intricacies of Multilingual websites? The short answer is a resounding YES! Let’s explore how to build a multilingual theme and website together in this guide.
Step 1: Choosing a MultiLanguage Plugin
First of all, we need to understand that WordPress in itself does not come with any multilanguage features. You will need to install a plugin to really get going. There are a number of alternatives, which we have already discussed in a previous post about WordPress multilanguage plugins. For this tutorial we will be using WPML, which is probably the most supported and fully featured of all WP multilanguage plugins.
WPML has recently made the transition from being a free plugin to being a paid plugin. Although we would always like things to be free, I believe the improvements brought about by the change are worth the cost. The code is now much cleaner and more secure. Moreover they have the divided the plugin into several smaller plugins which can be enabled on demand, thus reducing the load on your server. The switch to a commercial model will also enable the WPML team to focus more on support and improving the plugin. According to their website, the next releases will improve interoperability with popular plugins such as W3TC, AIOSEOP, Shopp, WP E-Commerce and NextGen Gallery. We definitely look forward to such improvements.
The first step to Multilanguage nirvana is thus purchasing WPML and installing it on your site. For a start, I recommend you install the following:
- WPML Multilingual CMS (the core plugin)
- WPML String Translation (add-on)
- WPML Translation Management (add-on)
Step 2: Translating the Theme
If you have downloaded a free theme or purchased one, chances are that it is already set up to be multilanguage compatible. If however you are creating the theme yourself you need to make sure to implement some minor changes in order to transform it into a multilingual theme. The nice thing about WPML is that you don’t need to create any .mo or .po files yourself, all this is handled by the WPML String Translation add-on.
WPML provide 2 excellent guides on how to create a multilingual theme, so we won’t be repeating the information here. It is worth mentioning that themes should use GetText for localisation. Take a look at the WPML guides:
Linking to the Home Page
When linking to the Home page of your site, you need to use the following function to load the correct language according to what the user had selected:
<a href="<?php echo wpml_get_home_url() ?>">
Using Hard Coded Links in the Theme
If you are including any hard coded links in your theme, you need to use this:
wpml_link_to_element($element_id, $element_type='post', $link_text='', $optional_parameters=array(), $anchor='');
More info on this here:
Returning the Right Contents Per Language
When getting posts into a page or post template (for example to display a few featured posts), you need to adjust the IDs to reflect the language that has been selected. You can use the following code for this:
wpml_get_object_id($element_id, $element_type='post', $return_original_if_missing=false, $ulanguage_code=null);
Other Plugins that Can Be Useful
Amir Helzer of WPML has recently penned an article entitle 9 Killer Plugins for a WordPress Multilingual Website, you should definitely check it out for more ideas about plugins you can use when building a multilanguage site in WordPress.
Do you have any experience building multilingual sites with WordPress? Have you used WPML or other plugins for the job? Share your experience in the comments section!