2

I'm using Entity Translation for Taxonomy Terms.

I've a Cities Vocabulary and I need to get translated names of some 1600 cities.

Using taxonomy_get_tree without arguments returns the term names in English. However if I pass the last parameter $load_entities= TRUE then it currectly returns $term->name as translated one.

But it seems fully loading 1600 terms by setting $load_entities can slown down the site performance heavily as mentioned in the api page.

Is there any faster way to do it?

I'm thinking of caching the results in a temp file. Or can use some query as in When using Entity Translation and the Title module, how can I get the translated term from the term ID programmatically? to fetch it myself.

3

You are using Entity Translation, so keep in mind there can't be any translated term load because you're translating fields not whole term. Term will load by

$term = taxonomy_term_load($tid);

use in devel mode or by dpm see the $term object. There you'll see structure

$term->name_field['en'][0]['value'] 

You can fetch it this way or by field_get_items() for en language.

$name = field_get_items('taxonomy_term', $term, 'name_field', 'en');

AND

$term->name_field['fr'][0]['value']

You can fetch it this way or by field_get_items() for fr language.

$name = field_get_items('taxonomy_term', $term, 'name_field', 'fr');

This is how you can get the data per language

| improve this answer | |
  • Thanks but isn't this very slow for 1600 terms? This is what exactly I asked. – AgA Apr 9 '15 at 11:08
  • 1
    Then using entityFieldQuery would be good. Read drupal.org/node/1343708 – Himanshu Pathak Apr 9 '15 at 13:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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