// 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();
// Place a Block with a translatable string on the page.
$this->
placeBlock('system_powered_by_block',
['region' => 'content'
]);
// Load the Spanish Node page once, to register the translatable string.
$this->
drupalGet('/es/node/1'
);
// Translate the Powered by string.
/** @var \Drupal\locale\StringStorageInterface $string_storage */
$string_storage = \Drupal::
getContainer()->
get('locale.storage'
);
$source =
$string_storage->
findString(['source' => 'Powered by <a href=":poweredby">Drupal</a>'
]);