How to only display languages in language switcher block where a translation exists? I need to enable thousands of languages on my Drupal 7 site, but I do not want to incur the rendering overhead of creating the language switcher sidebar for every language. The default behavior for the language switcher block is to show languages which do not have translations in gray font and struck out.

How would I modify the language switcher block to only show active links, i.e. only display the languages for which a translation exists? I looked at this code from this post but need help adjusting it for my needs:

&lt;?php 
  function YOURTHEMENAME_links__locale_block($variables) {
  foreach($variables[links] as $key =&gt; $lang) {
    if (isset($lang['attributes']['class']) &amp;&amp; in_array('locale-untranslated', $lang['attributes']['class'])) {
      $variables['links'][$key]['href'] = '&lt;front&gt;'; // Set here any page link...
    }
  }
  return theme_links($variables);
}


What should the code be, and where do I put the code in my theme?
To adapt the solution you tried, you would just have to unset entries for languages where no translation exists, so no link will be printed for them in the theme_links() call. So:

function YOURTHEMENAME_links__locale_block($variables) {

  foreach($variables['links'] as $key =&gt; $lang) {
    if (isset($lang['attributes']['class'])) {
        if (in_array('locale-untranslated', $lang['attributes']['class'])) {
            unset($variables['links'][$key]);
        }
    }
  }
  return theme_links($variables);
}


You would put this code into the template.php file of your theme, adapting the YOURTHEMENAME part of the function name above according to how all the other functions in your theme start. Means, you always start the function name of all your theme functions with the so-called "machine name" of your theme.