How to create a multilingual node programmatically? In the last days I tried to migrate a multilingual CSV file to Drupal 8 without success, so finally I decided to use a Batch Process to accomplish the task.

At this moment I have the batch process working, but at this point I need to create my nodes and create the translation. So, how to create a multilingual node programmatically?
Fortunately I found a post named Create and translate a multilingual nodes programmatically.

And here is the code with some comments:

use Drupal\node\Entity\Node;

$node = Node::create([
  // The node entity bundle in this case article.
  'type' =&gt; 'article',
  //The base language
  'langcode' =&gt; 'en',
  'created' =&gt; \Drupal::time()-&gt;getRequestTime(),
  'changed' =&gt; \Drupal::time()-&gt;getRequestTime(),
  // The user ID.
  'uid' =&gt; 1,
  'title' =&gt; 'My test!',
  //If you have another field lets says field_day you can do this:
  //'field_day' =&gt; 'value',
  'body' =&gt; [
    'summary' =&gt; '',
    'value' =&gt; '&lt;p&gt;The body of my node.&lt;/p&gt;',
    'format' =&gt; 'full_html',
  ],
]);
//Saving the node
$node-&gt;save();
//This line is not necessary
\Drupal::service('path.alias_storage')-&gt;save("/node/" . $node-&gt;id(), "/my/path", "en");

//Creating the translation Spanish in this case
$node_es = $node-&gt;addTranslation('es');
$node_es-&gt;title = 'Mi prueba!';
$node_es-&gt;body-&gt;value = '&lt;p&gt;El cuerpo de mi nodo.&lt;/p&gt;';
$node_es-&gt;body-&gt;format = 'full_html';
//Saving the node
$node_es-&gt;save();
//This line is not necessary
\Drupal::service('path.alias_storage')-&gt;save("/node/" . $node-&gt;id(), "/mi/ruta", "es");