Code Snippets

Drupal 5 Internationalization Module

Drupal 5 has a minor issue for the Internationalization Module. More details are available on this blog post.

To have the option to choose a language, use the default language and have no language can be done in this way:

First, choose the option on Drupal 5

"2) Current language/default language/no language" for "content selection mode".

Then implement hook_views_pre_view() to remove duplicate content.

An example:

/**
* Implementation of hook_views_pre_view()
*/
function example_views_pre_view($view, &$items) {
  $lang = i18n_get_lang();
  $translations = array();

  //Find nodes which have translations
  foreach($items as $key => $val) {
    $result = db_query("SELECT trid, language FROM {i18n_node} WHERE nid = %d AND trid != 0 AND language != '' AND language IS NOT NULL", $val->nid);

    if($obj = db_fetch_object($result)) {
      $translations[$obj->trid][$key] = $obj->language;
    }
  }

  //if a node has a translation of the current language, remove the other translation and English nodes of the same content
  foreach($translations as $key => $val) {
    if((count($val) > 1) && (($index = array_search($lang, $val)) !== FALSE)) {
      foreach($val as $key2 => $val2) {
        if($key2 != $index) {
          unset($items[$key2]);
        }
      }
    }
  }

  return '';
}

Fortunately, upgrading to Drupal 6 will not have this problem.

 

Resource Tags: