How to print localized taxonomy term in node template?
['taxonomy_term']->name; is printing term name, but not localized.

Comments

webflo’s picture

Status: Active » Fixed

Use i18n_taxonomy_term_name() or entity_label().

ali_b’s picture

thank you.
if someone is looking for solution to print localized taxonomy terms, this is the code:
terms are printed as strings, not links, sepatared by commas.
(replace $node->field_yourfieldname with your name)

   <?php 
    $i = 0; 
    $langcode = isset($options['language']) ? $options['language']->language : i18n_langcode();
    foreach($node->field_yourfieldname['und'] as $term) {
    if($i == 0){ 
    $term = $term['taxonomy_term'];
    $term = i18n_taxonomy_term_name($term, $langcode);
    print  $term;
     }
    else {
    $term = $term['taxonomy_term'];
    $term = i18n_taxonomy_term_name($term, $langcode);
    print ', '. $term;
        }
    $i++;
  }   
?>

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.