Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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;
}
Comment | File | Size | Author |
---|---|---|---|
#4 | i18n_taxonomy-entity_label_callback-1340858.patch | 1.05 KB | tnightingale |
Comments
Comment #1
drunken monkeyWe 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.
Comment #2
fagoentity_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.
Comment #3
romaingar CreditAttribution: romaingar commentedYes 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.
Comment #4
tnightingale CreditAttribution: tnightingale commentedHere'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.
Comment #5
Jose Reyero CreditAttribution: Jose Reyero commentedLooks great. Committed. Thanks.
Comment #7
mpp CreditAttribution: mpp commentedI 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.
Comment #8
FiNeX CreditAttribution: FiNeX commented@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
Comment #9
foopang CreditAttribution: foopang commentedHi 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.
Comment #10
Anonymous (not verified) CreditAttribution: Anonymous commented@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
Comment #11
GaëlGI just submitted Title problem mentioned in #9 at #1865604: Title module overrides label callback (prevents term label localization).
Comment #12
foopang CreditAttribution: foopang commentedThanks GaëlG!
Comment #13
brainHax CreditAttribution: brainHax commentedDo you still have to translate each terms from translate interface?