Block content translation

Drupal's i18n module can translate block contents.

To display blocks in multiple languages, you can use one of these approaches:

  1. Creating a different block for each language.
  2. Using string localization

When you create a block, you can choose to assign it to a specific language or to all languages and use string translation.

Method 1 - different blocks per language

Select a unique language for the block and indicate which nodes to display it for. You should select only nodes that are written in the same language as the block.

Then, create similar blocks in other languages and enable them for the nodes in those languages.

This process will keep complete isolation between blocks in different languages. They can be translations of each other, but can also contain completely independent contents. Drupal and i18n don't offer any facilities for synchronizing between block contents in different languages.

Method 2 - string localization

Drupal can translate strings from English to other languages (currently, there is no solution for translating from any language other than English). You can tell Drupal to handle the title and contents of blocks as strings and look for translations using Drupal's string translation mechanism.

When a block is being displayed in a different language, Drupal will look up the title and body of the block to see if there is a string translation of the title and body. If they are available the translation will be displayed otherwise it will display the original text.

To use this method set the block language to "All languages (Translatable)" while creating or editing a block.

block translatable

NOTE: An important point when using this method is that the default language should be English. Drupal localizes these strings with the t() function, meant to be called whenever a module outputs an English text string.

Here is an example. We'll create a new block and translate its strings.

Create the block and set to 'All languages (Translatable)'

create a block

Choose where the block is displayed

We'll display this block in the right sidebar. The display position doesn't really matter and the block doesn't have to be displayed in order to be translated.

block in right sidebar

Which now shows as:

block on home page

Switching to Spanish shows the block visible but with no translation:

block not translated.

Manually entering translation for the block contents

The strings for the title and the body are translated using the translate interface.

Go to /admin/build/translate/search and look for the strings used in the block.

block search

Click on "Edit" and enter the translation.

Block enter translation

Repeat for the body of the block searching for some text in the body.

This should now give you a fully translated block on the Spanish home page.

 

block translated to spanish

 

 

 

Translating blocks using ICanLocalize Translator

ICanLocalize Translator handles block translation using Drupal's string translation mechanism.

Although internally nodes and blocks are constructed differently, ICanLocalize Translator makes their translation appear the same.

Blocks will appear in the translation dashboard just like all other content types. Behind the scenes, ICanLocalize Translator will fetch the strings created by the Drupal blocks and return the translated contents as string translations. Users don't need to manually handle this as the module handles everything automatically.