Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to translate Symfony2 Exception

I'm using yml format to translate my web app but I've one problem.

What I would like to do:

#exception.en.yml
exception.bad: 'Bad credentials'

What I know is possible to do:

#exception.en.yml
'Bad credentials': 'Bad credentials'

Is this the only method to translate the exception?

like image 318
Matteo Martinelli Avatar asked Oct 26 '14 15:10

Matteo Martinelli


1 Answers

simply put in the translator and remember to add the trans statement on the messagge error dump in the Twig template.

Here an xliff example:

    messages.en.xlf

        <trans-unit id="1">
            <source>User account is disabled.</source>
            <target>Account disabled or waiting for confirm</target>
        </trans-unit>
        <trans-unit id="2">
            <source>Bad credentials</source>
            <target>Wrong username or password</target>
        </trans-unit>

and in the template

{# src/Acme/SecurityBundle/Resources/views/Security/login.html.twig #}
{% if error %}
    <div>{{ error.message|trans }}</div>
{% endif %}

<form action="{{ path('login_check') }}" method="post">
    <label for="username">Username:</label>
    <input type="text" id="username" name="_username" value="{{ last_username }}" />

    <label for="password">Password:</label>
    <input type="password" id="password" name="_password" />

    <button type="submit">login</button>
</form>

Check this doc for exclude non active users

hope this help

like image 180
Matteo Avatar answered Oct 15 '22 18:10

Matteo