我正在使用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>
希望这个帮助