# 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: contributions/modules/nat/nat.module
--- contributions/modules/nat/nat.module Base (1.35)
+++ contributions/modules/nat/nat.module Locally Modified (Based On 1.35)
@@ -85,30 +85,22 @@
  */
 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;
   }
-
   switch ($op) {
     case 'load':
       $node->nat = nat_get_terms($node->nid);
       break;
     case 'insert':
-      $body = $node->body;
-      // Copying over the node body is optional.
-      $body = isset($nat_config['body'][$node->type]) ? $body : '';
-
       // Add node title as terms.
-      $terms = _nat_add_terms($nat_config['types'][$node->type], $node->title, $body, $node->taxonomy, $node->nat['related'], $node->nat['synonyms']);
-
+      $terms = _nat_add_terms($node);
       // Save node-term association in the NAT table.
       _nat_save_association($node->nid, $terms);
       break;
     case 'update':
-      $body = $node->body;
       // Copying over the node body is optional.
-      $body = isset($nat_config['body'][$node->type]) ? $body : '';
-
+      $body = isset($nat_config['body'][$node->type]) ? $node->body : '';
       // Update node title in term(s).
       $terms = nat_get_terms($node->nid);
       _nat_update_terms($terms, $node->title, $body, $node->taxonomy, $node->nat['related'], $node->nat['synonyms']);
@@ -567,41 +559,65 @@
  * @return $tids
  *   An array of term objects.
  */
-function _nat_add_terms($vids, $title, $body, $hierarchy = array(), $relations = array(), $synonyms = NULL) {
+function _nat_add_terms($node) {
+
+  $nat_config = _nat_variable_get();
+
   $edit = array(
-    'name' => $title,
-    'description' => $body,
-    'weight' => 0
+    'name' => $node->title,
+    'description' => isset($nat_config['body'][$node->type]) ? $node->body : '',
+    'weight' => 0,
+    'synonyms' => $node->nat['synonyms'] ? $node->nat['synonyms'] : NULL,
   );
 
-  if (!empty($synonyms)) {
-    $edit['synonyms'] = $synonyms;
-  }
-
   $tids = array();
-
+  $vids = $nat_config['types'][$node->type];
   foreach ($vids as $vid) {
-    // $edit is passed by reference and 'tid' is set with the tid of the new
-    // term.
-    unset($edit['tid']);
 
     $edit['vid'] = $vid;
+
     // 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];
     }
     else {
       $edit['parent'] = array();
     }
 
-    if (count($relations)) {
-      $edit['relations'] = $relations[$vid];
+    if (count($node->nat['related'])) {
+      $edit['relations'] = $node->nat['related'][$vid];
     }
 
+    if(module_exists('i18ntaxonomy')) {
+    // Multilanguage behavior.
+    //$vocabulry = taxonomy_vocabulary_load($vid);
+      switch(i18ntaxonomy_vocabulary($vid)) {
+        case I18N_TAXONOMY_LOCALIZE:
+        case I18N_TAXONOMY_LANGUAGE:
+          $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);
-    $tids[] = $edit;
+          break;
   }
+    }
+    else {
+    // No i18n module always means one node one term.
+      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;
 }
 
