Solution for fundamental tnid issue in i18n

I started testing out Internationalization 7.x-1.5 the other day and soon noticed a big problem: When you select the local task "Translate" for a node and choose to create a new node as a translation, they aren't connected to each other! Neither the translate page for the source node nor for the translated node shows their relationship. Only by selecting the node in the autocomplete field at the translation page followed by clearing the cache was I able to create the relationship between them.

Troubleshooting this issue, I created a new node and then created a translation for it, also a new node. Then I took a look in the database, specifically the node table. It looked like this:

(Click for image)

Look at the tnid column. See the zero for the node with nid 3? That's the source node. Now, I started thinking. Back in D6, didn't the source node use to have its own nid as tnid? So I edited the row manually, like so:

(Click for image)

After clearing the cache, it worked. So, the problem is basically that when a new node is created, the tnid property isn't populated. After looking through node_save() I came up with a solution that works well. You just add a hook_node_insert() in i18n_node.module and check for the node's tnid. If there isn't any, you use the nid for it and save it to the database. Here's the code:

* Implements hook_node_insert().
function i18n_node_node_insert($node) {
  if(!$node->tnid) {
    $node->tnid = $node->nid;
    drupal_write_record('node', $node, 'nid');

A patch may be downloaded below, as usual. Apply it from the root folder of i18n.

Link to issue