4 min read

Multilingual support in Drupal 7

To make a website more user-friendly, there is often a need to add multiple languages. While creating separate articles for each language is an option, it does not solve the issue of translating other site elements like menus and blocks. A few modules can fully translate the entire site into any required language.

Required modules

  • Internationalization - set of modules to extend multilingual capabilities.
  • Variable - allows editing Drupal registry variables, useful for translating system variables.

Activating core and additional modules

The first step is to enable the core Locale module. Then, go to admin/config/regional/language and add the desired language. By default, English is installed. In this example, new language is added and set as the default language. Translations for Drupal can be manually downloaded from drupal.org, or installed using the Localization Update module.

Drupal 7 multilingual

Next, install and activate the Internationalization and optionally the Variable modules.

Modules to enable:

  • Internationalization
  • Field translation - translates fields.
  • Menu translation - translates menus.
  • Block languages - translates blocks.
  • Multilingual content - expands basic content translation.
  • Taxonomy translation - translates taxonomy.
  • String translation - translates user-defined strings.
  • Variable translation (optional) - translates system variables.
  • Variable (optional) - access to system variables.
  • Variable admin (optional) - UI for editing variables.

To enable and activate modules, navigate to admin/structure/types and enable multilingual support for the content types that require translation.

First, go to the Publication Settings section and select the option Enable and allow translation. After saving, go to the Multilingual Settings section and enable the Require language option to ensure that no language-neutral content appears on the site.

Drupal 7 multilingual

Create a Basic page in a new language and add it to the menu. The newly added page will look like this:

Drupal 7 multilingual

Next, we need to add a translation for the page by clicking the Translate button in the list of local tasks. Fill in the fields similarly, but in English, and add a link to the menu.

Now comes the most important step: selecting the parameter that will determine the language for the entire site. To do this, navigate to admin/config/regional/language/configure, where you will find the site language detection settings form.

Drupal 7 multilingual

From the method descriptions, everything should be clear. The detection methods will trigger based on their weight and the order in which they are arranged. Let’s focus on the language detection method by URL. Check the box to activate it, and then proceed to the settings.

Choose Path prefix to display the language code in the URL, e.g.,:

  • https://multi.local/en/node/1
  • https://multi.local/ua/node/1
  • https://multi.local/ru/node/1

Alternatively, choose Domain-based detection, e.g.,:

  • https://en.multi.local/node/1
  • https://ua.multi.local/node/1
  • https://ru.multi.local/node/1

Drupal 7 multilingual

For Path prefix, go to admin/config/regional/language/edit/YOUR_LANGUAGE_PREFIX and leave the Language prefix field empty to remove YOUR_LANGUAGE_PREFIX from the URL when using a new language.

Here is the page in a new language:

Drupal 7 multilingual

And here it is in English:

Drupal 7 multilingual

For Domain-based detection, configure language settings in admin/config/regional/language.

New language:

Drupal 7 multilingual

English:

Drupal 7 multilingual

Now, the new language version is available at https://multilan.local, while the English version is at https://en.multilan.local.

If the en subdomain is inaccessible, check server settings and .htaccess directives.

Maintaining authentication across domains

To maintain login sessions across language versions, set the following in settings.php:

$cookie_domain = '.multilan.local';

Conclusion

With just a few modules, a fully multilingual Drupal 7 website can be set up, including translations for menus, blocks, taxonomy terms, and site variables using set_variable. This significantly enhances multilingual site capabilities.