Hi,

I went through all the different threads about this issue but found no solution. I translated my terms (default language: German, vocabulary: localizabled, no real translation) on translation interface to English by Internationalization/ Taxonomy Translate and everything works fine. BUT: in exposed filtes the terms are still not translated.

Here are the stats of my installation.

Drupal 6.19
Internationalisation 6.x-1.5 (Taxonomy Translation activated)
Internationalization Views 6.x-2.0 (with applied patch of http://drupal.org/node/346028#comment-2769734)

I also tried the lates dev version of Internationalization Views but nothing changed (yes, I cleared ALL caches several times). Can anyone help me with this issue?

Greez,
Tobias

Comments

udane’s picture

I have the same problem. Does anyone have the solution?
Thanks!

miaoulafrite’s picture

+1

Bilmar’s picture

subscribing - also interested in being able to search the translated term in autocomplete exposed filters

GN’s picture

I have the same problem - an i18n issue #295315: Views: taxonomy terms shown in dropdown lists of exposed filters are not translated was posted two years ago, and it's still unsolved for the current versions of i18n and Views.

As a workaround, it's possible to add a Content Taxonomy field and expose it in your filter instead of the taxonomy terms. In this case, term names in dropdown lists are properly translated.

However, it does not work well when you need to group items via Argument Summary (i.e. when you add "Taxonomy: Term" or "Content: CCK-Term" as an Argument and set "Action to take if argument is not present" to "Summary"). With Taxonomy, term names in Summary are not translated (like with exposed filters); when you try to use a Content Taxonomy field instead of the taxonomy terms, Summary displays its integer values, i.e. term id's (tid) instead of their names. (See #973624: Argument Term ID not translated when if not present showing a summary of terms.).

bibo’s picture

subscribe

selinav’s picture

+1

pandersb’s picture

This also stumped me and I found a way using the template_preprocess_views_exposed_form function in Views (6.x-2.12) theme.inc in the theme folder.

I don't think you need i18nviews module for this fix since your taxonomy terms will come up as "Built-in interface" in the translate interface search. Add this to your template file, clear your cache, and refresh your language strings. Do a search and translate. It should show up in your form translated.

/**
 * Default theme function for all filter forms.
 */
function yourtheme_preprocess_views_exposed_form(&$vars) {
  $form = &$vars['form'];
 
  foreach ($form['#info'] as $id => $info) {
    $widget = new stdClass;
    // set up defaults so that there's always something there.
    $widget->label = $widget->operator = $widget->widget = NULL;

    $widget->id = $form[$info['value']]['#id'];
    if (!empty($info['label'])) {
      $widget->label = $info['label'];
    }
    if (!empty($info['operator'])) {
      $widget->operator = drupal_render($form[$info['operator']]);
    }
//here's where you replace the terms with translated terms
    $options = array();
    foreach($form[$info['value']]['#options'] as $key=>$option) {
        $options[$key] = t($option);    	
    }
   unset($form[$info['value']]['#printed']);
   $form[$info['value']]['#options'] = $options;  

//end modification
    $widget->widget = drupal_render($form[$info['value']]);
    $vars['widgets'][$id] = $widget;
  }

}
selinav’s picture

#7, thank you for your code, if the default language is not english but french for example it doesn't work, but I have found the solution.

Replace

- $options[$key] = t($option);
+ $options[$key]=tt('taxonomy:term:'. $key .':name', $option);
micheleannj’s picture

My default language is French and I made the change you suggested, but I'm still only seeing English terms.

Should the terms be localized? I'm reading conflicting things as to how the vocabulary should be configured....

Thanks,
m

selinav’s picture

In my case, they can be translated.

rv0’s picture

@selinav

thanks, your tt() code saved me a whole bunch of work

christiaan_’s picture

You could try this solution - it solved the issue for me.

#1106294: exposed term with depth filter not translated

mkalbere’s picture

#7 & #8 did it for me ! Thanks !

miaoulafrite’s picture

#7 & #8 are interesting ways but i believe it depends on your taxonomy configuration
it would work in case the vocabulary is set to Localize terms. Terms are common for all languages, but their name and description may be localized. or even Set language to vocabulary. The vocabulary will have a global language and it will only show up for pages in that language.

but if you've chosen, say, Per language terms. Different terms will be allowed for each language and they can be translated., this won't work

is that correct?

moreover, the preprocessors are theme functions where it should only render HTML based on operations made by modules.
in the #7, $options are re-generated in the preprocessor, where in the default preprocessor they are not (see default function here)

i believe there should be some hook to make the translation/exposure of terms translatable, whatever taxonomy configuration you've chosen here:
http://drupalcontrib.org/api/drupal/contributions--views--docs--docs.php...

could be that one maybe?
http://drupalcontrib.org/api/drupal/contributions--views--docs--docs.php...

mathieu’s picture

Sadly, #7 does not work if you are using views-6.x-3.x.

mvc’s picture

as mentioned above, see #1106294: exposed term with depth filter not translated for a solution for views 6.x-2.x and 6.x-3.x.

Amarjit’s picture

Thanks for this.

#7 + #8 worked on my config.

I added a slight tweak because I had multiple exposed fields.

  + $taxonomy_array = $form[$info['value']]['#options'];
  + if (sizeof($taxonomy_array) > 0) {
     - foreach ($form[$info['value']]['#options'] as $key => $option) {
     + foreach ($taxonomy_array as $key => $option) {
       $options[$key] = tt('taxonomy:term:'. $key .':name', $option);   
     }
  + }

Versions:

  • Drupal Core: 6.19
  • Views: 6.x-2.11

Cheers,
Amarjit

ron_ron’s picture

Hi,

i ported the code to 7. I know the code is a little bit fuzzy but it works.
The if(isset($option->option)) is necessary because if you use "Show hierarchy in dropdown".

Hope that helps someone too.

Cheers

function yourtheme_preprocess_views_exposed_form(&$vars) {
  $form = &$vars['form'];

  foreach ($form['#info'] as $id => $info) {
    $widget = new stdClass;
    // set up defaults so that there's always something there.
    $widget->label = $widget->operator = $widget->widget = NULL;

    $widget->id = $form[$info['value']]['#id'];
    if (!empty($info['label'])) {
      $widget->label = $info['label'];
    }
    if (!empty($info['operator'])) {
      $widget->operator = drupal_render($form[$info['operator']]);
    }
//here's where you replace the terms with translated terms
    $options = array();
    foreach($form[$info['value']]['#options'] as $key=>$option) {
				
		if(isset($option->option)) {
			$str = $option->option[key($option->option)];
			$pos = strrpos($str, "-", -1);
			if ($pos !== false) {
				$bef = substr($str, 0, $pos + 1);
				$aft = strstr($str, $pos);
			} else {
				$bef = '';
				$aft = $str;
			}
			
			$trans = i18n_string_translate('taxonomy:term:'. key($option->option) .':name');
			
			if($trans == "") {
				$options[key($option->option)]=$option->option[key($option->option)];	
			} else {
				$options[key($option->option)]=$bef . $trans;
			}
		} else {
			$options[$key]=i18n_string_translate('taxonomy:term:'. $key .':name', $option);	
		}
		
    }
   unset($form[$info['value']]['#printed']);
   $form[$info['value']]['#options'] = $options; 

//end modification
    $widget->widget = drupal_render($form[$info['value']]);
    $vars['widgets'][$id] = $widget;
  }

}
star-szr’s picture

Nicolas Bouteille’s picture

For Drupal 6.28, Views Translation 6.x-2.0 and Views 6.x-2.16, the code on #7 and #8 was not working anymore.

I had to tweak it a little bit probably because the structure of the form must have change between versions.

Here is the updated code :

<?php
    $options = array();

    foreach($form[$info['value']]['#options'] as $key=>$option) {
      
      $temp = $option->option;
      if(isset($temp)) {
        foreach($temp as $termID => $termName) {          
          $options[$termID] = tt('taxonomy:term:'. $termID .':name', $termName);
        }
      }
      else {
        $options[$key] = t($option);
      }
      
    }

   unset($form[$info['value']]['#printed']);
?>
heyehren’s picture

#7 and #8 worked for me. i'm using views 6.x-3.0+77-dev.
thank you!

heyehren’s picture

For anyone who's looking for a solution, try this: http://drupal.org/node/929368#comment-4025498

JulienThomas’s picture

Thanks. It helped me a lot!

I would suggest a small update to avoid warnings:

preprocess_views_exposed_form(&$vars) {
  $form = &$vars['form'];

  foreach ($form['#info'] as $id => $info) {
    $widget = new stdClass;
    // set up defaults so that there's always something there.
    $widget->label = $widget->operator = $widget->widget = NULL;

    $widget->id = $form[$info['value']]['#id'];
    if (!empty($info['label'])) {
      $widget->label = $info['label'];
    }
    if (!empty($info['operator'])) {
      $widget->operator = drupal_render($form[$info['operator']]);
    }
//here's where you replace the terms with translated terms
    $options = array();

$options_src = @$form[$info['value']]['#options'] ;
if(!empty($options_src )) {
foreach($options_src as $key=>$option) {

		if(isset($option->option)) {
			$str = $option->option[key($option->option)];
			$pos = strrpos($str, "-", -1);
			if ($pos !== false) {
				$bef = substr($str, 0, $pos + 1);
				$aft = strstr($str, $pos);
			} else {
				$bef = '';
				$aft = $str;
			}

			$trans = i18n_string_translate('taxonomy:term:'. key($option->option) .':name');

			if($trans == "") {
				$options[key($option->option)]=$option->option[key($option->option)];	
			} else {
				$options[key($option->option)]=$bef . $trans;
			}
		} else {
			$options[$key]=i18n_string_translate('taxonomy:term:'. $key .':name', $option);	
		}

}

    }
   unset($form[$info['value']]['#printed']);
   $form[$info['value']]['#options'] = $options; 

//end modification
    $widget->widget = drupal_render($form[$info['value']]);
    $vars['widgets'][$id] = $widget;
  }

}
malc0mn’s picture

Issue summary: View changes

I would suggest this change:

Original:

    else {
      $options[$key]=i18n_string_translate('taxonomy:term:'. $key .':name', $option);
    }
      elseif (is_numeric($key)) {
        $options[$key] = i18n_string_translate('taxonomy:term:'. $key .':name', $option);
      }
      else {
        $options[$key] = $option;
      }

Reason: if you have an optional filter, 'All' will be added to the first item in the list. That case would now end up in the very last translation alteration, generating a 'dirty' i18n string that won't make much sense...

pdelorme’s picture

I patched views/modules/taxonomy/views_handler_filter_term_node_tid.inc:136
with

else {
+       global $language_content;
        $options = array();
        $query = db_select('taxonomy_term_data', 'td');
        $query->innerJoin('taxonomy_vocabulary', 'tv', 'td.vid = tv.vid');
+       $query->leftJoin('locales_source', 'ls', 'ls.location=CONCAT(\'taxonomy:term:\',td.tid,\':name\')');
+       $query->leftJoin('locales_target', 'lt', 'ls.lid = lt.lid AND lt.language=\''.$language_content->language.'\'');
        $query->fields('td');
+       $query->addField('lt','translation');
        $query->orderby('tv.weight');
        $query->orderby('tv.name');
        $query->orderby('td.weight');
        $query->orderby('td.name');
        $query->addTag('term_access');
        if ($this->options['limit']) {
          $query->condition('tv.machine_name', $vocabulary->machine_name);
        }
        $result = $query->execute();
        foreach ($result as $term) {
+         $options[$term->tid] = empty($term->translation)?$term->name:$term->translation;
        }
      }

altought it is probably not the nicest way, it works fine.