Hide the active language in Language Switcher block in Drupal 7

mlecha's picture

I'd like to have the language switcher block in core Drupal 7 hide the active language. (ie: If you're reading the English page, don't display a link to the English page.)

I've come across this solution for Drupal 6, which seems hefty for a seemingly trivial task (and doesn't work in D7):
http://drupal.org/node/909418

I'm new to Drupal, and I am having difficulties knowing where to start.

What's interesting, is that the language links that appear on the bottom of the content that is translated don't include the language of the current page. Perhaps what I need to do is somehow override the functionality and have it output in the theme region of my choosing?

Your comments would REALLY be helpful!

Comments

If you are looking to hide

stuartEngelhardt's picture

If you are looking to hide it, why not just assign the .active for the element to display: none; in your theme's CSS?

yeah. that will just work

dan.hu's picture

yeah. that will just work perfectly!

Other way

yrocq's picture

If, like me, you don't like to hide elements with CSS, you can put this code in your template.php file :

<?php
function mythemename_links__locale_block($variables) {
  global
$language;
  unset(
$variables['links'][$language->language]);

  return
theme('links', $variables);
}
?>

Hide untranslated languages

natuk's picture

And for those who only want to hide the untranslated languages elements use this:

<?php
function iic_main_links__locale_block($variables) {
  foreach(
$variables['links'] as $key => $value) {
    if (
$value['attributes']['class']=='locale-untranslated') {
      unset(
$variables['links'][$key]);
    }
  }
  return
theme('links', $variables);
}
?>

Hide active language and format to copy Primary Links

mory's picture

I know it's been a while, but I thought I'd post my solution, for the sake of those like me: who never got to work this out other ways.

For drupal 7

I copied this in my css theme style:

.language-switcher-locale-url li.active a{
display: none;
}

.language-switcher-locale-url li,
.language-switcher-locale-url ul,
.language-switcher-locale-url ol,
.language-switcher-locale-url a,
.language-switcher-locale-url a:link,
.language-switcher-locale-url a.link,
.language-switcher-locale-url a:visited,
.language-switcher-locale-url a.visited,
.language-switcher-locale-url a:hover,
.language-switcher-locale-url a.hover,
.language-switcher-locale-url a.hovered
{

font-size: 15px;
font-family: Arial, Helvetica, Sans-Serif;
display: inline;
color: white;
text-decoration: none;
}

After, I got my switcher block in a free region and aligned it with my "Primary links" menu with css (Extra2 in my case)

Up to you to change fonts settings and more. I covered pretty much all angles of the link (hovered, visited). I'm relatively new to css and drupal so please feel free to correct this. This hides my active language and formats the unactive language with my Primary links menu.

** sorry for my bad english, I'm french.

Keep it theme agnostic

colan's picture

To keep this theme agnostic (independent of the theme you're currently using), I'd recommend doing this in a hook_language_switch_links_alter implementation.

Internationalization

Group organizers

Group categories

Content categories

Group events

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: