4
我使用yml格式來翻譯我的web應用程序,但我遇到了一個問題。如何翻譯Symfony2異常
我想這樣做:
#exception.en.yml
exception.bad: 'Bad credentials'
我知道什麼是可以做到的:
#exception.en.yml
'Bad credentials': 'Bad credentials'
這是該異常翻譯的唯一方法?
我使用yml格式來翻譯我的web應用程序,但我遇到了一個問題。如何翻譯Symfony2異常
我想這樣做:
#exception.en.yml
exception.bad: 'Bad credentials'
我知道什麼是可以做到的:
#exception.en.yml
'Bad credentials': 'Bad credentials'
這是該異常翻譯的唯一方法?
只需放入翻譯器中,並記住在Twig模板中的消息錯誤轉儲中添加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爲排除非活躍用戶
希望這有助於
究竟如何我就在想,很有用! – 2014-10-26 21:22:49