Recommended way to translate authentication errors to symfony2

I need to display, for example, the message "Bad credentials" in another language. So far, I have found that it is selected as an exception in
\vendor\symfony\src\Symfony\Component\Security\Core\Authentication\Provider\UserAuthenticationProvider.php
authenticate as a function throw new BadCredentialsException('Bad credentials', 0, $notFound);

I am wondering what would be the recommended way to display this message in another language. Just changing the line at this point seems not optimal ... There are also other messages that may be shown during authentication.

I use JMSSecurityExtraBundle and FOSUserBundle , and I assume there may be some built-in functions to handle this ...?

0
authentication internationalization symfony
source share
1 answer
  • Override login template: copy FOSUserBundle / Resources / views / Security / login.html.twig to application / Resources / views / Security / login.html.twig (see doc , video )

  • Add a trans filter to the error in login.html.twig (see doc ):

    {{error | trans}}

  • In your translation file src / YourBundlePath / Resources / translations / messages. {locale} .yml add:

    Invalid credentials: error text

+4
source share

All Articles