Home » Php » php – How to translation "Invalid credentials." error in FOSUserBundle symfony

php – How to translation "Invalid credentials." error in FOSUserBundle symfony

Posted by: admin July 12, 2020 Leave a comment

Questions:

I have this part of code in login.html.twig page

I want to translate error message “Invalid credentials.”

 {% if error %}
     <div style="color:red">
         {{ error.messageKey|trans(error.messageData, 'security') }}
     </div>
 {% endif %}

now, i’m trying to translat in messages.en.yml or in FOSUserBundle.en.yml and nothing happen. (using symfony3)

How to&Answers:

After looking for a while, I found it can help

I looked for where the message came fromץץ
and i found that this message “Invalid credentials.” coming from this path.

vendor\symfony\symfony\src\Symfony\Component\Security\Core\Resources\translations\security.en.xlf

so i copeid the file security.en.xlf into app\Resources\translations
and made some change to the part i wanted to translate

<trans-unit id="4">
    <source>Invalid credentials.</source>
    <target>Username/password doesn't match</target>
</trans-unit>

Answer:

Btw, in my case, I just uncomment the following line in config.yml :

framework:
    translator: { fallbacks: ['%locale%'] }

And my locale was set to “fr”

parameters:
    locale: fr