You are here

function i18n_taxonomy_translate_path in Internationalization 7

Find translations for taxonomy paths.

Parameters

$path: Path to translate.

$path_prefix: Path prefix, including trailing slash, defaults to 'taxonomy/term/'. It will be different for taxonomy term pages and for forum pages.

Return value

Array of links (each an array with href, title), indexed by language code.

2 calls to i18n_taxonomy_translate_path()
i18n_forum_i18n_translate_path in i18n_forum/i18n_forum.module
Implements hook_i18n_translate_path()
i18n_taxonomy_i18n_translate_path in i18n_taxonomy/i18n_taxonomy.module
Implements hook_i18n_translate_path()

File

i18n_taxonomy/i18n_taxonomy.module, line 435
i18n taxonomy module

Code

function i18n_taxonomy_translate_path($path, $path_prefix = 'taxonomy/term/') {
  $prefix_match = strtr($path_prefix, array(
    '/' => '\\/',
  ));
  if (preg_match("/^({$prefix_match})([^\\/]*)(.*)\$/", $path, $matches)) {
    $links = array();
    $term = FALSE;

    // If single term, treat it differently
    if (is_numeric($matches[2]) && !$matches[3]) {
      $term = taxonomy_term_load($matches[2]);
      if (!empty($term->i18n_tsid)) {
        $set = i18n_translation_set_load($term->i18n_tsid);
      }
    }
    foreach (language_list() as $langcode => $language) {
      if ($term) {
        if (!empty($set) && ($translation = $set
          ->get_item($langcode))) {
          $links[$langcode] = array(
            'href' => $path_prefix . $translation->tid,
            'title' => $translation->name,
          );
        }
        else {
          $links[$langcode] = array(
            'href' => $path,
            'title' => i18n_taxonomy_term_name($term, $langcode),
          );
        }
      }
      elseif ($str_tids = i18n_taxonomy_translation_tids($matches[2], $langcode)) {
        $links[$langcode]['href'] = $path_prefix . $str_tids . $matches[3];
      }
    }
    return $links;
  }
}