I need to specify the language, which the drupal renderer uses, when generating a custom render array.
$renderArray = [
"#theme" => "DNMBE_email",
"#body" => [
"#theme" => "DNMBE_emailBody_groupMessage",
"#author" => $groupMessage->author,
"#group" => $groupMessage->group,
"#message" => $groupMessage->message,
],
"#leadin" => $partials->leadin,
"#leadout" => $partials->leadout,
];
$render = \Drupal
::service('renderer')
->renderRoot($renderArray);
$html = (string)$render;
#theme parameters resolve to twigs, which, among other things, contain {{ "From"|t }}
markup which is incorrectly rendered as From
.
I already posted a similar question, which was marked as duplicate, with the answer suggesting using \Drupal::languageManager()->setConfigOverrideLanguage($language)
. I do not get the expected result.
When using the t()
function, you can supply as third parameter an array, which can be used to specify the language. The renderer however does not take extra parameters, thus also not passing it to twig.
I verified that /admin/config/regional/translate has got the translated string, case-sensitive. I also use ['#cache']['max-age'] = 0
and I don't "precalc"-store any Drupal objects.