I have tried this
$term = taxonomy_term_load($tid);
and this:
$term = i18n_taxonomy_localize_terms(taxonomy_term_load($tid));
Both return the default language (English) term
I am using D7.
Drupal Answers is a question and answer site for Drupal developers and administrators. It only takes a minute to sign up.
Sign up to join this communityTry
$term = taxonomy_term_load($tid);
$translated_term = i18n_taxonomy_term_get_translation($term, $langcode);
Also, a good place to look for more information: /sites/all/modules/i18n/i18n_taxonomy/i18n_taxonomy.module
To translate a string, you should use two functions, depending on which i18n mode you use:
Localize mode: i18n_string_translation_update()
<?php
$result_translation = i18n_string_translation_update(
array('taxonomy', 'term', $tid, 'name'), // Path where to store source and translation.
$translated_string,
$language,
$source_string
);
?>
Translate mode: i18n_translation_set_create()
<?php
// 1. Load or create a translation set.
$translation_set = ($source_term->i18n_tsid) ?
i18n_translation_set_load($source_term->i18n_tsid) :
i18n_translation_set_create('taxonomy_term', $vocabulary->machine_name);
// 2. Add the full source term in this set.
$translation_set->add_item($source_term, $source_term->language);
// 3. Add the full translated term in this set.
$translation_set->add_item($translated_term, $translated_term->language);
$translation_set->save(TRUE);
?>
Strings for other contents and modules
When a module defines its own strings, it must use some additional functions to allow these string to be tracked and updated.
Define the textgroup by implementing hook_i18n_string_info()
. This is how it looks (i18n_taxonomy module)
<?php
/**
* Implements hook_i18n_string_info()
*/
function i18n_taxonomy_i18n_string_info() {
$groups['taxonomy'] = array(
'title' => t('Taxonomy'),
'description' => t('Vocabulary titles and term names for localizable vocabularies.'),
'format' => FALSE, // This group doesn't have strings with format
'list' => FALSE, // This group cannot list all strings
'refresh callback' => 'i18n_taxonomy_i18n_string_refresh',
);
return $groups;
}
?>
Read more at: Using the i18n API from other modules
Related:
How to associate programatically the translation of new term to the original existing term?
i18n_taxonomy_localize_terms works on getting site language
please check Home » Administration » Configuration » Regional and language » Languages to ensure the site language detection is working as you wanted
i got this done when site languages change on user language preference
Here is how to rewrite the Finder menue display with localized tayonomy terms:
<?php
$query = new EntityFieldQuery;
$result = $query
->entityCondition('entity_type', 'taxonomy_term')
->propertyCondition('name', $display)
->propertyCondition('vid', 3) // Change this to Your ID!!
->execute();
$found_tid = array_shift($result['taxonomy_term'])->tid;
// print $found_tid;
$tid = $found_tid;
$term = taxonomy_term_load($tid);
$translated_term = i18n_taxonomy_localize_terms($term);
print $translated_term->name;
?>