Index: i18nmenu/i18nmenu.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/i18n/i18nmenu/i18nmenu.module,v
retrieving revision 1.2.2.9
diff -u -p -r1.2.2.9 i18nmenu.module
--- i18nmenu/i18nmenu.module	3 Oct 2008 11:32:24 -0000	1.2.2.9
+++ i18nmenu/i18nmenu.module	4 Dec 2008 22:02:53 -0000
@@ -30,7 +30,7 @@ function i18nmenu_locale($op = 'groups',
 function i18nmenu_locale_refresh() {
   foreach (menu_get_menus() as $name => $title) {
     $tree = menu_tree_all_data($name);
-    i18nmenu_localize_tree($tree);
+    i18nmenu_localize_tree($tree, TRUE);
   }
 }
 
@@ -88,7 +88,7 @@ function i18nmenu_translated_tree($menu_
 /**
  * Localize menu tree.
  */
-function i18nmenu_localize_tree(&$tree) {
+function i18nmenu_localize_tree(&$tree, $update = FALSE) {
   global $language;
   foreach ($tree as $index => $item) {
     $link = $item['link'];
@@ -105,12 +105,11 @@ function i18nmenu_localize_tree(&$tree) 
         $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);
+          $tree[$index]['link']['title'] = _i18nmenu_save_item($link, $update);
         }
         // Localize subtree.
         if ($item['below'] !== FALSE) {
-          i18nmenu_localize_tree($tree[$index]['below']);
+          i18nmenu_localize_tree($tree[$index]['below'], $update);
         }
       }
     }
@@ -118,6 +117,19 @@ function i18nmenu_localize_tree(&$tree) 
 }
 
 /**
+ * Optionally insert/update and return the localized version of a menu item
+ * string.
+ */
+function _i18nmenu_save_item($link, $update = FALSE) {
+  if ($update) {
+    return tt('menu:item:'. $link['mlid'] .':title', $link['link_title'], NULL, TRUE);
+  }
+  else {
+    return tt('menu:item:'. $link['mlid'] .':title', $link['link_title']);
+  }
+}
+
+/**
  * Get the menu router for this router path.
  *
  * We need the untranslated title to compare, and this will be fast.
@@ -132,22 +144,40 @@ function i18nmenu_get_router($path) {
 }
 
 /**
- * Implementation of hook_form_alter().
+ * Implementation of hook_form_form_id_alter().
+ *
+ * Add a language selector to the menu_edit_item form and register a submit
+ * callback to process items.
  */
-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,
-    );
+function i18nmenu_form_menu_edit_item_alter(&$form, $form_state) {
+  if ($form['menu']['#item'] && isset($form['menu']['#item']['options']['langcode'])) {
+    $language = $form['menu']['#item']['options']['langcode'];
   }
-}
\ No newline at end of file
+  else {
+    $language = '';
+  }
+  $form['menu']['language'] = array(
+    '#type' => 'select',
+    '#title' => t('Language'),
+    '#options' => array('' => t('All languages')) + locale_language_list('name'),
+    '#default_value' => $language,
+  );
+  $form['#submit'][] = 'i18nmenu_menu_item_update';
+}
+
+/**
+ * Submit handler for the menu_edit_item form.
+ *
+ * On menu item insert or update, save a translation record.
+ */
+function i18nmenu_menu_item_update($form, &$form_state) {
+  $item = $form_state['values']['menu'];
+  list($item['menu_name'], $item['plid']) = explode(':', $item['parent']);
+  // If this was an insert, determine the ID that was set.
+  if (!isset($link['mlid'])) {
+    $item['mlid'] = db_result(db_query("SELECT mlid FROM {menu_links} WHERE link_path = '%s' AND menu_name = '%s' AND module = 'menu' AND plid = %d AND link_title = '%s'", $item['link_path'], $item['menu_name'], $item['plid'], $item['link_title']));
+  }
+  if (!empty($item['mlid'])) {
+    _i18nmenu_save_item($item, TRUE);
+  }
+}
