Multilingual sites using WordPress

Posted on April 4th, 2011

Let’s have a look on how can we create a multilingual website using WordPress and the WPML plugin

Localization of theme strings

Before installing a plugin on your blog, the first thing to do is to localize theme strings. PHP and the Gettext tool (which allow easy string translation) have two functions: _e() and __().

We have to localize theme string before installing a plug-in on your blog. There are two functions _e() and __() which allow easy string translation for PHP and Gettext tool.

Here that _e() will echo a string and __() is used to assign a string to a variable.

Let’s try with the following code:

<div>

<h1>Welcome to my site!</h1>

<p>I hope you’ll like it.</p>

</div><!– #content –>

We have to wrap all strings into the _e() or __() functions, as shown in the example below:

<div>

<h1><?php _e(“Welcome to my site!”); ?></h1>

<p><?php _e(“I hope you’ll like it.”); ?></p>

</div><!– #content –>

Now the string will be recognized by the WPML plug-in  as translatable strings.

Installation and configuration of WPML plug-in

Now we can install WPML plug-in which will make our blog multilingual. We can install it from the dashboard itself, activate the plug-in, and add the languages.

Translation of theme strings

Now let us translate the  theme strings in French. For that we have to  click on the “Theme and plugins localization” link which you can see under the “WPML” tab. On the “Theme and plugins localization” page, choose the Translate the theme by WPML option, Now you can directly provide translations in your WordPress dashboard. You can also use .mo file, the WPML plugin allows it as well, though you can choose your favorite option.

Translation of site content

WPML is an easy way to translate your site/blog content. You can see a box in the right side while creating/editing pages for the translation.

Translation of your site menu

For translating the navigation menu, Click on “Appearance”, “Menus” and select your current menu. WPML has added some new options to allow you to create a new menu per language. Now, our site is fully multilingual.