Hello,

How can I remove the current language from the language switcher block?

I found this snippet

 $current = i18n_get_lang();
  unset($links[$current]);

That could be used if the language switcher is placed as part of the page.tpl.php but I'm not sure where to place it if I leave it as part of the block?

Any help would be great

Comments

sgabe’s picture

Subscribe. I would like to remove the link of the current language too.

sgabe’s picture

Till then, one solution to the problem to invoke hook_translation_link_alter(); function in a new module with totocol's snippet.

<?php 
function foo_translation_link_alter(&$links, $path) {
  global $languages;
  $current = i18n_get_lang();
  if ($paths = translation_path_get_translations($path)) {
    foreach ($links as $langcode => $link) {
      if (isset($paths[$langcode])) {
        // Translation in a different node.
        $links[$langcode]['href'] = $paths[$langcode];
      }
      else {
        // No translation in this language, or no permission to view.
        unset($links[$langcode]);
      }
    }
  }
  unset($links[$current]);
}
?>
jose reyero’s picture

Status: Active » Fixed

Yes, that will work.

You can also code a module that provides a different block, instead of altering the translation module's block.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.