Translation of Exceptions
- tomcat4x
- Member | 22
Hi,
has anyone a solution for translate the thrown exeptions from Nette without changing the main classes.
For examle the SimpleAuthenticator Class is throwing a
AuthenticationException(‘Invalid password.’, self::INVALID_CREDENTIAL);
or
AuthenticationException(“User ‘$username’ not found.”, self::IDENTITY_NOT_FOUND);
I use Kdyby/Translation, but i find no solution für translate this Exception text to german with this extension.
regards Frank
- jiri.pudil
- Nette Blogger | 1014
Hello,
it's not a good practice to display exception messages to users; exceptions are part of a method's application interface, not user interface. You should catch them and display your own message based on the exception's code. Translating it will be easy this way.
- matopeto
- Member | 395
Hmm.. Something like that? (writen by hand, bud i think idea is clear)
try {
// authentication
// $userName, $password...
} catch (AuthenticationException $ex) {
if ($ex->getCode() === IAuthenticator::IDENTITY_NOT_FOUND) {
$messaget = $translator->translate("user.not.found", $userName);
}
}
- Whory1946
- Member | 1
matopeto thanks a lot. it's indeed very helpful and understandable. i don't have the time and i can't even concentrate right now, all because i need to search for online pharmacy because of my health issues. so i was thinking that i could get some help online and i did thanks to you. thanks a lot for everything. might i come back asking you some other questions if i would have any? thanks!
Last edited by Whory1946 (2017-11-27 19:04)
- zonbin
- Member | 1
matopeto wrote:
Hmm.. Something l that? (writen by hand, bud i thi idea is clear)
try { // authentication // $userName, $password... } catch (AuthenticationException $ex) { if ($ex->getCode() === IAuthenticator::IDENTITY_NOT_FOUND) { $messaget = $translator->translate("user.not.found", $userName); } }
Thank you so much