I want to render a node display programmatically for sending it to a search engine. It works ok but is ignoring the language and renders the field labels in the source language (which is English).
I use the following code for creating the teaser markup.
$render_array_teaser = $view_builder->view($entity, 'compact_teaser', 'de'); $rendered_teaser = $renderer->renderPlain($render_array_teaser);
The result gives me a teaser that includes a field named "field_sku" that has the label "SKU number". If I output the teaser in the browser the label gets correctly translated to German = "Artikelnummer" if the current language is "German".
If I render the teaser with the above code the label stays English even if I set the langcode parameter to 'de'.
How to get the teaser with German lables?