You are here

function i18n_taxonomy_term_get_translation in Internationalization 7

Find term translation from translation set.

@result object Taxonomy Term Translation if exists.

Parameters

$term: Term object to find translation.

$langcode: Language code to find translation for.

2 calls to i18n_taxonomy_term_get_translation()
i18n_taxonomy_field_prepare_translation in i18n_taxonomy/i18n_taxonomy.module
Prepare and synchronize translation for term reference fields
i18n_taxonomy_tokens in i18n_taxonomy/i18n_taxonomy.tokens.inc
Implements hook_tokens().

File

i18n_taxonomy/i18n_taxonomy.module, line 497
i18n taxonomy module

Code

function i18n_taxonomy_term_get_translation($term, $langcode) {
  if (i18n_object_langcode($term)) {
    if ($term->language == $langcode) {

      // Translation is the term itself.
      return $term;
    }
    elseif (!empty($term->i18n_tsid)) {
      return i18n_translation_set_load($term->i18n_tsid)
        ->get_item($langcode);
    }
    else {
      return NULL;
    }
  }
  else {

    // Term has no language, translation should be the same
    return $term;
  }
}