--- translation.module.ori	Mon Apr 02 16:41:02 2007
+++ translation.module	Mon Apr 23 08:17:51 2007
@@ -53,6 +53,13 @@ function translation_menu($may_cache) {
 
   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'),
       'callback' => 'drupal_get_form',
@@ -370,6 +377,17 @@ function translation_node_form($node, $l
   $form['trid'] = array('#type' => 'hidden', '#value' => $node->trid);
   $languages = i18n_node_language_list($node);
 
+  $form['autolookup'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Search for node'),
+    '#description' => t('You can enter the node id or the node title and the autolookup will show the relevant node titles and node ids.<br /> The <strong>node id</strong> will displayed once you have selected a node.'),
+  );
+  $form['autolookup']['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 +397,19 @@ function translation_node_form($node, $l
   return $form;
 }
 
+ /**
+ * Menu callback: autocomplete for selecting node translations
+ */
+function translation_node_autocomplete($string){
+  $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, $node->nid);
+  while($nodelist = db_fetch_object($result)){
+    $matches[$nodelist->nid] = $nodelist->title . ' (nid = ' . $nodelist->nid . ')';
+  }
+  print drupal_to_js($matches);
+  exit();
+}
+
 /**
  * Menu callback: administration page for node translations
  */
@@ -658,7 +689,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
