I would like to display a node in NL. This node is not translatable but I would like to have the fields labels translated in NL.
This rendering occurs in a cron job and is used to render an email in the recipient language (ex: NL).
Unfortunately, the following code output the labels in the current language of the page (if I run it outside the cron) or in the default language of the site from within the cron job
$entity = Drupal\node\Entity\Node::load($nid);
$view_builder = Drupal::entityTypeManager()->getViewBuilder($entity->getEntityTypeId());
$summary = $view_builder->view($entity, 'summary', 'nl');
$render=Drupal::service('renderer')
->renderPlain($summary);
dpm($render);
Solutions I have already tested:
1-I have tried the solution which set the config override language to the desired language here without luck
2-I have also tried the solution which set a custom language negotiator here without success
3-Finally I have tried the solution which use the 'language' session parameter here without any result
I have traced the code and I think that the language is selected/choose in the render part... But it was really difficult to understand this due to the complexity.
I was also thinking to add a '#langcode'
to the build but I couldn't find an example.