Index: modules/simpletest/tests/translation_test.info
===================================================================
RCS file: modules/simpletest/tests/translation_test.info
diff -N modules/simpletest/tests/translation_test.info
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ modules/simpletest/tests/translation_test.info	20 Jan 2009 23:46:20 -0000
@@ -0,0 +1,9 @@
+; $Id$
+name = "Translation test"
+description = "Support module for Translation testing."
+package = Testing
+version = VERSION
+core = 7.x
+files[] = translation_test.module
+dependencies[] = translation
+hidden = TRUE
Index: modules/simpletest/tests/translation_test.module
===================================================================
RCS file: modules/simpletest/tests/translation_test.module
diff -N modules/simpletest/tests/translation_test.module
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ modules/simpletest/tests/translation_test.module	20 Jan 2009 23:46:20 -0000
@@ -0,0 +1,9 @@
+<?php
+// $Id$
+
+/**
+ * Implementaton of hook_translation_change().
+ */
+function translation_test_nodeapi_translation_change($node) {
+  variable_set('translation_change_called', $node->nid);
+}
Index: modules/translation/translation.api.php
===================================================================
RCS file: modules/translation/translation.api.php
diff -N modules/translation/translation.api.php
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ modules/translation/translation.api.php	20 Jan 2009 23:46:20 -0000
@@ -0,0 +1,12 @@
+/**
+ * Respond to changes in a node's translation set.
+ *
+ * The node object is extended with a 'translation_change' array containing
+ * both the old and new tnid.
+ *
+ * @param $node
+ *   The node being acted upon.
+ */
+function hook_nodeapi_translation_change($node) {
+  db_query('UPDATE {my_table} SET my_tnid = :new_tnid WHERE my_tnid = :old_tnid', array(':new_tnid' => $node->translation_change['new_tnid'], ':old_tnid' => $node->['translation_change['old_tnid']));
+}
Index: modules/translation/translation.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/translation/translation.module,v
retrieving revision 1.37
diff -u -p -r1.37 translation.module
--- modules/translation/translation.module	16 Dec 2008 22:05:51 -0000	1.37
+++ modules/translation/translation.module	20 Jan 2009 23:46:20 -0000
@@ -262,7 +262,16 @@ function translation_remove_from_set($no
   if (isset($node->tnid)) {
     if (db_result(db_query('SELECT COUNT(*) FROM {node} WHERE tnid = %d', $node->tnid)) == 1) {
       // There is only one node left in the set: remove the set altogether.
+      $node->translation_change = array(
+        'old_tnid' => $node->tnid,
+        'new_tnid' => 0,
+        // Determine the remaining former member of the translation set.
+        // May be needed e.g. to reassign existing data from the tnid to this nid.
+        'remaining_nid' => db_result(db_query('SELECT nid FROM {node} WHERE tnid = %d', $node->tnid)),
+      );
       db_query('UPDATE {node} SET tnid = 0, translate = 0 WHERE tnid = %d', $node->tnid);
+      // Allow other modules to respond to the removal of this translation set.
+      node_invoke_nodeapi($node, 'translation_change');
     }
     else {
       db_query('UPDATE {node} SET tnid = 0, translate = 0 WHERE nid = %d', $node->nid);
@@ -270,8 +279,13 @@ function translation_remove_from_set($no
       // If the node being removed was the source of the translation set,
       // we pick a new source - preferably one that is up to date.
       if ($node->tnid == $node->nid) {
-        $new_tnid = db_result(db_query('SELECT nid FROM {node} WHERE tnid = %d ORDER BY translate ASC, nid ASC', $node->tnid));
-        db_query('UPDATE {node} SET tnid = %d WHERE tnid = %d', $new_tnid, $node->tnid);
+        $node->translation_change = array(
+          'old_tnid' => $node->tnid,
+          'new_tnid' => db_result(db_query('SELECT nid FROM {node} WHERE tnid = %d ORDER BY translate ASC, nid ASC', $node->tnid)),
+        );
+        db_query('UPDATE {node} SET tnid = %d WHERE tnid = %d', $node->translation_change['new_tnid'], $node->tnid);
+        // Allow other modules to respond to the changed source for this translation set.
+        node_invoke_nodeapi($node, 'translation_change');
       }
     }
   }
Index: modules/translation/translation.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/translation/translation.test,v
retrieving revision 1.7
diff -u -p -r1.7 translation.test
--- modules/translation/translation.test	30 Dec 2008 16:43:19 -0000	1.7
+++ modules/translation/translation.test	20 Jan 2009 23:46:20 -0000
@@ -1,6 +1,9 @@
 <?php
 // $Id: translation.test,v 1.7 2008/12/30 16:43:19 dries Exp $
 
+/**
+ * Tests for translation module.
+ */
 class TranslationTestCase extends DrupalWebTestCase {
   protected $book;
 
@@ -13,7 +16,7 @@ class TranslationTestCase extends Drupal
   }
 
   function setUp() {
-    parent::setUp('locale', 'translation');
+    parent::setUp('locale', 'translation', 'translation_test');
   }
 
   /**
@@ -22,7 +25,7 @@ class TranslationTestCase extends Drupal
   function testContentTranslation() {
     // Setup users.
     $admin_user = $this->drupalCreateUser(array('administer languages', 'administer content types', 'access administration pages'));
-    $translator = $this->drupalCreateUser(array('create page content', 'edit own page content', 'translate content'));
+    $translator = $this->drupalCreateUser(array('create page content', 'edit own page content', 'delete own page content', 'translate content'));
 
     $this->drupalLogin($admin_user);
 
@@ -67,6 +70,15 @@ class TranslationTestCase extends Drupal
     $edit['translation[status]'] = FALSE;
     $this->drupalPost('node/' . $node_translation->nid . '/edit', $edit, t('Save'));
     $this->assertRaw(t('Page %title has been updated.', array('%title' => $node_translation_title)), t('Translated node updated.'));
+
+    // Delete the source node.
+    $this->drupalPost('node/' . $node->nid . '/edit', array(), t('Delete'));
+    $this->drupalPost(NULL, array(), t('Delete'));
+
+    // Assert that hook_translation_change() was called.
+    $this->assertEqual(variable_get('translation_change_called', ''), $node->nid, t('hook_nodeapi_translation_change() was called.'));
+
+
   }
 
   /**
