Closed (duplicate)
Project:
Nice Menus
Version:
6.x-1.3
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
15 Mar 2010 at 07:38 UTC
Updated:
27 May 2010 at 23:44 UTC
in regards to
problem is that nice_menus will show all lang's menu item, same issue goes for http://drupal.org/node/301247
personally i prefer not to touch the module so i used this function in the template.php
Note: This function is tested for 6.x-1.3 but i see no reason why it should not work for 6.x-2x as well
function theme_nice_menu_build($menu) {
global $language;
$output = '';
/*http://drupal.org/node/301247#comment-1497198*/
$index = 0;
$count = 0;
//count only if item is not hidden and is shown only for the current language
foreach ($menu as $menu_count) {
if ( ($menu_count['link']['hidden'] == 0) && ($menu_count['link']['localized_options']['langcode'] == $language->language) ) {
$count++;
}
}
$output = '';
foreach ($menu as $menu_item) {
$mlid = $menu_item['link']['mlid'];
// Check to see if it is a visible menu item.
if ($menu_item['link']['hidden'] == 0) {
//check page language and render the menu only item if same as page language
if ( $menu_item['link']['localized_options']['langcode'] == $language->language ){
// Build class name based on menu path
// e.g. to give each menu item individual style.
// Strip funny symbols.
$clean_path = str_replace(array('http://', '<', '>', '&', '=', '?', ':'), '', $menu_item['link']['href']);
// Convert slashes to dashes.
$clean_path = str_replace('/', '-', $clean_path);
$path_class = 'menu-path-'. $clean_path;
// If it has children build a nice little tree under it.
if ((!empty($menu_item['link']['has_children'])) && (!empty($menu_item['below']))) {
// Keep passing children into the function 'til we get them all.
$children = theme('nice_menu_build', $menu_item['below']);
// Set the class to parent only of children are displayed.
$parent_class = $children ? 'menuparent ' : '';
$output .= '<li id="menu-'. $mlid .'" class="'. $parent_class . $path_class .'">'. theme('menu_item_link', $menu_item['link']);
// Build the child UL only if children are displayed for the user.
if ($children) {
$output .= '<ul>';
$output .= $children;
$output .= "</ul>\n";
}
$output .= "</li>\n";
}
else {
$output .= '<li id="menu-'. $mlid .'" class="'. $path_class .'">'. theme('menu_item_link', $menu_item['link']) .'</li>'."\n";
}
}
}
}
return $output;
}
Comments
Comment #1
avner commentedforgot to add the classed to the output
fixed code
Comment #2
greg.harveyTwo problems with this request:
1. Many themes add a language class to the body tag, so why would you need language information at menu level, when you can do
body.lang-fr .nice-menus etc. {}(I don't remember exactly what the styles are, but you get the point...)2. It was pointed out to me when I made a similar patch for Zen that you can do this with CSS anyway, no class required:
http://www.w3.org/International/questions/qa-css-lang
Thoughts?
Comment #3
avner commentedHi Greg,
maybe it is me who is missing something here.
I will try to explain my point:
The problem here is that unlike the core's menu module, the nice_menus will render all menu items with no regards to the language of the page.
thus, if we have a bi-lingual site, which has 5 menu items for each language, instead of showing the 5 right items for the relevant language, it will show all ten.
True, you can use css to make the unneeded items disappear, however, you may lose the odd even first last functionality. In any case i do not think this is best practice since you should not render what is not being used.
Comment #4
greg.harveyOhhhh, I'm sorry - ignore me. I misunderstood the purpose of the patch. Serves me right for not actually reading the code.
I would mark up the behaviour you describe as a bug rather than a feature request, as it's a feature of Drupal core the module ought to cater for... IMHO anyway.
Comment #5
add1sun commentedThis was a feature added to the 2.x version #300628: Support menu translation (i18n)
Comment #6
avner commentedsince drupal is a multi lang system, and the nice menu doesnt support this core feature, shouldnt this issue be makred as a bug for version 1.3? even though its fixed in later version
Comment #7
greg.harveyActually, my mistake on that - node translation is core, menu translation with i18n is not, so definitely a feature request. I see no reason why Nice Menus would not function fine if you did menu translations the "old fashioned" way, e.g. translate nodes (core) and provide a different menu item for the translated nodes on a different (translated) menu (then give the menu blocks a language so you load the correct one for the correct language). This is how it was done before i18n and I can't think of any reason why Nice Menus wouldn't work with this approach?
Comment #8
add1sun commentedAs Greg points out, menu translation is not in core so this is a feature request, not a bug. I am not inclined to add any more features to 1.x because I have extremely limited time and need to get 2.x stable and out the door to prepare for a D7 port.
Comment #9
avior commentedHi
just needed that , thank you
but must check if the current item is marked 'All languages' (no language)
change the if to this
thank you