Creates a translation duplicate of the given entity.
\Drupal\Core\Entity\ContentEntityInterface $target_entity: The target entity to clone.
string $langcode: Language code for all the clone entities created.
\Drupal\Core\Entity\ContentEntityInterface New entity object with the data from the original entity. Not saved. No sub-entities are cloned.
protected function createTranslationDuplicate(ContentEntityInterface $target_entity, $langcode) {
$duplicate = $target_entity
->createDuplicate();
// Change the original language.
if ($duplicate
->getEntityType()
->hasKey('langcode')) {
$duplicate
->set($duplicate
->getEntityType()
->getKey('langcode'), $langcode);
}
return $duplicate;
}