Putting language links above the content

Having the language links below the content always seems a bit odd to me.  When a visitor enters a page and is confronted with a language he doesn't know, scrolling down to the bottom of the page isn't necessarily the first thing that comes to his mind. Chances are he will leave without further actions. 

hook_page_alter() to the rescue

Picking this one link out of the links section in the page and putting it on top of the content wasn't that easy up till Drupal 6. With Drupal 7 it is, leveraging the power of hook_page_alter().

 * Implements hook_page_alter().
 * Change placement of language links.
function <modulename>_page_alter(&$page) { 
  // nodes only, and only if translation exists.
  if((arg(0) == 'node' && is_numeric(arg(1))) 
    && isset($page['content']['system_main']['nodes'][arg(1)]['links']['translation'])) {
    // copy the translation links to the newly created 'toplinks' element.
    $page['content']['system_main']['nodes'][arg(1)]['toplinks'] = $page['content']['system_main']['nodes'][arg(1)]['links']['translation'];
    // assign the toplinks element a weight < 0.
    $page['content']['system_main']['nodes'][arg(1)]['toplinks']['#weight'] = -10;
    // Optionally remove the original links from the 'links' section.