By mate64


2013-07-11 11:37:20 8 Comments

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 in "how to get the translated taxonomy term programmatically?" seem not work for Drupal 7.

5 comments

@a.alshamiri 2017-11-19 10:21:38

If you want to use it as Function..

function _get_term_name_translate($tid) {
  $term = i18n_taxonomy_localize_terms(taxonomy_term_load($tid));
  return $term->name;
}

@Florian Limmer 2014-06-18 08:13:30

You should use the i18n_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;

@B2F 2014-10-13 14:05:07

I had the same problem with localized taxonomy term translations. If you have your "Multilingual options" translation mode set to "Localize", then it's pretty straightforward.

Let's say your term id is 788 like the OP's, then just do something along these lines:

  $i18n_object = i18n_get_object('taxonomy_term', 788);
  $target_langcode = 'de';
  $translated_term = $i18n_object->localize($target_langcode);

@GwenM 2014-12-19 14:07:52

It worked for me!, weird that the function i18n_taxonomy_localize_terms didn't. thx

@jan 2015-01-27 14:13:27

Worked perfect. Like @Namari function i18n_taxonomy_localize_terms didn't seem to do its job.

@batigolix 2013-10-21 12:49:48

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?

@Oumar 2013-07-31 15:48:16

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!

Related Questions

Sponsored Content

1 Answered Questions

How to get the vocabulary terms for the current language

3 Answered Questions

1 Answered Questions

[SOLVED] How to get term ID from translated term name?

  • 2018-11-20 23:51:20
  • andileco
  • 48 View
  • 1 Score
  • 1 Answer
  • Tags:   views 8 i18n-l10n

3 Answered Questions

[SOLVED] Set term tid programmatically

  • 2012-08-20 14:52:29
  • arrubiu
  • 2095 View
  • 2 Score
  • 3 Answer
  • Tags:   taxonomy-terms

5 Answered Questions

[SOLVED] How to get custom field labels translated

1 Answered Questions

[SOLVED] Get translated taxonomy terms with Entity Translation

  • 2015-04-09 05:49:23
  • AgA
  • 2358 View
  • 2 Score
  • 1 Answer
  • Tags:   7 i18n-l10n

1 Answered Questions

Sponsored Content