Drupal
Understanding Drupal translations and multilingual modules
![trans](/sites/default/files/styles/wide/public/2024-05/translatee.jpeg.webp?itok=oS1vFLe9)
Why are multilingual translations are useful ?
Multilingual translations can help us to expand our market and reach a wider audience. However, By translating your own content into multiple languages, we could breakdown language barriers and make your website readily available across the globe. Poorly translated content can damage your organisations reputation and lose a number of potential customers. Drupal provides four translation modules where each plays a significant role in translating.
When we install a Drupal instance, we need to choose the default language as English. The installer will attempt to make the reasonable choice based on your browser language, and should display the page in your browser language.
Steps for enabling multilingual in your Drupal instance
Step 1: Install all translation modules
Drupal comes with four core multilingual modules, the basic installation involve these four Drupal modules:
- Content Translation
- Language
- Interface Translation
- Configuration Translation
![Languages](/sites/default/files/2024-05/Screenshot%202024-05-27%20at%201.16.09%E2%80%AFPM.png)
Step 2: Add language
Navigate to Configuration->Regional and language (/admin/config/regional/language)
Choose any preferred language from the language name list (Eg. French, Dutch). Now, click on Add language, then the language is yet to download and once the download is complete you'll be redirected to Languages page with a confirmation page.
![language translation](/sites/default/files/2024-05/Screenshot%202024-05-27%20at%201.11.59%E2%80%AFPM.png)
Step 3: Configuring content translation
So, the goal is to make content, content block, custom menu link, taxonomy term and URL alias translatable. The basic requirement to translate all of this is content translation module.
In the administrative menu, navigate to configuration > regional and language > Content language and translation (admin/config/regional/content-language). We need to go under Custom language settings and check on content, content block, custom menu link, taxonomy term and URL alias. However, on checking these entities all the related translatable checks will be shown below and makes these entities translatable.
![Custom language settings](/sites/default/files/2024-05/Screenshot%202024-05-27%20at%201.22.24%E2%80%AFPM.png)
We further have options to set the default language (English) or choose any of installed languages from the drop down as shown in the image below.
![Content Translation image 1](/sites/default/files/2024-05/Screenshot%202024-05-27%20at%201.24.36%E2%80%AFPM.png)
Finally, click on Save configuration.
Step 4: Enable translation in content types
Go to your content type edit page and enable translation in the language settings pages. Assuming, we are translating from default language English to French.
In Administrator menu, navigate to content (admin/content) and locate to any content item or by searching by the keyword in the title field.
![add language](/sites/default/files/2024-05/Screenshot%202024-05-27%20at%201.28.01%E2%80%AFPM.png)
Now, select Translate tab which is shown in the above image, click on add in the French language row. A new edit page with Title, Body and URL alias is displayed and go ahead and save this translation. We have converted the entity item's language to French. A new content item will be created with French language accordingly.
We can find the language code "fr" in the URL once we view the content item. To revert back it to English we need to remove the "fr" keyword right after the domain name. For example, assuming the URL is mydummyproject.com/fr/node/5/translations/add/en/fr is a French translated page. we need to remove "fr" which is right after mydummyproject.com to switch back to English.
Step 5: Enable interface translation module
Interface translation is a core module which allows us to replace any string in the interface with a string that has been customised. This module plays a significant role in Drupal by translating any string and tries to translate the particular string to the current language of the interface. This module as also filters the untranslated string in the table.
Navigate to Configuration > Regional and language > Interface translation to manage User Interface translations.
![conten translation image 2](/sites/default/files/2024-05/Screenshot%202024-05-27%20at%201.31.43%E2%80%AFPM.png)
Step 5 : Enable configuration translation module
Configuration translation module (core module) helps in translating configuration in different languages. Configurations like site name, vocabularies, menus, blocks can be translated using this module.
Note : Content such as nodes, taxonomy terms, custom blocks, and so on are translatable with the Content Translation module in Drupal core and not with configuration translation module.
![configuration translation](/sites/default/files/2024-05/Screenshot%202024-05-27%20at%201.32.51%E2%80%AFPM.png)
Some important translatable configuration elements
- Block
- Comment type
- Configuration entity type
- Contact form
- Content type
- Custom block type
- Date format
- Form mode
- Image style
- Language
- Menu
- Role
- Taxonomy vocabulary
- User fields
- View
- View mode
- Account settings
- RSS publishing
- System information
Additional information
A very basic module called Language Switcher Dropdown exposes a new block that is comparable to the Language Switcher block that the Locale module by default provides. If installed, the module also works well with the Language Icons module as well.
To install via composer, use the below command :
composer require 'drupal/lang_dropdown:^2.1'
After installing the module, navigate to Structure -> Block Layout. From there, locate to the Language Switcher block in the block list and place it in the appropriate region. In the image below, the language switcher block is positioned in the right sidebar.
![language translation](/sites/default/files/2024-06/language.png)
Conclusion
Drupal serves a better way in building a multilingual website having more than 100+ languages and translating the website effectively. Drupal translation modules are core modules which provides a multilingual domain to translate the website as per clients experiences.
Many thanks for these invaluable references:
- https://www.drupal.org/docs/administering-a-drupal-site/multilingual-guide/setting-the-language-for-administration-pages
- https://www.drupal.org/docs/administering-a-drupal-site/multilingual-guide/adding-a-language-to-drupal-core
- https://www.drupal.org/project/language_switcher_extended