# This patch file was generated by NetBeans IDE
# This patch can be applied using context Tools: Apply Diff Patch action on respective folder.
# It uses platform neutral UTF-8 encoding.
# Above lines and this line are ignored by the patching process.
Index: nat/nat.module
--- nat/nat.module Base (1.34.2.18)
+++ nat/nat.module Locally Modified (Based On 1.34.2.18)
@@ -76,7 +76,7 @@
  */
 function nat_nodeapi(&$node, $op, $teaser, $page) {
   $nat_config = _nat_variable_get();
-  if (!isset($nat_config['types'][$node->type]) || empty($nat_config['types'][$node->type])) {
+  if (empty($nat_config['types'][$node->type])) {
     return;
   }
 
@@ -485,7 +485,8 @@
   $edit = array(
     'name' => $node->title,
     'description' => isset($nat_config['body'][$node->type]) ? $node->body : '',
-    'weight' => 0
+    'weight' => 0,
+    'synonyms' => $node->nat['synonyms'] ? $node->nat['synonyms'] : NULL,
   );
 
   $tids = array();
@@ -493,25 +494,50 @@
   $vids = empty($vids) ? $nat_config['types'][$node->type] : $vids;
 
   foreach ($vids as $vid) {
-    // $edit is passed by reference and 'tid' is set with the tid of the new
-    // term.
-    unset($edit['tid']);
-
+    // Reset data on start.
     $edit['vid'] = $vid;
+    $edit['parent'] = array();
+    $edit['relations'] = array();
+
     // Save hierarchy for vocabularies also present in the node form.
-    if (isset($hierarchy[$vid])) {
-      $edit['parent'] = $hierarchy[$vid];
+    if (isset($node->taxonomy[$vid])) {
+      $edit['parent'] = $node->taxonomy[$vid];
     }
+
+    if (count($node->nat['related'])) {
+      $edit['relations'] = $node->nat['related'][$vid];
+    }
+
+    if(module_exists('i18ntaxonomy')) {
+      // Multilingual behavior.
+      switch(i18ntaxonomy_vocabulary($vid)) {
+        case I18N_TAXONOMY_LOCALIZE:
+        case I18N_TAXONOMY_LANGUAGE:
+          // Use term of translation source node.
+          $term = nat_get_term($node->translation_source->nid, array($vid));
+          if($term->tid) {
+            $edit['tid'] = $term->tid;
+            break;
+          }
+        case I18N_TAXONOMY_NONE:
+        case I18N_TAXONOMY_TRANSLATE:
+        default:
+        // Seperate terms per node.
+          taxonomy_save_term($edit);
+          break;
+      }
+    }
     else {
-      $edit['parent'] = array();
+      // No i18n module always means one node one term.
+      taxonomy_save_term($edit);
     }
-    $edit['relations'] = isset($node->nat) && isset($node->nat['related'][$vid]) ? $node->nat['related'][$vid] : array();
-    $edit['synonyms'] = isset($node->nat) ? $node->nat['synonyms'] : '';
 
-    taxonomy_save_term($edit);
     $tids[] = $edit;
-  }
 
+    // taxonomy_save_term passes $edit by reference. So we need to unset the
+    // tid to reuse the data in the next run.
+    unset($edit['tid']);
+  }
   return $tids;
 }
 
@@ -539,6 +565,21 @@
     $edit['relations'] = isset($node->nat) && isset($node->nat['related'][$term->vid]) ? $node->nat['related'][$term->vid] : array();
     $edit['synonyms'] = isset($node->nat) ? $node->nat['synonyms'] : '';
 
+    if(module_exists('i18ntaxonomy')) {
+      // Multilingual behavior.
+      switch(i18ntaxonomy_vocabulary($term->vid)) {
+        case I18N_TAXONOMY_LOCALIZE:
+        case I18N_TAXONOMY_LANGUAGE:
+          // If not translation source return.
+          if($node->tnid !== $node->nid) {
+            return;
+          }
+        case I18N_TAXONOMY_NONE:
+        case I18N_TAXONOMY_TRANSLATE:
+        default:
+          break;
+      }
+    }
     taxonomy_save_term($edit);
   }
 }
