0

I'm using i8n to host a bilingual site and I only like to display the inactive language in the top bar. What php code do I need to detect the current language so I place the inactive language in the template? Thanks:

<a href=
<?php
global $language; 
if (($language -> name) == 'English') { 
print "\"http://www.mangallery.net/fr\"".">french";
} else {
print '"http://www.mangallery.net"'.">english";
}
?>
</a>

2 Answers 2

1

Use the global variable $language

https://api.drupal.org/api/drupal/developer%21globals.php/global/language/7

2
  • The exact code you're looking for is global $language; print $language->language; //prints 'en' for english
    – rreiss
    Commented Nov 15, 2013 at 19:27
  • thank you so much Rotem and user1406716. I finally tweaked it and got it parsing:
    – user529481
    Commented Nov 15, 2013 at 21:25
0

If you are planning to use the existing Language switcher block of Drupal which links directly to the translated page(s) on a multilingual website, here is some sample code to remove the active language from the list.

You can add this code in the template.php of your theme. Replace YOURTHEME with the name of your theme and don't forget to clear the cache.

function YOURTHEME_preprocess_links(&$variables)
{
    if (!isset($variables['attributes']['class']['0'])) {
        return false;
    }

    // Only alter links for the language switcher block
    if ($variables['attributes']['class']['0'] === 'language-switcher-locale-url') {
        global $language;

        // Remove active language from the list
        if (isset($variables['links'][$language->language])) {
            unset($variables['links'][$language->language]);
        }
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.