Hi,
It seems that terms in facets are not translated if the translation mode is set to "localize". I've created a little patch to manage translation. It's not very clean, but it works...

@@ -355,7 +355,15 @@ function search_api_facets_block_view($delta = '') {
if ($entities) {
$values = array();
foreach ($entities as $id => $entity) {
- $label = entity_label($options['entity_type'], $entity);
+ if($options['entity_type']=='taxonomy_term'){
+ //HERE WE LOAD THE TERM NAME
+ $label = i18n_taxonomy_term_name($entity);
+ }else{
+ $label = entity_label($options['entity_type'], $entity);
+ }
+ 
+ 
if ($label) {
$values[$id] = $label;
}
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

drunken monkey’s picture

Title: Facet term translation » Language in entity_label()
Project: Search API » Entity API
Component: Facets » Code - misc

We can't just use a function from the i18n module there.
I'd rather say that entity_label() should be locale-aware – and actually I believed it was.
Moving this to the Entity API issue queue, let's see what fago says.

fago’s picture

Project: Entity API » Internationalization
Component: Code - misc » Taxonomy

entity_label() is rather dumb, but that should be doable via a query callback and/or using the translation query tag. I guess this should be an i18n issue.

romaingar’s picture

Yes you're right,
it's not a problem with facets but with entity_label...
the same problem happends too with the #subject of the block.

tnightingale’s picture

Status: Active » Needs review
FileSize
1.05 KB

Here's a patch that implements hook_entity_info_alter() in i18n_taxonomy to add a label callback that ensures the taxonomy term name returned by entity_label() is in the language that the site is being viewed in.

Jose Reyero’s picture

Status: Needs review » Fixed

Looks great. Committed. Thanks.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

mpp’s picture

I had to patch this fix too to make facet block terms translated:in Facet API at #1276812: Multilingual facet items. It is in the dev snapshot, but not yet in the supported release.

FiNeX’s picture

@mpp: I'm using the latest version of i18n (which contains the patch) but still facet blocks doesn't display localized terms: http://drupal.org/node/1276812#comment-6727336

foopang’s picture

Hi FiNeX, I had the same problem before, I checked that it was the Title module I use (http://drupal.org/project/title) it also implemented hook_entity_info_alter to override the entity label callback function so that the i18n label callback function for Taxonomy terms won't get called. I solved this by adding a condition in the Title module's hook_entity_info_alter to check for overriding the node entity type only, I think that should be fine as the Title module would only affect the node entity type. Please advise, thanks.

Index: title.module
===================================================================
--- title.module	(revision 103)
+++ title.module	(revision 104)
@@ -67,7 +67,7 @@
         );
 
         // Support add explicit support for entity_label().
-        if (isset($entity_info['entity keys']['label']) && $entity_info['entity keys']['label'] == $legacy_field) {
+        if (isset($entity_info['entity keys']['label']) && $entity_info['entity keys']['label'] == $legacy_field && $entity_type == 'node') {
           $info[$entity_type]['label callback'] = 'title_entity_label';
           $fr_info += array('preprocess_key' => $info[$entity_type]['entity keys']['label']);
         }
Anonymous’s picture

@FiNeX et al: I'm unsure if I am affected by this, too. The result is the same (facet blocks not showing translated terms). However, I don't use taxonomy terms but fields. Taxonomy terms work fine for me. Anyone else?

edit:
this is it: http://drupal.org/node/1210730#comment-6787050

GaëlG’s picture

foopang’s picture

Thanks GaëlG!

brainHax’s picture

Issue summary: View changes

Do you still have to translate each terms from translate interface?