tags:

views:

27

answers:

2

I'm doing a simple for loop through the terms in a given vocabulary, these terms have their description in both the default language and an additional. The thing is that $term->description is always returning the default language version no matter which language is active so I guess I'm missing something here since I guessed (appparently wrong) that this field would be populated with the active language version. Here's a bit of the code I'm using:

<?php $terms = taxonomy_get_tree(5);    
        for ($index = 0; $index < count($terms); $index++) {?>

                ...

                <div class="info"><?php echo trim_description($terms[$index]->description, 10) ?></div>

                <div class="more-info"><a href="<?php print url(taxonomy_term_path($terms[$index])); ?>">More details</a></div>
            </div>
        <?php }?>

Edited to add: my default language is not english, I have spanish by default and english as the second option.

+1  A: 

Try calling t():

<div class="info"><?php echo trim_description(t($terms[$index]->description), 10) ?></div>
dusan
Just did, but keeps returning the same string. Still I'll look deeper into it so thanks a lot.
JoseMarmolejos
`t()` has a third parameter, the language code. Experiment with it.
dusan
Apparently the t() method only translates from english to a second language. Kind of a fail.
JoseMarmolejos
+1  A: 

If you are using the Taxonomy translation module, you should use i18ntaxonomy_translate_terms() to get the translations of your terms.

<?php
global $language
$terms = i18ntaxonomy_translate_terms(taxonomy_get_tree(5), $language->language));
for ($index = 0; $index < count($terms); $index++): ?>
  <div>
    ...
    <div class="info"><?php echo trim_description($terms[$index]->description, 10) ?></div>
    <div class="more-info"><a href="<?php print url(taxonomy_term_path($terms[$index])); ?>">More details</a></div>
  </div>
<?php endfor;?>
mongolito404
i18nstrings_translate_string() did the trick, but I'm still playing around with it as it's behaving a bit strange.
JoseMarmolejos