I have defined a route as follow:
mymodule.node_summary:
path: '/node/{node}/summary'
options:
parameters:
node:
type: 'entity:node'
defaults:
_controller: '\Drupal\mymodule\Controller\NodeSummaryController::content'
_title: 'Summary'
requirements:
node: \d+
_entity_access: 'node.view'
Then I have created the following controller:
class NodeSummaryController {
public function content(Node $node = NULL) {
$view_builder = Drupal::entityTypeManager()
->getViewBuilder('node');
$summary = $view_builder->view($node, 'summary');
$render = Drupal::service('renderer')
->renderPlain($summary);
$response = new Response($render);
return $response;
}
}
If I visit the page /nl/node/xxx/summary
everything is fine, my node's summary is displayed in dutch
But if I try to get this content with a sub-request, I get the result in the default language of my site, not in dutch
$kernel = \Drupal::service('http_kernel.basic');
$sub_request = \Symfony\Component\HttpFoundation\Request::create("/nl/node/xxx/summary");
$response = $kernel->handle($sub_request, \Symfony\Component\HttpKernel\HttpKernelInterface::SUB_REQUEST);
$html = $response->getContent();
dpm($html); // ERROR THIS IS NOT IN DUTCH