Tuesday, February 25, 2014

Internationalizing Drupal 7

Recently I had to create a bilingual website in Drupal 7.26. I found information here and there but no comprehensive, up to date and detailed roadmap to say: "do this and it will all work". Here's my attempt to set the record straight.

  1. First you have to install the internationalization modules: Locale, Localization Update, Internationalization (comprising Block Languages, Content translation, Field translation, Internationalization, Language Icons, Menu Translation, Multilingual Content, Multilingual Select, Path Translation, String Translation, Synchronize translations, Taxonomy Translation, Translation redirect, Translation sets, Variable Translation, should all be enabled), Variable (comprising Variable, Variable Realm, Variable Store, should all be enabled)
  2. Now go to the Configuration page
    1. In Regional and Language click on Languages and make sure your language is the default and that they are all enabled. On Icons you can set the icon size.
    2. In Multilingual settings->Selection select "Select nodes by language" and "Select taxonomy terms by language". In the Variables tab select "Default front page". In Strings set Translatable formats to Plain text and HTML and set the source language to English.
    3. In Translate Interface load the language files of all the languages you want to support. You can get these from localize.drupal.org.
    4. In System->Site Information choose the home page for each language by first selecting the language using the language switcher and then specify a Default Front Page for it. If you generate content from nodes you don't need to do this.
  3. Now enter the administration pages and take the tabs one by one:
    1. In Structure->Menus select "Translate and Localize". Menu items with language will allow translations. Menu items without language will be localized." in the multilingual options for each menu you want to appear in multiple languages. Save. Now go back and edit each menu item of that menu that needs translating. Click the tab "Translate" and the "Add translation" to provide a translation for the missing language(s). Save.
    2. In Blocks sets the Language Switcher to appear somewhere on the page - in the header or in Primary. Now configure it so that it shows all the languages you want in "Visibility Settings" or the menu won't appear at all. In Content Types set it to appear in all. Similarly make it appear for all roles. In Footer make it translatable and select all desired languages for display. Set the correct footer text for your current language (check the URL in the browser path). If you want to translate it, switch to another language and return to Structure->Blocks->Footer. Now hit the translate button, add a translation and supply the text. Save.
    3. In Content Types: Basic page, set Language to "Hidden" or you will get a report on the language at the foot of each page.
  4. If like me you have generated content in the footer, for example, to say "Last updated on..." you can add some code to the footer (or wherever) like this:
    global $language;
    $lang_name = $language->language;
    if ( isset($node) && isset($node->changed) )
    {
        if ( $lang_name == 'it' )
            print "Ultimo aggiornamento ".format_date($node->changed);
        else
            print "Last updated ".format_date($node->changed);
    }
    

For each page in the source language you will have to "add a translation" and have it saved under the target language. I use Google Translate, which often does a passing good job. But really you need a native speaker to go over it. Now when you switch languages the menus should swap, the custom text should swap and the content will swap. You may have to do some of these things in a different order, since they are all interdependent. Good luck, and I hope I haven't left anything out. If I have, then Google it!

1 comment:

  1. Hello there! If you need to create a bilingual website in Drupal, I would suggest to try a software localization tool like https://poeditor.com/ which can simplify the entire process for you. It has a flexible work interface that allows project managers to work efficient on their translation projects.

    ReplyDelete