how to show a custom block on specific language pages in drupal

Drupal

When working on a multilingual Drupal website, you might want to only show a block on pages that are translated in one particular language.

This is particularly useful since one might have a block in English, which is meant to be displayed only on English pages, and a block in Italian, to be shown only on Italian pages.

It took me a little bit longer than I would have liked to figure out, which is way I'm sharing the following PHP code snippet here.

In the admin/build/block/configure configuration page for the block, select the Show if the following PHP code returns TRUE (PHP-mode, experts only). in the Page specific visibility settings:


<?php
global $language;

if ($language->language == 'it') {
return TRUE;
} else {
return FALSE;
}
?>

This will only show the block when the current language code for the page is 'it'.