php – 如何翻译Symfony2异常

我正在使用yml格式来翻译我的网络应用程序,但我遇到了一个问题.

我想做什么:

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

我所知道的可能是:

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

这是翻译异常的唯一方法吗?

解决方法:

只需放入翻译器并记住在Twig模板中的messagge错误转储中添加trans语句.

这是一个xliff示例:

    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>

并在模板中

{# 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>

检查this doc是否排除非活动用户

希望这个帮助

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...