I am relatively new to Drupal development but I found a fix for a problem that was driving me mad. I am creating a basic site that needs content translated into various languages (entity translation). I got everything else working except the vocabulary title in the Taxonomy Breadcrumb wouldn't display the localized title. The link and Taxonomy Term all worked fine.

But it would always show the default (source) language, English in this case, for the vocabulary title.

I found that if you use the i18n_taxonomy_vocabulary_name($vocabulary) (if you have i18n installed) instead of $vocabulary->name, it would return the translated name. Again, I am new to Drupal so if there is a better way to accomplish this, please share. New code below:

// Generate the VOCABULARY breadcrumb.
  $vocabulary_path = _taxonomy_breadcrumb_get_vocabulary_path($term->vid);
  if ($vocabulary_path != NULL) {
    $vocabulary = taxonomy_vocabulary_load($term->vid);
    
    // Added i18n translation of vocabulary title
    if(function_exists('i18n_taxonomy_vocabulary_name')){
      $breadcrumb[] = l(_taxonomy_breadcrumb_tt("taxonomy:vocabulary:$term->tid:name", i18n_taxonomy_vocabulary_name($vocabulary)), $vocabulary_path);
    }
    else{
      $breadcrumb[] = l(_taxonomy_breadcrumb_tt("taxonomy:vocabulary:$term->tid:name", $vocabulary->name), $vocabulary_path);
    }
  }
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

firebird’s picture

I've got the same problem, with "Home" (see also http://drupal.org/node/1381966 ), and all the parent terms. The term itself is translated as it should.

The breadcrumb segment is passed to function "_taxonomy_breadcrumb_tt()", which is meant to do the translation. It appears that it doesn't do it, since the language is not passed to the function.

As such, I'd be more inclined to fix this by adding the language parameter to the function call.

firebird’s picture

Status: Active » Needs review
FileSize
804 bytes

Didn't quite get it right with the first guess. The reason for failure was actually checking for the existence of the deprecated and removed function tt().

The attached patch calls the current replacement for that function, and fixes the problem for me.

Brian L.’s picture

Your patch is what I tried earlier. I wiped out my code to the latest release of taxonomy_breadcrumb and added your patch and it behaved the same (incorrectly. Everything is translated but the Vocabulary title (i disabled showing the 'Home' part).

I don't have any other customizations to the site and I have the Vocabulary title and description translated as I'm supposed to.

Again, I am totally new to translated/multi-lingual sites let alone Drupal itself, so it might be something elsewhere, but I still had to re-apply my custom code to get the Vocabulary title to translate.

It seems the i18n_string_translate() method doesn't do anything. The strings appear to be translated (or not translated) before they get to this method.

firebird’s picture

Ah, my bad. Looks like I'm not showing the vocab name in the breadcrumb; I thought the first level term was the vocab name.

I actually can't turn on the "Add item for vocabulary"-option, since it's disabled for some reason. I'll look into that next.

My patch above still fixes translation of higher level parent terms, which weren't being translated either.

EDIT: And that option is in Taxonomy _Menu_, not Taxonomy Breadcrumb. How do you turn on the showing of the vocabulary name as the first element?

firebird’s picture

Got it. You just need to define the "breadcrumb path" on the vocabulary edit page, and the vocabulary name is shown in the breadcrumb. I managed to replicate the problem.

Looks like there was a minor case of copy-and-paste coding. The attached patch fixes the translation of the vocabulary name, as well as the translations of the parent terms.

romansta’s picture

Works for me!

jantoine’s picture

Status: Needs review » Closed (duplicate)

Marking this as a duplicate of #1381966: i18n localization support.

Treidge’s picture

Patch in #5 works. No issues so far.

sebto’s picture

Patch in #5 works. Thanks!

Anonymous’s picture

There is a little problem for me, I applied the patch, but the current (active) breadcrumb is still in my default language (the last one, without the link).

romansta’s picture

Have the same problem like #10