The content in this example being a node, we’ll use the node namespace :
use Drupal\node\Entity\Node;
$nid = 10; //id of the node
$node = Node::load($nid);
$node_trans = $node->addTranslation("FR");
//FR being ISO lang code for French
$node_trans->title = "Le titre";
$node_trans->body = [
'value' => "<p>Une paragraphe</p>",
'format' => "full_html",
];
$node_trans->status = 1; //Publication status Boolean
//Metatag field needs to be serialized
$node_trans->field_metatag = serialize([
'title' => "Titre Metatag",
'description' => "Desc",
]);
$node->save();
Please follow and like us: