09. Blocks

Last modified: June 2, 2009 - 02:45

Technically, this is not a Localizer feature, because as of Localizer 3.0, block support from within Localizer was dropped. However, having blocks appear only for a given language can be done with Drupal core features plus a little code in the conveniently provided box.

First, create your block.

Once it is done and in the list of available blocks, choose configure.

Scroll down to the bottom of the configuration page to the Page specific visibility settings. Enable the option Show if the following PHP code returns TRUE (PHP-mode, experts only). Then, in the code entry box provided, add the following, changing out 'ja' (=Japanese) for the language code of your choice.

<?php
global $locale;
if(
$locale=='ja') return TRUE;
return
FALSE;
?>

Click Save block.
Make sure that you have enabled the block by choosing a region for it to reside.
If everything is working correctly, the block should only appear when the language in the code is the language of the user interface.

Handling multilang block visibility on specific pages only

The trick with "Show if the following PHP code returns TRUE" is good; however, you cannot simultaneously select this option and an option of "Showing the block on only the listed pages" or "Showing the block on every page except the listed pages."

If you need to display (or not display) the block on the listed pages only, you would need to add the list of conditions to the PHP code.
Or, alternatively, you can make a single bilingual (or multilingual) block instead of the set of single-language blocks, and use in the block body a PHP condition like this:

<?php
global $locale;
if(
$locale=="jp") {echo 'Block body in Japanese';}
else {echo
'Block body in another language';}
?>

 
 

Drupal is a registered trademark of Dries Buytaert.