You are here

function i18n_menu_localize_tree in Internationalization 7

Localize menu tree.

2 calls to i18n_menu_localize_tree()
i18n_menu_navigation_links in i18n_menu/i18n_menu.module
Return an array of localized links for a navigation menu.
i18n_menu_translated_tree in i18n_menu/i18n_menu.module
Get localized menu tree.

File

i18n_menu/i18n_menu.module, line 392
Internationalization (i18n) submodule: Menu translation.

Code

function i18n_menu_localize_tree($tree, $langcode = NULL) {
  $langcode = $langcode ? $langcode : i18n_language_interface()->language;
  foreach ($tree as $index => &$item) {
    $link = $item['link'];

    // We only process links that are visible and not processed before.
    if (_i18n_menu_link_process($item['link'])) {
      if (!_i18n_menu_link_is_visible($item['link'], $langcode)) {

        // Remove links for other languages than current.
        // Links with language won't be localized.
        unset($tree[$index]);

        // @todo Research whether the above has any advantage over:
        // $item['hidden'] = TRUE;
      }
      else {
        if (_i18n_menu_link_is_localizable($item['link'])) {

          // Item has undefined language, it is a candidate for localization.
          _i18n_menu_link_localize($item['link'], $langcode);
        }

        // Localize subtree.
        if (!empty($item['below'])) {
          $item['below'] = i18n_menu_localize_tree($item['below'], $langcode);
        }
      }
    }
  }
  return $tree;
}