There are already a bunch of issues regarding nodereference and multilanguage content here. Nevertheless I haven't seen any explanations for my specific case, nor found I the appropriate solution for the problem.

In #308188: Refactor nodereference to handle multilingual content? some good ideas were expressed, but after almost 2 years they are still only words and nothing more.

So, my situation is following:
1. I have 2 content types, say, Company and Product.
2. Product has a nodereference field Company
3. I use 2 languages, say, English and Russian. Both Companies and Products could be translated. Interface language could be switched as well.
4. I like the idea that nodereference is actually a link between entities, ie between translation sets and not language versions. Therefore Company field of Product always holds nid of original lang version of the node (= tnid).
5. When viewing Product node, Company nodereference field is displayed as title (company name) with link to company node (ie default format).

That said, let's look at a sample use case. I have:

Company1 with 2 translations: EN_Company1 (original) and RU_Company1
Product1 with 2 translations: EN_Product1 (original) and RU_Product1

Product1 has a reference to Company1, and considering #4 above, it's actually a reference to EN_Company1.

Now I view Product1 in Russian, and here comes a problem: I get EN_Company1 as my company reference,

Desired behaviour: I suppose, when my current language is Russian, I should get Russian version of referenced node (ie RU_Company1), if exists, Furthermore, even if Product1 is untranslated, ie we're viewing EN_Product1 node but in Russian interface, we should get RU_Company1 as a company. In other words, I think we should take current language into account and not language of parent node.

For now, I've come up with a little hack to achieve this behaviour. In nodereference.module, I've created a following function:


function nodereference_formatter_preprocess(&$element) {
    global $language;.
    $lang = $language->language;.
    $translations = translation_node_get_translations($element['#item']['safe']['nid']);

     if (isset($translations[$lang])) {
        $element['#item']['safe']['nid'] = $translations[$lang] -> nid;
        $element['#item']['safe']['title'] = $translations[$lang] -> title;
    }
}
 

and call it in default formatter:


function theme_nodereference_formatter_default($element) {
  $output = '';
  if (!empty($element['#item']['safe']['nid'])) {
    // get appropriate translation here
    nodereference_formatter_preprocess($element);
   ...
 

I'm aware that this solution is neither elegant nor universal. but it did the trick for me. Maybe it will help someone else struggling with the same problem.

Anyway, I wonder, how it could be done in a better way and are there any plans to solve this problem in future versions of CCK?

Comments

patrick2000’s picture

Hi

I had a similar problem. I've got the content types "page", which has multilanguage support and "pictures", which is language neutral. In "pictures" i've got (some imagefields and) a nodereference field to choose a node where the pictures should appear. Now when I translate a "page", that some "pictures" node is referencing, the pictures only show up on the original language (source) "node".

My solution to make the pictures appear on the translated nodes as well, was to change my "pictures_view" block display that displays the images.

My "pictures_view" block display used to have the "nodereference_field" of the "pictures" node type as an argument and the "pictures_imagefield" as fields to display. The block is then added to the theme and shows up only on pages referenced by the corresponding "nodereference_field".

(Well ... it's not easy. This took me roughly a day to figure out:)

To make the pictures appear on translated nodes as well, I changed the "pictures_view"s configureation. Instead of "Content: nodereference_field", I am now using a simple "Node: Nid", using a relation: "Node translation: Translations". And i choose "Translation options": "All" from the dropdown menu when creating it. This relation is again using a relation: "Content: nodereference_field" provided by the cck "node reference" module. So the "Node: Nid" is in effect using two, stacked relations in the end.

You have set up the relationships and arguments in the reverse order then described above: 1. "Content: nodereference_field" relation; 2. "Node translation: Translations" relation; 3. "Node: Nid" argument (whit "Action to take if not present": "Provide default argument" => "Node ID from URL").

And that way it works as i want it to - no php code, just some db config. But, it's not trivial. Maybe you can adopt this tactic for your case as well.

Have fun with "Relationships" !

lolandese’s picture

@ #1: Wow! I honestly think I couldn't have figured out this one myself. Thanks for sharing.

I noticed when creating new content through the Referenceable node links (see Content Type field settings), one has do it from the original content to show up in the View. Not from a translation. But this is only a minor issue.

zibretni’s picture

Thank you for sharing !

palamida’s picture

I have one question...
it seems that doing this way the view block contains all pictures with reference to certain page.
Can you tell me if it is possible to display pictures with "Language neutral" and pictures with the "Page language" but hiding those pictures with some other language slected ?

thanks
regards

marko

henno.gous’s picture

Did you guys ever figure out why node references need to be made from the original node and not from the translations? All my references are working fine in views with the use of references, but only for references between the original nodes.

When I go to a translation of the referencing node, I can see the translated version of the referencable node as an option to pick in the node reference field. But if I pick it, it comes up empty in my views...

Weird.

shreeni2’s picture

Hey Thanks patrick2000,

It is really useful for me. :)