function taxonomy_menu_translated_menu_link_alter in Taxonomy menu 7.2
Same name and namespace in other branches
- 6.3 taxonomy_menu.module \taxonomy_menu_translated_menu_link_alter()
- 6.2 taxonomy_menu.module \taxonomy_menu_translated_menu_link_alter()
- 7 taxonomy_menu.module \taxonomy_menu_translated_menu_link_alter()
Implements hook_translated_menu_link_alter().
Translate menu links on the fly by using term translations.
File
- ./
taxonomy_menu.module, line 645 - Generates menu links for all selected taxonomy terms.
Code
function taxonomy_menu_translated_menu_link_alter(&$item, $map) {
if (module_exists('i18n_taxonomy')) {
// In case of localized terms, use term translation for menu title.
if ($item['module'] == 'taxonomy_menu') {
$t = _taxonomy_menu_get_item($item['mlid']);
// Only translate when term exist (may per example occur with stray menu item)
if ($t) {
// Only translate when translation mode is set to localize
if (i18n_taxonomy_vocabulary_mode($t->vid, I18N_MODE_LOCALIZE)) {
// this is a term
if ($t->tid > 0) {
$term = taxonomy_term_load($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 && taxonomy_menu_variable_get('hide_empty_terms', $t->vid, FALSE) && !_taxonomy_menu_children_has_nodes($t->tid, $t->vid)) {
$display_num = '';
}
elseif (taxonomy_menu_variable_get('display_num', $t->vid, FALSE)) {
// if number > 0 and display descendants, then count all of the children
if (taxonomy_menu_variable_get('display_descendants', $t->vid, FALSE)) {
$num = taxonomy_menu_term_count_nodes($t->tid);
}
$display_num = " ({$num})";
}
if ($item['title'] != $term->name . $display_num) {
// Should not happen
watchdog('error', 'Menu and taxonomy name mismatch: @title != @name', array(
'@title' => $item['title'],
'@name' => $term->name . $display_num,
));
}
$term = i18n_taxonomy_localize_terms($term);
$item['title'] = $item['link_title'] = $term->name . $display_num;
if ($term->description) {
$item['options']['attributes']['title'] = $term->description;
}
}
else {
$vocab = taxonomy_vocabulary_load($t->vid);
$item['title'] = i18n_string('taxonomy:vocabulary:' . $vocab->vid . ':name', $vocab->name);
}
}
}
else {
watchdog('taxonomy_menu', 'Error with menu entry "%me" in menu "%mt"', array(
'%me' => $item['title'],
'%mt' => $item['menu_name'],
));
}
}
}
}