3

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?

2 Answers 2

2

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.

4
  • 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
    Commented Aug 9, 2016 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
    Commented Aug 10, 2016 at 6:00
  • is it applicable to search page, search/node/help?
    – developer
    Commented Sep 13, 2017 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. Commented Jan 22, 2018 at 11:25
1

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 and acknowledge you have read our privacy policy.

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