--- translation.module	Mon Apr 02 16:41:02 2007
+++ translation.module	Tue Apr 17 21:29:06 2007
@@ -52,6 +52,15 @@ function translation_menu($may_cache) {
   $items = array();

   if ($may_cache) {
+
+    $items[] = array(
+      'path' => 'translation/autocomplete',
+      'title' => t('translation node autocomplete'),
+      'callback' => 'translation_node_autocomplete',
+      'access' => user_access('administer site configuration'),
+      'type' => MENU_CALLBACK,
+    );
+
     $items[] = array(
       'path' => 'admin/settings/i18n/translation',
       'title' => t('Translation'),
@@ -370,6 +379,18 @@ function translation_node_form($node, $l
   $form['trid'] = array('#type' => 'hidden', '#value' => $node->trid);
   $languages = i18n_node_language_list($node);

+  $form['alternate'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Search for node'),
+    '#description' => t('You can enter the node id or the node title and the autolookup will find the relevant node id(s) and display the corresponding node title once selected.'),
+  );
+  $form['alternate']['lookup'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Enter node id or title'),
+    '#size' => 30,
+    '#autocomplete_path' => 'translation/autocomplete',
+  );
+
   $form['nodes']['nid'] = array(
    '#type' => 'radios', '#title' => t('Select translation for %language', array('%language' => $languages[$lang])),
        '#default_value' => isset($node->translation[$lang]) ? $node->translation[$lang]->nid : '',
@@ -379,6 +400,19 @@ function translation_node_form($node, $l
   return $form;
 }

+/* new function for autocomplete */
+function translation_node_autocomplete($string){
+  global $i18n_langpath;
+  $lang = $i18n_langpath;
+  $matches = array();
+  $result = db_query("SELECT n.nid, n.title FROM {node} n INNER JOIN {i18n_node} i ON n.nid = i.nid WHERE (LOWER(n.title) LIKE LOWER('%s%%') OR n.nid = %d) AND i.language != '%s'", $string, $string, $lang);
+  while($nodelist = db_fetch_object($result)){
+    $matches[$nodelist->nid] = $nodelist->title;
+  }
+  print drupal_to_js($matches);
+  exit();
+}
+
 /**
  * Menu callback: administration page for node translations
  */
@@ -658,7 +692,12 @@ function translation_node_form_submit($f
   $op = $_POST['op'];
   $source_nid = $form_values['source_nid'];
   $language = $form_values['language'];
-  $nid = $form_values['nid'];
+  if($form_values['nid']) {
+    $nid = $form_values['nid'];
+  }
+  if ($form_values['lookup']) {
+    $nid = $form_values['lookup'];
+  }
   if( $source_nid && $language && $nid ) {
    if($trid = $form_values['trid']){
       // Delete old translations
