1

I have a website in English.

I need to put all the nodes of all contentypes into another language so that the client is only responsible for entering and modifying data.

I know how to go through the nodes, I know how to create a translation of a node but I do not know how to duplicate all the fields of a node in the translation.

How could I do it?

With this code i create a translation from a node

$node = \Drupal\node\Entity\Node::load($value_rowToTranslate->nid->value);

$translation = $node->addTranslation('es');
$translation->title = "Titulo traducido";
$translation->field_1 = "dasdas"
$translation->field_2 = "xxxxxxxxx"
...
$translation->field_N = "xxxxxxxxx"

$translation->save();
Javier
  • 395
  • 3
  • 18

1 Answers1

2

Question has been answered here : https://drupal.stackexchange.com/questions/270121/create-translated-node-programmatically

$node->addTranslation('de', $node->toArray());
Mistraƫ
  • 338
  • 5
  • 21