Community Documentation

The same idea, different code

Last updated January 13, 2012. Created by kasiawaka on August 22, 2008.
Edited by Kristen Pol. Log in to edit this page.

On my page I wanted to display only the language switcher for languages that are not currently being used: for example, if I am currently viewing English pages, I wanted there to be only French language switcher, instead of both (or more, if you use more languages).
I turned off the block "Translations for Content" that was displaying all available languages and created a new one to display only the languages that are not currently in use.

Here is the code for that new block:

<?
//get i18n module vars info
$query = drupal_query_string_encode($_GET, array('q'));
$lang = translation_get_links($_GET['q'], empty($query) ? NULL : $query);
$current_lang = i18n_get_lang(); // currently used language
$active_lang = i18n_languages('active'); // array with all active languages

// Find the name of the currently chosen language
$active_lang_name = $active_lang[$current_lang];
// Get rid of the array keys because we want the keys to be numeric as keys in $lang
$active_lang_values = array_values($active_lang);
// Find the key for the currently chosen language.
$find_key = array_search($active_lang_name,$active_lang_values);

foreach($lang as $key=>$value) {
    // As long as the find_key is different from the key, display the value (link to that language)
    if ($key <> $find_key) {
print $value;
    }
}
?>

About this page

Drupal version
Drupal 5.x

Multilingual Guide

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.