4

My site uses multiple languages and I'm using menu_tree_all_data() to get the menu tree programmatically. Currently all nodes and their translated nodes use the same menu tree.

If I use a menu block the menu that is displayed is filted by language version of the site the user is on. Which is good.

When calling the menu_tree_all_data() in code to build a menu programmatically it returns the entire tree and there does not seem to be an option to filter the menu by a language.

Does anyone know how to get the menu tree in code filted for a specific language?

1 Answer 1

6

I suppose you have i18n_menu.module installed. In this case, use i18n_menu_localize_tree($MENU_TREE) to get the tree for the current language.

To get secondary menu, for instance (on template.php):

$tree = menu_tree_all_data('menu-secondary');
$variables['secondary_menu_expanded'] = menu_tree_output(i18n_menu_localize_tree($tree));
1
  • Useful answer. Actually i had to use: menu_tree_output(i18n_menu_localize_tree(menu_tree_all_data('mymenu_machine_name'))) Commented Jan 25, 2016 at 14:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.