How to only display languages in language switcher block where a translation exists?
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.