Render custom twig in a specific language I need to specify the language,
which the drupal renderer uses,
when generating a custom render array.

$renderArray = [
    "#theme" =&gt; "DNMBE_email",
    "#body" =&gt; [
        "#theme" =&gt; "DNMBE_emailBody_groupMessage",
        "#author" =&gt; $groupMessage-&gt;author,
        "#group" =&gt; $groupMessage-&gt;group,
        "#message" =&gt; $groupMessage-&gt;message,
    ],
    "#leadin" =&gt; $partials-&gt;leadin,
    "#leadout" =&gt; $partials-&gt;leadout,
];

$render = \Drupal
    ::service('renderer')
    -&gt;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()-&gt;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.
Currently, the only working way seems to be by passing local context - including a langcode in the render array and using |t([], {'langcode': 'XX'}) resp. {% trans with {'langcode': 'XX'} %} as mentioned in https://www.drupal.org/project/drupal/issues/2049241