Hi

this is a patch that allow to synchronize nodereference fields with the corresponding translations (if they exists).
info about patched module:

; $Id: i18nsync.info,v 1.1.2.3 2007/06/18 23:06:46 dww Exp $
name = Synchronization
description = Synchronizes content translations
dependencies = i18n translation
package = Multilanguage - i18n - experimental
; Information added by drupal.org packaging script on 2007-10-30
version = "5.x-2.2"
project = "i18n"
datestamp = "1193766006"

patch:

--- i18nsync.module.orig	2007-06-06 13:54:18.000000000 +0200
+++ i18nsync.module	2008-04-04 13:08:46.000000000 +0200
@@ -163,16 +163,46 @@ function i18nsync_node_translation($node
           }
         }
         break;
-      default: // For fields that don't need special handling
-        if (isset($node->$field)) {
-          $translation->$field = $node->$field;
-        }
+      default: // For other fields
+       if (isset($node->$field) && $_field = $node->$field) {
+         // For nodereference fields !IT'S RAW METHOD, MAY NEED REVIEW!
+         if (isset($_field[0]['nid']) && $_field[0]['nid'] != $node->nid ) {
+           i18nsync_node_translation_referenced_node(&$node, &$translation, $field);
+         } else {
+           // For fields that don't need special handling
+           $translation->$field = $node->$field;
+         }
+       }
     }
   }
   node_save($translation);
 }
 
 /**
+ * Node reference that may have translation
+ *
+ */
+function i18nsync_node_translation_referenced_node(&$node, &$translation, $field) {
+$translation->$field = array();
+  $_field = $node->$field;
+  foreach ($_field as $key=>$reference) {
+    if ($referenced = node_load($reference['nid'])) {
+      // This content type has translations, find the one
+      if (variable_get("i18n_node_$referenced->type", 0) && isset($referenced->translation[$translation->language])) {
+        array_push($translation->$field, array('nid'=>$referenced->translation[$translation->language]->nid));
+        drupal_set_message(t('%title referenced node has been synchronized to %language translation',array('%title'=>$referenced->title, '%language'=>$translation->language)));
+      } else {
+        // Reference without translation, just copy the nid
+        array_push($translation->$field, $_field[$key]);
+      }
+    } else {
+      // False reference nid, just copy the nid
+      array_push($translation->$field, $_field[$key]);
+    }
+  }
+}
+
+/**
  * Node attachments that may have translation
  * 
  */

I also give in attached files a bundled patch of this add-on + "automatic update path after synchronizing taxonomy" (see http://drupal.org/node/237546#comment-779300)

Tests and reviews are welcome!

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Jose Reyero’s picture

Status: Needs review » Needs work

This looks good. However I think we could reuse the code for attached nodes which is quite similar.

Also, to avoid future headaches, it should handle the case of cck fields with multiple values.

kharbat’s picture

Version: 5.x-2.2 » 6.x-1.0-beta4
Priority: Normal » Critical

is there a similar patch for drupal 6 ??

dasjo’s picture

Title: Try to translate node reference with i18nsync » translate node references with i18nsync
Version: 6.x-1.0-beta4 » 6.x-1.x-dev
Component: Experimental modules » Code
Priority: Critical » Normal
Status: Needs work » Needs review
FileSize
3.09 KB

nedjo and me worked on a solution for this issue regarding the translation of nodereferences in i18n, drupal 6

jose, so we followed your advice, reused the attached nodes sync code.

so we have a helper function i18nsync_node_translation_reference_field which is used by i18nsync_node_translation_attached_node and i18nsync_node_translation_nodereference_field

i attached the patch, it's actually my first one, so i hope it works fine ;)

dasjo’s picture

FileSize
3.75 KB

the same patch in cvs diff -up format

Jose Reyero’s picture

This one looks much better

Just need someone else to give it a try and tell me it works.

@nedjo, if you are around, feel free to commit.

Jose Reyero’s picture

Status: Needs review » Fixed

I'm thinking let's speed up the process.

As I've been committing some other improvements in that module, see changelog, I've also committed this one, so you don't need to update it again.

If this breaks anything, someone will let us know :-)

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Dubs’s picture

We have a CCK Node reference which referencing bi-lingual versions of a node. If we have a view which uses the node reference field as an exposed filter, then select a node and change language, then we get the following error: -

