t('Menu')); case 'refresh': if ($group == 'menu') { return i18nmenu_locale_refresh(); } } } /** * Refresh locale strings. */ function i18nmenu_locale_refresh() { foreach (menu_get_menus() as $name => $title) { $tree = menu_tree_all_data($name); i18nmenu_localize_tree($tree); } } /** * Implementation of hook_menu_link_alter(). * * Catch changed links, update language and refresh texts */ function i18nmenu_menu_link_alter(&$item, $menu) { // If we set option to language it causes an error with the link system // This should handle language only as the links are being manually updated if (!empty($item['language'])) { $item['options']['langcode'] = $item['language']; } elseif (isset($item['language'])) { unset($item['options']['langcode']); } // @ TO DO: Refresh texts //dsm($item); //$original = $item['original_item']; //$item['router_path'] = _menu_find_router_path($menu, $item['link_path']); //i18nmenu_make_translatable($item); } /** * Implementation of hook_help(). */ function i18nmenu_help($path, $arg) { switch ($path) { case 'admin/help#i18nmenu' : $output = '

'. t('This module provides support for translatable custom menu items:') .'

'; $output .= ''; $output .= '

'. t('To search and translate strings, use the translation interface pages.', array('@translate-interface' => url('admin/build/translate'))) .'

'; return $output; } } /** * Get localized menu tree. */ function i18nmenu_translated_tree($menu_name) { static $menu_output = array(); if (!isset($menu_output[$menu_name])) { $tree = menu_tree_page_data($menu_name); i18nmenu_localize_tree($tree); $menu_output[$menu_name] = menu_tree_output($tree); } return $menu_output[$menu_name]; } /** * Localize menu tree. */ function i18nmenu_localize_tree(&$tree) { global $language; foreach ($tree as $index => $item) { $link = $item['link']; if ($link['customized']) { // Remove links for other languages than current. // Links with language wont be localized. if (!empty($link['options']['langcode'])) { if ($link['options']['langcode'] != $language->language) { unset($tree[$index]); //dsm("Removed because language:".$link['title'].' language='.$link['options']['langcode']); } } else { $router = i18nmenu_get_router($link['router_path']); // If the title is the same it will be localized by the menu system. if ($link['link_title'] != $router['title']) { //$tree[$index]['link']['title'] = 'Translated'; $tree[$index]['link']['title'] = tt('menu:item:'. $link['mlid'] .':title', $link['link_title'], NULL, TRUE); } // Localize subtree. if ($item['below'] !== FALSE) { i18nmenu_localize_tree($tree[$index]['below']); } } } } } /** * Get the menu router for this router path. * * We need the untranslated title to compare, and this will be fast. * There's no api function to do this? */ function i18nmenu_get_router($path) { static $cache = array(); if (!array_key_exists($path, $cache)) { $cache[$path] = db_fetch_array(db_query("SELECT title FROM {menu_router} WHERE path = '%s'", $path)); } return $cache[$path]; } /** * Implementation of hook_form_alter(). */ function i18nmenu_form_alter(&$form, $form_state, $form_id) { if ($form_id == 'menu_edit_item') { //dsm ($form); if ($form['menu']['#item'] && isset($form['menu']['#item']['options']['langcode'])) { $language = $form['menu']['#item']['options']['langcode']; } else { $language = ''; } $form['menu']['language'] = array( '#type' => 'select', '#title' => t('Language'), '#options' => array('' => t('All languages')) + locale_language_list('name'), '#default_value' => $language, ); } }