Index: C:/Programme/wamp/www/drupal-4.7.2/modules/i18n/contrib/i18nmenu.module =================================================================== --- C:/Programme/wamp/www/drupal-4.7.2/modules/i18n/contrib/i18nmenu.module (revision 60) +++ C:/Programme/wamp/www/drupal-4.7.2/modules/i18n/contrib/i18nmenu.module (revision 74) @@ -15,12 +15,123 @@ if($may_cache){ // The menu is being rebuilt. Prepares to translate on second call. $menu_translate = TRUE; + + $items = array(); + + $items[] = array('path' => 'admin/menuTranslate', 'title' => t('menu translations'), + 'callback' => 'i18nmenu_admin_menu_translations', + 'access' => user_access('administer menu')); + + return $items; } elseif($menu_translate) { // This runs only when menu_hook is called twice i18nmenu_translate_all(); } } +function format_inputField($mid, $lang, $name, $value, $size) +{ + $id = $lang. '_' . $name . '_' . $mid; + $output = "" + . ""; + return $output; +} + +//parse the POST variables and update database fields if appropriate. +//return true if updates were made, false otherwise. +function update_menu_translations() +{ + $hasModified = false; + + foreach($_POST as $key => $value) { + $segments = explode("_", $key); + if (count($segments) == 3) { + $lang = $segments[0]; + $name = $segments[1]; + $mid = (int)$segments[2]; + + $oldName = $key . "_old"; + if ($_POST[$oldName] != $value) { + if (is_int($mid) && ($name == 'title' || $name == 'description') ) { + if ($lang == 'en') { + $sql = "update {menu} set %s = '%s' where mid = %d"; + $hasModified |= db_query($sql, $name, $value); + } else { + $sql = "insert into {i18n_menu} set mid_lang = '%d%s', %s = '%s' on duplicate key update %s = '%s'"; + $hasModified |= db_query($sql, $mid, $lang, $name, $value, $name, $value); + } + } + } + } + } + return $hasModified; +} + +function i18nmenu_admin_menu_translations() +{ + $output = ""; + + + global $_menu; + global $user; + global $locale; + + if (update_menu_translations()) + { + // Clear the page cache, so that changed menus are reflected for anonymous users. + cache_clear_all(); + // Also clear the menu cache. + cache_clear_all('menu:', TRUE); + + $output .= t('
Menu translations were updated.
'); + } + + $languages = _i18n_locale_supported_languages(); + + $header = array(); + $rows = array(); + + foreach($languages as $lang => $langName) { + $header[] = $lang . '-title'; + $header[] = $lang . '-description'; + } + + //$destination = '/en/admin/menuTranslate'; + $destination = check_url($_SERVER['REQUEST_URI']); + + foreach($_menu['items'] as $mid => $item) { + if($item['type'] & MENU_CREATED_BY_ADMIN) { + $row = array(); + + $sql = 'SELECT title, description FROM {menu} WHERE mid = \'%d\''; + $result = db_fetch_array( db_query( $sql, $mid ) ); + $row[] = format_inputField($mid, 'en', 'title', $result['title'], 15); + $row[] = format_inputField($mid, 'en', 'description', $result['description'], 35); + + foreach($languages as $lang => $langName) { + if ($lang != 'en') + { + $sql = 'SELECT title, description FROM {i18n_menu} WHERE mid_lang = \'%d%s\''; + $result = db_fetch_array( db_query( $sql, $mid, $lang ) ); + $row[] = format_inputField($mid, $lang, 'title', $result['title'], 15); + $row[] = format_inputField($mid, $lang, 'description', $result['description'], 35); + } + } + $rows[] = $row; + //$_menu['items'][$mid]['title'] = t($_menu['items'][$mid]['title']); + //$result .= "" . $_menu['items'][$mid]['title'] . "
"; + } + } + + $output .= "'; + + + + return $output; +} + function i18nmenu_translate_all(){ global $_menu; global $user; @@ -29,8 +140,17 @@ cache_clear_all($cid); // Translate all user defined meny items foreach($_menu['items'] as $mid => $item) { - if($item['type'] & MENU_CREATED_BY_ADMIN) { - $_menu['items'][$mid]['title'] = t($_menu['items'][$mid]['title']); + if( ($item['type'] & MENU_CREATED_BY_ADMIN) && ($locale != 'en')) { + $sql = 'SELECT title, description FROM {i18n_menu} WHERE mid_lang = \'%d%s\''; + $result = db_fetch_array( db_query( $sql, $mid, $locale ) ); + $title = $result['title']; + $desc = $result['description']; + + if ($title) + $_menu['items'][$mid]['title'] = $title; + + if ($desc) + $_menu['items'][$mid]['description'] = $desc; } } // Update cache