1

I have many articles in original (English) language and they're all translated to 3 languages - however, the translations were created as new nodes (and not by clicking "Add translation" in the Translation tab).

Is it possible to somehow relate the translations with the original English article or do I have to manually redo it all by clicking "Add translation" in the Translate tab of each node and adding the translations?

1

You can do this in code by reading the field values from the three translated nodes and add them as translation to the english node:

$node_en->addTranslation($langcode1, $node1->toArray());
$node_en->addTranslation($langcode2, $node2->toArray());
$node_en->addTranslation($langcode3, $node3->toArray());
$node_en->save();

This is for demonstration only, you can loop through the languages and get the langcode from the node.

The problem is that at the moment the translated nodes and the english node have no connection in the database. If you have some data in the nodes that do match, you can do a entity query and loop through the results.

  • As you said, that doesn't connect anything, it actually duplicates all data. But I'd still say that's the only viable approach right now and additionally, I would just delete the original separate nodes after merging them like this. Then you don't have to worry about disconnect. The ID's will then of course change, so if you have references, you need to map them somehow. – Berdir Aug 9 '16 at 19:44
  • So, if I'm not a programmer, I have to do this manually, there's no clickable interface to do this, right? – Ondrej Aug 10 '16 at 6:00
  • is it applicable to search page, search/node/help? – developer Sep 13 '17 at 14:00
  • I have the following error when method save() is executed "Invalid translation language (und) specified. in Drupal\Core\Entity\ContentEntityBase->getTranslation()", do you have an idea ? Of course, I event tried to hardcore 'en' in addTranslation() method. – Pauloscorps Jan 22 '18 at 11:25
0

I created module to add this functionality. https://www.drupal.org/sandbox/lamp5/2956687

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.