Translation of Exceptions

about a year ago

tomcat4x
Member | 22
+
0
-

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

about a year ago

jiri.pudil
Member | 833
+
+5
-

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.

about a year ago

matopeto
Member | 400
+
+4
-

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);
 }
}

about a year ago

Whory1946
Member | 1
+
0
-

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)

12 days ago

zonbin
Member | 1
+
0
-

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