Making Drupal Multilingual

This post covers steps to turn your site into multilingual site.

Installation

The following modules are required.

sudo drush dl l10n_update 
sudo drush en l10n_update 
sudo drush dl i18nviews
sudo drush en i18nviews
sudo drush dl variable
sudo drush en variable
sudo drush dl transliteration
sudo drush en transliteration
sudo drush dl i18n
sudo drush en i18n

Here, we use drush to download(dl) and enable(en) each module
The following modules also needed but you may already have it:

A quick way to verify:

drush pml | grep ctools 
drush pml | grep token 
drush pml | grep pathauto 
drush pml | grep views 

You can verify if all of the modules installed and enabled at Admin->modules:
1. Core
Contact
Locale
Content translation
2. Chaos tool suite
Chaos tools
3. Multilingual – Internationalization
Block languages
Contact translation
Internationalization
Menu translation
Multilingual content
Multilingual select
String translation
Synchronize translations
Taxonomy translation
Translation sets
Views translation
4. Other
Pathauto
Token
Transliteration
5. Variable
Variable
6. Views
Views
Views UI

1. Set Date and Time

The date is displayed different for different countries. To configure, go Admin->Configurations->Regional and language -> Data and Time and all the date formats your site is going to use

2. Add Languages

To add all of the different languages for your site by going to Admin->Configurations->Regional and language -> Languages and clicking ‘Add Language’

3. Configure Language Detection

There are several methods for your site to detect the language new visitor comes to your site. The most common is based on url(i.e. some-site.com/fr, some-site.com/lv). To configure your choice of method, go to admin->Configurations->Regional and language -> Languages -> Detection and Selection.

4. Add Language Switcher

The multilingual modules come with a block that enables user to switch the language. Incorporate the block in your site wherever you wish by going to Admin->Structor->Block and selecting the region for the Language switcher block

5. Turn on Content Types

Next, turn on multilingual support for each of the content by going to admin->structure->content types->’some type’. Then under ‘Publishing Options’ enable the multilingual support. You have to do this for all content types

6. Add Translation

Open to edit any of the content pages that you would like to translate. In the edit mode, there should be a tab – Translate. In the ‘Translate’ section, click on ‘Add Translation’

7. Make Admin Always One Language

By default, after you add translation to one of the content nodes, automatically the whole admin section is also in that language. To keep one default langauge for Admin section, install module ‘admin language’:

drush dl admin_language
drush en admin_language

Afterwards, configure the admin language under ‘Admin -> Configurations -> Region and Langauge -> Languages -> Admin Language’

Site Menu Altered for Multilingual Support

When multiple languages is enabled for a site and the language detection configured, then the main menu contains multiple links each different language for the same page. Here is custom code snippet from template.tpl.php to filter menu links specific to currently selected language:

    //load all menu links
    $mainMenuArray = menu_load_links('main-menu');
    $finalMainMenu = array();//array holding the final menu
    foreach($mainMenuArray as $key=>$menuItem){
        global $language;//retrieves all languages configured
        $currentLang = $language->language;
        if($menuItem['language'] == 'und'){
//for default language still set the language code
            $menuItem['language'] = language_default('language');
        }
//filter all menu links of currently selected language
        if($currentLang == $menuItem['language'] ){
            $linkPath = $menuItem['link_path'];
            $linkPathAlias = drupal_get_path_alias($linkPath, $currentLang);
            $currentUrl = drupal_get_path_alias($_GET['q'],$currentLang);

            if($currentUrl == $linkPathAlias){
//decorate the link of currently selected page
                $finalMainMenu[$key]['active'] = 'muted-img';
            }
            $finalMainMenu[$key]['url'] = $linkPathAlias;
            $finalMainMenu[$key]['title'] = $menuItem['link_title'];
        }
    }
    $vars['mainMenu'] = $finalMainMenu;

Here all links of the main menu is loaded including different language then traveled through and only set ones that are of the selected langauge

XML Sitemap for Each Language

Make user to generate XML sitemap for each language. Go to Admin->Configurations->Search And Metadate -> Xml Sitemap and click ‘Add New XML Sitemap’ to generate a new sitemap

Useful Sources

https://drupal.org/node/1268692

Leave a Reply

Your email address will not be published. Required fields are marked *