slim-jwt-auth
slim-jwt-auth copied to clipboard
Translate error messages
Hi, Is it possible to modify (translate) the error messages that are generated, for example when not receiving a token?
Not directly, but you could use the error handler. Let's assume you have created a translating function translate_error($locale, $message)
then the error handler would be something like:
$app = new Slim\App;
$app->add(new Tuupola\Middleware\JwtAuthentication([
"secret" => "supersecretkeyyoushouldnotcommittogithub",
"error" => function ($response, $arguments) {
$data["status"] = "error";
$data["message"] = translate_error("et_EE", $arguments["message"]);
return $response
->withHeader("Content-Type", "application/json")
->getBody()->write(json_encode($data, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
}
]));
Problem with translating the message, is that when the message in english changes, there will be no translation and the developer will not know. When a token expires Firebase\JW\ExpiredException is thrown. From a user(other developer)-view would it not be better to be able to catch the Firebase\JW\ExpiredException instead of handling the "error"-function( "error" => function ($response, $arguments) { ... } )?
I have been using your library for a few years now and I want to thank you for the effort and functionality btw.