// Create a Node with title 'English' and translate it to Spanish.
$node = Node::
create([ 'type' => 'page',
'title' => 'English',
]);
$node->
save();
$node->
addTranslation('es',
['title' => 'EspaƱol'
]);
$node->
save();
// Enable both language_interface and language_content language negotiation.
\Drupal::
getContainer()->
get('language_negotiator'
)->
updateConfiguration([ 'language_interface',
'language_content',
]);
// Set the preferred language of the user for admin pages to English.
$user->
set('preferred_admin_langcode', 'en'
)->
save();
// Make sure node edit pages are administration pages.
$this->
config('node.settings'
)->
set('use_admin_theme', '1'
)->
save();
$this->container->
get('router.builder'
)->
rebuild();