Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I'm looking for a working method to get the translated term name by tid.

The following code returns the original term name but not the translation.

global $language;

$lang_name = $language->language; // en

$term_id = 788;

$term = i18n_taxonomy_term_get_translation($term_id, $lang_name);

Example of a translated Taxonomy Term (German to English)

Most examples provided by different users here or here seems not work for Drupal .

share|improve this question
    
i think the code should work but the first parameter should be a term object and not a term id... –  lenni Jul 11 '13 at 12:37
    
@lenni Unfortunately it does not to work. Drupal returns the same object back. –  cept0 Jul 11 '13 at 13:35

3 Answers 3

I managed to make it work! This is my code

$tree = taxonomy_get_tree(9); // Your taxonomy id

foreach ($tree as $term) {
  if (module_exists('i18n_taxonomy')) { //To not break your site if module is not installed
    $term = i18n_taxonomy_localize_terms($term); // The important part!
  }
  print l($term->name, 'taxonomy/term/' . $term->tid); //print the terms
}

That sould do it! Diadeuf!

share|improve this answer

You should use the 18n_taxonomy_localize_terms() function. This is the working code for me:

$tid = 10;
$term = taxonomy_term_load($tid);
$translated_term = i18n_taxonomy_localize_terms($term);
print $translated_term->name;
share|improve this answer

Knibals code shows how to translate a full vocabulary tree. This code snippet shows how to translate one specific term.

$term = taxonomy_term_load($tid);
$translated_term = i18n_taxonomy_term_get_translation($term, $langcode);

This question was already answered here: how to get the translated taxonomy term programmatically?

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.