Exclude current language block.

Last modified: February 26, 2008 - 13:42

It was my wish to have a language switch block that excludes the current language. I have 2 languages set up, so now it will display either "Nederlands" or "English". The block provided by the module doesnt do this. I created a block with php enabled. Then i used the following script (copied from the original block, and slightly modified)

<?php
// modified function

function excl_translation_get_links($path = '', $query = NULL, $names = NULL) {
 
$current = i18n_get_lang();
 
$names = $names ? $names : i18n_languages('native');
  foreach (
array_keys(i18n_supported_languages()) as $lang){
  if (
$lang != $current) {
   
$url = translation_url($path, $lang);
   
$links[]= theme('i18n_link', $names[$lang], i18n_path($url, $lang) , $lang, $query);
  }}
  return
$links
}

$lang_list = theme('item_list', excl_translation_get_links($_GET['q'], empty($query) ? NULL : $query));

echo
$lang_list;
?>

that will put out a list of the available languages, excluding the active language!
I was looking for this a long time, so hopefully this can be of some help for anyone.

Only works if "Interface language depends on content" is used

O_o - March 19, 2008 - 13:58

If you have configured your Language Management setting to be "Interface language depends on content." this works. But if, as I do, use the "Interface language is independent" setting this will not work. All it will do is to show your secondary language(s) twice.

Here's an adapted version

Frank Steiner - April 25, 2008 - 13:36

Here's an adapted version for Drupal 6.x: http://drupal.org/node/242646

 
 

Drupal is a registered trademark of Dries Buytaert.