You are here

function taxonomy_menu_translated_menu_link_alter in Taxonomy menu 6.3

Same name and namespace in other branches
  1. 6.2 taxonomy_menu.module \taxonomy_menu_translated_menu_link_alter()
  2. 7.2 taxonomy_menu.module \taxonomy_menu_translated_menu_link_alter()
  3. 7 taxonomy_menu.module \taxonomy_menu_translated_menu_link_alter()

Implementation of hook_translated_menu_link_alter().

Translate menu links on the fly by using term translations.

File

./taxonomy_menu.module, line 362
It Generates menu links for all selected taxonomy terms

Code

function taxonomy_menu_translated_menu_link_alter(&$item, $map) {
  if (module_exists('i18ntaxonomy')) {

    // in case of localized terms, use term translation for menu title
    if ($item['module'] == 'taxonomy_menu') {

      // TODO: check vocabulary translation mode before tryring to translate: but is this really usefull ?
      //  if (i18ntaxonomy_vocabulary($vid) == I18N_TAXONOMY_LOCALIZE) {
      $t = _taxonomy_menu_get_item($item['mlid']);
      if ($t['tid'] > 0) {

        // this is a term
        $term = taxonomy_get_term($t['tid']);
        $display_num = '';
        $num = _taxonomy_menu_term_count($t['tid']);

        //if hide menu is selected and the term count is 0 and the term has no children then do not create the menu item
        if ($num == 0 && variable_get('taxonomy_menu_hide_empty_terms_' . $t['vid'], FALSE) && _taxonomy_menu_children_has_nodes($t['tid'], $t['vid'])) {
          $display_num = '';
        }
        else {
          if (variable_get('taxonomy_menu_display_num_' . $t['vid'], FALSE)) {

            // if number > 0 and display decendants, then count all of the children
            if (variable_get('taxonomy_menu_display_descendants_' . $t['vid'], FALSE)) {
              $num = taxonomy_term_count_nodes($t['tid']);
            }
            $display_num = " ({$num})";
          }
        }
        if ($item['title'] != $term->name . $display_num) {

          // Should not happen
          drupal_set_message(t('Menu and taxonomy name mismatch : @title != @name', array(
            '@title' => $item['title'],
            '@name' => $term->name . $display_num,
          )), 'error');
        }
        $item['title'] = tt('taxonomy:term:' . $term->tid . ':name', $term->name) . $display_num;
      }
      else {

        // is a vocabulary
        $vocab = taxonomy_vocabulary_load($t['vid']);
        $item['title'] = tt('taxonomy:vocabulary:' . $vocab->vid . ':name', $vocab->name);
      }
    }
  }
}