You are here

function i18n_taxonomy_localize_terms in Internationalization 7

Localize taxonomy terms for localizable vocabularies.

Parameters

$terms: Array of term objects or term object.

Return value

Array of terms with the right ones localized.

4 calls to i18n_taxonomy_localize_terms()
i18n_taxonomy_taxonomy_display_breadcrumb_parents_alter in i18n_taxonomy/i18n_taxonomy.module
Implements hook_taxonomy_display_breadcrumb_parents_alter().
i18n_taxonomy_taxonomy_display_term_page_term_object_alter in i18n_taxonomy/i18n_taxonomy.module
Implements hook_taxonomy_display_term_page_term_object_alter().
i18n_taxonomy_term_page in i18n_taxonomy/i18n_taxonomy.pages.inc
Menu callback; displays all nodes associated with a term.
i18n_taxonomy_views_pre_render in i18n_taxonomy/i18n_taxonomy.module
Implements hook_views_pre_render().

File

i18n_taxonomy/i18n_taxonomy.module, line 1054
i18n taxonomy module

Code

function i18n_taxonomy_localize_terms($terms) {

  // If not localizable language just return. Performance optimizations.
  if (!i18n_string_translate_langcode()) {
    return $terms;
  }

  // $terms is not a valid array or term.
  if (empty($terms)) {
    return $terms;
  }
  $object_info = i18n_object_info('taxonomy_term');
  $list = is_array($terms) ? $terms : array(
    $terms,
  );
  foreach ($list as $index => $term) {
    if (i18n_taxonomy_vocabulary_mode($term->vid, I18N_MODE_LOCALIZE)) {
      $localize[$index] = $term->tid;
    }
  }

  // If multiple terms, preload all translations, then run object translation.
  if (!empty($localize)) {
    i18n_string_translation_search(array(
      'taxonomy',
      'term',
      $localize,
      '*',
    ));
    foreach ($localize as $index => $tid) {
      $list[$index] = i18n_string_object_translate('taxonomy_term', $list[$index]);
    }
  }

  // Return array or simple object, depending on incoming format.
  return is_array($terms) ? $list : reset($list);
}