// 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>'
]);
$string_storage->
createTranslation([ 'lid' =>
$source->lid,
'language' => 'es',
'translation' => 'Funciona con ...',
])->
save();
// Invalidate caches so that the new translation will be used.
Cache::
invalidateTags(['rendered', 'locale'
]);
} /**
* Tests translation with URL and Preferred Admin Language negotiators.
*
* The interface language uses the preferred language for admin pages of the
* user and after that the URL. The Content uses just the URL.
*/