Remove languages from $links for usability reasons?

public
O_o@drupal.org - Wed, 2008-03-26 14:51

First post here in this group, so a warm "Hi!" to everyone!

The background
I have been using the fantastic i18n module since a year back and recently installed i18n 5.x-2.2. I'm working on a multilingual intranet for my company. The interface language will always be set to the default language (English) by setting the Language Management setting to "Interface language is independent" while some node content (books) can be translated to other languages. Why, you might ask. In some countries documents regarding the benefits and obligations as an emplyee must be published in the native language.

The question/discussion
Anyway... I was not satisfied with the language switching block provided with i18n and have therefore disabled it. That leaves me with the option to show the available translations printed together with the $links at the bottom of the page (which it does by default). Is this the ideal solution for a language selection? No, because your visitors have to scroll down to the bottom of the page and choose their language (even if just once). Also, the languages are mixed up with some other options not related to translation; "Add child page" and "Printer-friendly version" in my case. The preferred way (as I see it) would be to place the language selection at the top right corner of the node content area. This is for two reasons. First, it will be placed in a position of the page where users easily can see it. Second, it clearly indicates that this language switch will not affect the whole page including the interface.

So I added a custom function (the one below) in my template.php which shows available translations of the current node. I then call this function in my node-book.tpl.php file and place it at the top right corner of the node area at the same level as the $submitted variable is printed. "This content is also translated to Polish" would show on the English version of the node if both English and Polish translations would exist. This use of a function call inside a template file is not ideal - ideas for a better solution are welcome.

For usability reasons I want to remove the languages from the $links variable and instead output the language selection in the way I have described above. I have located the translation_link() function that adds the languages to $links. How can I override that function without having to add my own intranet_link() function that overrides all hook_link() from other modules also?

Alright, let's sum it it up.
1) $links should not be used to output available languages since it also shows options not related to translation.
2) Language selection, when not affecting the whole interface should be placed at the top of node area to make it easy to see for the user.

It would be interesting to hear your opinion on this subject and my solution.

function intranet_i18n_translation_switch($node) {
  // ET 080319
  if (isset($node->translation) && (count($node->translation) >= 1)) {
    foreach ($node->translation as $language => $translation) {
      $links[$translation->language.'_translation'] = array(
        'title' => i18n_language_property($translation->language, 'name'),
'href' => i18n_default_language().'/node/'.$translation->nid
      );
    }
    $output  = '<div id="available-translations"><em>'.t('This content is also translated to ').'</em>';
    $output .= theme_links($links, array('class' => 'translation-languages'));
    $output .= '</div>';

    return $output;
  }
  return false;
}