How to make a multilingual website on WordPress

by | Jul 16, 2013 | Marketing and communication

Home 9 Marketing and communication 9 How to make a multilingual website on WordPress

More and more customers are asking for a multilingual website to intercept foreign markets. How to do on WordPress? The solution is the free plugin qTranslate, but it is not enough just install it: you need to build an efficient structure, to set the qTranslate parameters, to add extensions and fix something in the code. Thre are not simple operations are required a deep knowledge about WordPress and some basics of Php language; but, once settled, qTranslate plugin is very effective and easy to use. Below I will write step by step how to make a multi-language website on WordPress, using the example of a blog both in Italian and English.

The first question is: should I set two installations of WordPress or I have to create the multilingual site in one installation? They are both possible paths. If we want to create two different websites, one for every language and independent of each other, the best solution is that of the two installations. But, if we want to create a double site in two languages with the same pages and the same items, with double installation we would waste so much time in the construction phase and in the content management. In this case, the best solution is to connect all the languages in iìone website and organize contents through a plugin like qTranslate.

Is it better to use a subdomain or a directory system for a multilingual site? In other words: en.website.com or website.com/en? There are great differences between the two options and both are used by Google Webmaster Tools for geotargeting. The subdomain is slightly more effective for search engines because it allows different positions of the server, and then it divides more sharply the languages. However, the directory structure is perceived better by the user and it is easier to manage. Evaluating the pros and cons of the two options, the second is the recommended one.

We chose the domain. Now we can install the plugin qTranslate for WordPress and discover the basic functionality. You can install a widget that allows you to insert the flags within the site to read the contents in all languages selected (we can add all the languages that we want, even invented ones). By an intuitive interface of the editor of posts and pages, we can set the title and the body text in the languages chosen. We can also change title, description and keywords in the fields of the plugin All in one Seo, or category names and titles of the widgets by inserting before the text the codes associated with the languages, for example [: it] and [: en]

But this system is not enough. How to translate parts of code or text widget with qTranslate? First of all, you have to install the plugin qTranslate Extension and to replace rows from 202 to 210 of its php file with the Java code that follows.

jQuery(document.body).bind('click.widgets-toggle', function(e){
     var target = jQuery(e.target);
     if ( target.hasClass('widget-control-save') ) {
          var form = target.parents('form:first');
          if(form.hasClass('multilanguage-form')){
               prepareMultilanguageData(form);
               setTimeout(function(){
                    generateMultilanguageElements(form.parent());
               },2500);
          }
          e.preventDefault();
     }
});

In this way we solve the problem of the text widget that now understands the language codes. To work on the code of the pages you have to copy php commands like the following.

English text

To fix a bug in the menu, we have to add the following code in the file functions.php.

To fix a bug in the menu, we have to add the following code in the file functions.php.

add_filter('walker_nav_menu_start_el', 'qtrans_in_nav_el', 10, 4);
    function qtrans_in_nav_el($item_output, $item, $depth, $args){
        $attributes  = ! empty( $item->attr_title ) ? ' title="'  . esc_attr( $item->attr_title ) .'"' : '';
        $attributes .= ! empty( $item->target )     ? ' target="' . esc_attr( $item->target     ) .'"' : '';
        $attributes .= ! empty( $item->xfn )        ? ' rel="'    . esc_attr( $item->xfn        ) .'"' : '';

       // Determine integration with qTranslate Plugin
       if (function_exists('qtrans_convertURL')) {
          $attributes .= ! empty( $item->url ) ? ' href="' . qtrans_convertURL(esc_attr( $item->url )) .'"' : '';
       } else {
          $attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : '';
       }

       $item_output = $args->before;
       $item_output .= '';
       $item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
       $item_output .= '';
       $item_output .= $args->after;

       return $item_output;
    }

How can you manage a Seo optimizion for a website that uses the multilingual WordPress plugin qTranslate? We have seen that it is easy to change title, description and keywords thanks to the language codes that are accepted by the All in One SEO Pack plugin. But it is not possible to translate the URL which is very important for indexing on Google and on the search engines. To fix this problem, you just have to install the plugin qTranslate slug with Widget and replace the flags widget with the one that now is available. We can finally translate the URL of posts, pages and categories from the fields qTranslate Slug translation. Finally, do not forget the sitemap. The traditional ones are not good because they hardly consider the division into languages, but we can fix thanks to the plugin Google XML Sitemaps v3 for qTranslate.

By doing so, you get a fully multilingual website in WordPress that is also optimized for Seo. I have personally tested the qTranslate plugin on my blog and on some websites made for customers. The evaluation? It is a shellbomb, but get help from a professional to avoid that it will explode in your hands.

Luigi Nervo

Luigi Nervo

Digital Marketing Manager

Marketing, Seo and content expert (read the bio).

Keep in touch

Would you like to add value to your digital marketing activities?

Keep in touch now! You can find me on LinkedIn, or you can write filling the following form.

I hope to hear from you soon.

9 + 8 =

Luigi Nervo

Luigi Nervo

Digital Marketing Manager

Marketing, Seo and content expert (read the bio).