How to translate Symfony2 Exception

I am using the yml format to translate my web application, but I have one problem.

What I would like to do:

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

I know what can be done:

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

Is this the only method to throw an exception?

+4
source share
1 answer

just enter the translator and don't forget to add a statement transto dump message errors in the Twig template.

Here is 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 box to exclude inactive users

hope this help

+4
source

All Articles