The comment above i18n_sync_node_translation_reference_field() describes:

/**
 * Helper function to which translates reference field. We try to use translations for reference, otherwise fallback.
 * Example:
 *   English A references English B and English C.
 *   English A and B are translated to German A and B, but English C is not.
 *   The syncronization from English A to German A would it German B and English C.
 */

This is exactly what I want to happen, but this functions is never invoked. I'm using node reference fields from the Reference module. Do I have wrong fields?

CommentFileSizeAuthor
#2 i18n_references.tar_.gz589 bytesC. Lee

Comments

C. Lee’s picture

C. Lee’s picture

StatusFileSize
new589 bytes

The workaround is implementing hooks:

/**
 * Implements hook_field_info_alter().
 */
function i18n_references_field_info_alter(&$fields) {
  if (isset($fields['node_reference'])) {
    $fields['node_reference']['i18n_sync_callback'] = '_i18n_references_field_node_reference_sync';
  }
}

/**
 * Implements _i18n_references_field_node_reference_sync().
 */
function _i18n_references_field_node_reference_sync($entity_type, $entity, $field, $instance, $langcode, &$items, $source_entity, $source_language) {
  foreach ($items as $delta => &$reference) {
    if ($reference_node = node_load($reference['nid'])) {
      $reference['nid'] = i18n_sync_node_translation_reference_field($reference_node, $reference['nid'], $langcode);
    }
  }
}
webflo’s picture

Issue tags: +i18n compatibility

Tagging with i18n compatibility.

netsensei’s picture

You actually don't need to create a separate module with you own i18n_sync_callback implementation:

i18n_sync.module should implement this:

function i18n_sync_field_info_alter(&$fields) {
  if (isset($fields['node_reference'])) {
    $fields['node_reference']['i18n_sync_callback'] = 'node_reference_field_prepare_translation';
  }
}

And the references module needs the patch from #1046234: node reference issue with content translation

Done!

ThomasColliers’s picture

Thank you C. Lee, your workaround module works like a charm.

aacraig’s picture

Until i18n_sync actually implements the change mentioned in #4, you still need to create a separate module, unless you want to modify i18n_sync on your own.

#2 works great. Download and enable and you're done.

husumiao-1’s picture

The solution for #2 is perfect worked. Maybe you can also merge the code to i18n_sync module.
But why i still found it's doesn't fixed on 7.x-1.x-dev version for i18n(It's updated on date 2012-Mar-22). Nobody hand up this issue?
In short, Thanks to C. Lee.

drupalok’s picture

does this work for Drupal 6 too?

jose reyero’s picture

Title: i18n sync does not use translations for references » i18n sync does not use translations for references (New i18n contrib module)
Category: bug » feature
Priority: Normal » Major

This looks pretty good. However we don't want i18n, which is meant to be an API module and deals mainly with Drupal core issues to be plagued with dependencies on other contributed modules.

So I've created a new module and put the code (with some changes) there, see https://drupal.org/sandbox/reyero/1511088

@C. Lee,
If you wish to become a maintainer of that new module, just let me know.

About the 'node reference' code in i18n_sync, I think we should get rid of it as it doesn't do anything at all, right?
This new module implements the whole thing so we don't need anymore i18n_sync_node_translation_nodereference_field() and i18n_sync_node_translation_reference_field()

If this patch is eventually committed to references we may be able to reuse some of it too and make the module smaller, #1046234: node reference issue with content translation

jose reyero’s picture

Status: Active » Fixed

Please give a try to this new module, http://drupal.org/project/i18n_contrib

Status: Fixed » Closed (fixed)

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

finex’s picture

What about entity references? The suggested module (i18n_contrib) only works for node reference fields.

HakS’s picture

i18n_contrib now supports entity references in dev version.