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);
}
}
Comment | File | Size | Author |
---|---|---|---|
#5 | taxonomy_breadcrumb-translation_not_working-1382114-5.patch | 1.34 KB | firebird |
#2 | taxonomy_breadcrumb-translation_not_working-1382114-2.patch | 804 bytes | firebird |
Comments
Comment #1
firebird CreditAttribution: firebird commentedI'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.
Comment #2
firebird CreditAttribution: firebird commentedDidn'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.
Comment #3
Brian L. CreditAttribution: Brian L. commentedYour 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.
Comment #4
firebird CreditAttribution: firebird commentedAh, 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?
Comment #5
firebird CreditAttribution: firebird commentedGot 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.
Comment #6
romansta CreditAttribution: romansta commentedWorks for me!
Comment #7
jantoine CreditAttribution: jantoine commentedMarking this as a duplicate of #1381966: i18n localization support.
Comment #8
Treidge CreditAttribution: Treidge commentedPatch in #5 works. No issues so far.
Comment #9
sebto CreditAttribution: sebto commentedPatch in #5 works. Thanks!
Comment #10
Anonymous (not verified) CreditAttribution: Anonymous commentedThere 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).
Comment #11
romansta CreditAttribution: romansta commentedHave the same problem like #10