Translate login form error message

I am using the FOSUserBundle login form and I would like to translate error messages. These messages run here: vendor / symfony / src / Symfony / Component / Security / Core / Authentication / Provider / DaoAuthenticationProvider.php

protected function checkAuthentication(UserInterface $user, UsernamePasswordToken $token) { $currentUser = $token->getUser(); if ($currentUser instanceof UserInterface) { if ($currentUser->getPassword() !== $user->getPassword()) { throw new BadCredentialsException('The credentials were changed from another session.'); } } else { if (!$presentedPassword = $token->getCredentials()) { throw new BadCredentialsException('The presented password cannot be empty.'); } if (!$this->encoderFactory->getEncoder($user)->isPasswordValid($user->getPassword(), $presentedPassword, $user->getSalt())) { throw new BadCredentialsException('The presented password is invalid.'); } } } 

I am writing an application /Resources/translations/validators.fr.yml

 "The presented password cannot be empty.": "Veuillez saisir un mot de passe." 

I am writing an application /Resources/translations/messages.fr.yml

 "The presented password cannot be empty.": "Veuillez saisir un mot de passe." 

But that will not work. Another translation works (=> fr), but I have a problem with these messages.

Special procedure for these messages?

+1
symfony translation
source share
3 answers

In the file Sonata / UserBundle / Resources / views / Admin / Security / login.html.twig you have:

 <div class="alert-message error">{{ error|trans({}, 'SonataUserBundle') }}</div> 

therefore, you must change SonataUserBundle to any translation file that you use or add SRC / Your / Bundle / Resources / Translations / SonataUserBundle. {} locale .yml

and inside the translation file:

 'Bad credentials': 'Your translation' 'The presented password is invalid.': 'Your translation' 'The presented password cannot be empty.': 'Your translation' 

I hope this is clear enough;]

+7
source share

In version 1.3 of the FOSUserBundle, “Bad Credentials” are actually “Bad Credentials”. (remember the last point).

+2
source share

I do not think so. You must catch the error and do what you need to do ... For example, display a message with a message about the flash session and redirect it to the forgotten password page.

0
source share

All Articles