Skip to main content
translate in drupal 7

Translation in Drupal 7 : How it works?

As we all know that, we were all getting projects and clients across the globe. But doing a multilingual website with each having different set of requirements make the website handling tougher and tougher. Also, building a multilingual web site involves much more than translating content from one language to another. Translation must be done with an awareness of a language's idioms as spoken within a geographic region. But in Drupal we’ve been provided with rich set of core and contrib modules, which supports translation for our website(s). When we go deeper in the concept of Drupal Translation, there is a lot more can be learnt. Well, here I explain you a few concepts that i’ve come across.

The Translation Methods:

In Drupal 7, we have two different types of translation methods, which we can call as two main modules to implement translation of content in order to make a site multilingual. One is Entity Translation (contrib) and the other one is Content Translation (core).

  1. Content Translation

    1. a core Drupal module that allows you to translate nodes.
    2. Translated nodes are mapped together, but if they are distinct nodes that can be treated separately.
  1. Entity Translation

    1. Translation module lets you translate particular fields, while only a single node or entity is created.
    2. Entity Translation works for all kinds of entities that have fields, not just nodes. It provides a way to translate taxonomy terms, users, and comments as well.

Synchronizing Translations :

Synchronize Translations is a submodule of the Internationalization module (i18n). This module allows you to synchronize certain fields across languages when translating nodes with the Content Translation module. While it provides some of the same results, it works very differently from the entity translation module.

Here is the process I went through to set up a basic multilingual site:

  1. Setting up the core modules

    1. Locale (core module) : Adds language handling functionality and enables the translation of the user interface to languages other than English.
    2. Once it’s enabled, Language and Translate interface links will be added under Configuration  > Regional and Language

1 configuration.png

  1. Adding new languages

    1. Under Configuration > Regional and language > Languages click on Add language

2 Add language.png

  1. Select a language from the select list and click Add language

3 Select and add language.png

  1. After adding a language, it's now time for us to define which language will be used by Drupal to display page elements. Click on Detection and Selection tab.

5 Detection selection page.png

  1. Now, you will be presented with different options, as each of them are explained below:

    1. URL: Determine the language from the URL (Path prefix or domain).

      1. Path prefix: language code as first argument of the URL mysite.com/en/contact or mysite.com/it/contatti.
      2. Domain: language code as if you want like en.mysite.com or it.mysite.com. [You will need to create subdomains with this option]
    2. Session: Determine the language from a request/session parameter, like mysite.com?language=en or mysite.com?language=it.
    3. User: Follow the user's language preference. The user will be able set his language from his/her edit profile page.
    4. Browser: Determine the language from the browser's language settings.
    5. Default: Use the default site language (English).
  2. Now let us configure the URL option, then we proceed further:

6 URL detection.png

  1. Choose Path prefix and save configuration. Get back to the Detection and Selection page, enable URL  and Save settings.

8 detection configured.png

  1. Now the website will define the language by checking the detection method. Lets move forward to do translation via Translate Interface.
  1. Translate Interface (Here I chose Italian as my language)

    1. Go to Configure > Regional and languages > Translate interface.
    2. From the translate interface page, click on Translate
    3. Here you can look for any text string that is on the site. For new string you create in code, remember to wrap it in a t() function.
    4. Let us look for a sample string like “No front page content has been created yet.” and click filter.

12 - Translate interface - search string_0.png

  1. Now you have found the string and how you can see by the stroke on the Italian prefix that the string has not been translated. Click on Edit and translate it.

14 Translation interface - trssnlate string.png

  1. Provide the Italian translation and click on Save translations.

15 Translate interface - translate string fronpage.png

  1. Now if I visit mysite.com/it I will see the translated text and If I go to the mysite.com/en I will see it in English.

17 Translate interface - homepage.png

  1. Importing a language file

    1. You are also able to Import translated strings to the system from Import page. The file format will be .po. A list of ready translation may be found here https://localize.drupal.org/
    2. Choose the language(s) you are interested in and download the files related to your Drupal Version.
    3. Now, go to Configuration > Regional and language > Translate interface > Import, add the file in the Language file field input, import to the targeted language, choose the Text group and choose the mode and click import.

18 Translate interface   Brightlemon Multilingual Drupal Site.png

  1. After the import, Drupal can now translate your new language! In this case, Italian.Also if we check the homepage, we can see that most of the text has been translated too and the message I’ve translated previously, has been replaced with the one provided by the .po file.

 

Benvenuto su Brightlemon Multilingual Drupal Site   Brightlemon Multilingual Drupal Site.png

  1. Exporting the language Files

    1. If you want to import strings from an environment to another one go to Go to Configuration > Regional and language > Translate interface > Export and under Export translation, select the language you want to export, text group and click export. This operation will create a .po file with all the translated strings.

20 Translate interface   Brightlemon Multilingual Drupal Site.png

  1. You can also export a clean template for translation, this will give you a file with all strings from the Drupal locale database.

22 Translate interface   Brightlemon Multilingual Drupal Site.png

 

We will see the effective usage of translation in custom module in the next part.

Comments

David (not verified)

Mon, 08/31/2015 - 08:44

Hello Sasikumar! I think things may be easier with the help of a software localization tool to translate your website in multiple languages. https://poeditor.com/ is such a service that comes with a simple work interface, plenty of useful features (translation memory, API, tagging system, GitHub and BitBucket integration, WordPress plugin) to make the entire localization process easier for all users. Give it a try, maybe it is helpful. Cheers!