In a controller, I need to return translated message in an Ajax json response as:
$body['message'] = __("Duplicated");
$this->response->body(json_encode($body));
$this->response->statusCode(202);
$this->response->type('json');
return $this->response;
But the translation is not looked up. However, in a template, I am able to get this working:
<?= __("Duplicated");?>
I know I can use the Ajax layout and write a template, but in this case the message body is very short, I need to return a Status Code other than 200. How can I do this in a controller in CakePHP 3?