silexphp / Silex

[DEPRECATED -- Use Symfony instead] The PHP micro-framework based on the Symfony Components
https://silex.symfony.com
MIT License
3.58k stars 719 forks source link

Last security error is not translated #1620

Closed hkdobrev closed 6 years ago

hkdobrev commented 6 years ago

Found this question on StackOverflow: Silex, how to translate login error messages?

Looking the code it seems indeed the error message is not being translated:

https://github.com/silexphp/Silex/blob/e41379abc3e943fd5ff08e65158decca7af5748d/src/Silex/Provider/SecurityServiceProvider.php#L415-L429

Should we translate it if the translator is registered in the 'security.last_error' callback or should we expose the AuthenticationUtils class in the controllers like Symfony? I don't see translation of the message there as well.

Any pointers?

stof commented 6 years ago

The right solution is to expose AuthenticationUtils IMO.

$app['security.last_error'] exposes the message of the last error instead of the AuthenticationException object, which indeed does not give access to the translation key suited for user display.

hkdobrev commented 6 years ago

Got it. I didn't realise the AuthenticationUtils class is actually returning an AuthenticationException instance.

hkdobrev commented 6 years ago

I'll try to tackle that in the next couple of days :) Seems like an easy fix now.