D6 taxonomy term translation views workaround

If you're using Drupal 6 and i18n, AND are using views 2.x to display taxonomy term pages (overriding core), you might encounter an issue where translated taxonomy terms (using translate interface) are always displayed in their default language.

A possible solution is to use i18nviews module, but that one depends on Views 3.x.

If you are stuck on 2.x and want to display the translated term, you could use something like this as a workaround in your custom moduel or template.php.

<?php
 
global $language;
  if (
arg(0) == 'taxonomy' && arg(1) == 'term' && is_numeric(arg(2))) {
   
$tid = (int)arg(2);
   
$term = taxonomy_get_term($tid);
   
$vars['term_desc'] = filter_xss_admin($term->description);

    $lid = db_result(db_query("SELECT ls.lid FROM {locales_source} ls WHERE ls.source = '%s' AND ls.textgroup = 'taxonomy'", $vars['title']));
   
$translation = db_result(db_query("SELECT lt.translation FROM {locales_target} lt WHERE lt.lid = %d AND lt.language = '%s'", $lid, $language->language));
    if (!empty(
$translation)) {
     
$vars['title'] = $translation;
    }
  }
?>

About

This is the company blog of
Drupal specialist Merge.nl

We are located in Breda (Netherlands) and build websites using Drupal. More about us.

Content on this blog is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Netherlands License.

Creative Commons License

Recent Comments

Social