An illegal choice has been detected. Please contact the site administrator.

You can see the problem at http://plwm.nmaltd.com/events/gallery

Just pick an event from the dropdown (the node reference field) and then click "Cymraeg) in the top-right and the error should be displayed.

Is there anything that i18n can do about this, or does the problem lie outside the scope of this module?

GN’s picture

Status: Closed (fixed) » Active

i18nsynching of nodereferences seems to work only for already existing nodes, not for a fresh new translation before first saved. It looks like this:

  1. I create and save a cck node in Lang1, with a nodereference field containing some node references; this noderef field is configured as i18nsynched.
  2. I create a translation of this node into Lang2; while I'm editing it, no nodes appear selected in the noderef selection window - I need to redo the selection as I did for Lang1 node. If I don't, nodereference list is emptied for both nodes, Lang2 and Lang1.
  3. After the Lang2 node is already created and saved, changes in the noderef field are i18nsynched properly.

This behavior is similar to an imagefield issue #533228: i18nSynchronization of imagefields using image_fupload widget works only for existing nodes, not for fresh new translations.

orjantorang’s picture

Category: feature » bug
Priority: Normal » Critical

In my case a translation action gives no opportunity to check (I use checkboxes) any nodereferences, not even when I edit the new node.
I can see the title of the nodereference field but no form fields. In the database field content_field_... there is a NULL value stored. I changed this value
manually and in the view for the node I can now see the nodereferences, but still in edit I can't see any form fields.

I don't know the status of this project, but I have read #573548: Open i18nsync to modules (Open i18nsync to modules) and I think that is a good idea, but also a standard choice in in18n like http://drupal.org/project/node_clone, would be nice.

/Örjan

askibinski’s picture

subscribe

bibo’s picture

subscribe.

It still seems unclear to me how this should work in the current 1.5 i18nsync version. Apparently it syncs the referenrences' translations on some occasions, but generally it doesnt.

colan’s picture

Subscribing.

rp7’s picture

Subscribing, this is pretty critical...

varac’s picture

Version: 6.x-1.x-dev » 6.x-1.7

Subscribing, we have the same problem here (6.x-1.7) and think this is very important to fix !

blaiz’s picture

Actually this works for me. I'm synchronizing node references across translations. When I edit the English language one, and save, on the Italian translation, it will search for translated references and save the translated one, if not all referenced pages have been translated, then it will save the English ones instead, which is what I want.

Problem is, when I want to edit the Italian translation then, when I click on Save, it shows an error message stating "Name of the field: this post can't be referenced." for all the ones that reference English pages.And if I delete the English references here, since it's synchronized, it deletes them on the other languages as well.

Is there a way to override this? to force node reference to save even if some references link to another language?

jphil’s picture

This is really annoying and needs to be fixed ASAP....

Bartezz’s picture

+999

Subscribing

Seighaus’s picture

subscribing

zilverdistel’s picture

This is my situation:
- node type A refers to node type B (and vice versa).
- node type A is language neutral
- node type B can be Dutch (nl) or English (en).

When I save node of type A, I get the error

  Node type B: this post can't be referenced.

Saving a node of type B succeeds.

Cameron Tod’s picture

Is there a similar patch against 6.x-1.7?

stevenator’s picture

subscribing

screenage’s picture

subscribing

ducdebreme’s picture

subscribing

pedrosp’s picture

subscribing

zilverdistel’s picture

we fixed our problem by changing the content negotiation rules on admin/settings/language/i18n to "All content. No language conditions apply." This is just a temporary quickfix that works for us.

YK85’s picture

subscribing

Seighaus’s picture

My Problem (attach language neutral content to translatable content) was solved by this solution: http://drupal.org/node/855102#comment-3404492
Except I don't use a block but node attachment to attach my content.

I hope this helps some of you as well!

zeuty’s picture

Anything new on this issue?

shreeni2’s picture

Component: Code » Blocks

subscribing

slucas’s picture

I've lost some time to understand that this patch have been already applied to current version of i18nsync.
Furthermore to allow node reference of different language to be referenced in a node reference field use view and node language filter to achieve the result you want.
Select the view you've just done in the node reference field settings to select appropriate nodes.
This was quite challenging for me to understand this.
So I write it down here to give clue to others.

bvanmeurs’s picture

joseph.olstad’s picture

Status: Active » Closed (outdated)