1 – Localize 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:
The only difference between
__() is that
_e() echo a string while
__() is used to assign a string to a variable.
Let’s say your theme have the following code:
<div class="content"> <h1>Welcome to my site!</h1> <p>I hope you'll like it.</p> </div><!-- #content -->
What you have to do is to wrap all strings into the
__() functions, as shown in the example below:
<div class="content"> <h1><?php _e("Welcome to my site!"); ?></h1> <p><?php _e("I hope you'll like it."); ?></p> </div><!-- #content -->
Once done, your string will be recognized by the WPML plugin (we’re going to install it) as translatable strings.
2 – Install and configure the WPML plugin
Now that your theme is fully localized, the next step is to install the WPML plugin, which will make our blog multilingual. Install the plugin using your WordPress dashboard and activate it, then you’ll see a “WPML” link on your WordPress dashboard. Click on it and add at least one language.
3 – Translate theme strings
Once done, you now have to translate your theme strings in French. To do so, click on the “Theme and plugins localization” link located under the “WPML” tab. On the “Theme and plugins localization” page (See screenshot below) choose the Translate the theme by WPML option, so you’ll be able to directly provide translations in your WordPress dashboard. Though, if your prefer using a .mo file, the WPML plugin allows it as well, so feel free to choose your favorite option.
4 – Translate site content
Now, you have to translate your site/blog content. WPML provide an easy way to do it: Simply edit one of your posts or pages and have a look at the right side of the screen: you’ll see a box where you can create a translation for each of your posts and pages.
Translating your site content can take a while if your site have lots of pages, but thanks to the WPML plugin it is pretty easy to do.
5 – Translating your site menu
Right now, almost all your site is fully multilingual. Though, you still have to translate your navigation menu. To do so, simply go to “Appearance”, “Menus” and select your current menu. As you can see on the screenshot below, WPML has added some new options to allow you to create a new menu per language. How cool is that?
Right now, you should have a fully multilingual website. Hope you enjoyed this tutorial!