Index: modules/translation/translation.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/translation/translation.module,v
retrieving revision 1.40
diff -u -p -r1.40 translation.module
--- modules/translation/translation.module	8 Mar 2009 04:25:07 -0000	1.40
+++ modules/translation/translation.module	9 Mar 2009 02:30:02 -0000
@@ -266,16 +266,47 @@ 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.
-      db_query('UPDATE {node} SET tnid = 0, translate = 0 WHERE tnid = %d', $node->tnid);
+      $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_query('SELECT nid FROM {node} WHERE tnid = :tnid', array(':tnid' => $node->tnid))->fetchField(),
+      );
+      db_update('node')
+        ->fields(array(
+          'tnid' => 0,
+          'translate' => 0,
+        ))
+        ->condition('tnid', $node->tnid, '=')
+        ->execute();
+      // Allow other modules to respond to the removal of this translation set.
+      node_invoke_node($node, 'translation_change');
     }
     else {
-      db_query('UPDATE {node} SET tnid = 0, translate = 0 WHERE nid = %d', $node->nid);
+      db_update('node')
+        ->fields(array(
+          'tnid' => 0,
+          'translate' => 0,
+        ))
+        ->condition('nid', $node->nid, '=')
+        ->execute();
 
       // 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_query('SELECT nid FROM {node} WHERE tnid = :tnid ORDER BY translate ASC, nid ASC', array(':tnid' => $node->tnid))->fetchField(),
+        );
+        db_update('node')
+          ->fields(array(
+            'tnid' => $node->translation_change['new_tnid'],
+          ))
+          ->condition('tnid', $node->tnid, '=')
+          ->execute();
+        // Allow other modules to respond to the changed source for this translation set.
+        node_invoke_node($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	9 Mar 2009 02:30:02 -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,13 @@ 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_node_translation_change() was called.'));
   }
 
   /**
