在Symfony2的翻译身份验证错误的方式推荐 [英] Recommended way of translating authentication errors in symfony2
问题描述
我需要显示,例如,在另一种语言的坏凭据的消息。
到目前为止,我发现它抛出的结果异常
<$c$c>\\vendor\\symfony\\src\\Symfony\\Component\\Security\\Core\\Authentication\\Provider\\UserAuthenticationProvider.php$c$c>验证
函数结果抛出新BadCredentialsException(坏凭据',0,$ NOTFOUND);
我想知道什么将是展示另一种语言此消息的推荐方式。只是改变在这个地方似乎串非最佳...
也有可能大概身份验证过程中显示其他消息。
我现在用的是 JMSSecurityExtraBundle
和 FOSUserBundle
,我想可能有一些内置的功能来处理这个问题。 ..?
-
覆盖登录模板:副本 FOSUserBundle /资源/视图/安全/ login.html.twig 到应用/资源/视图/安全/ login.html.twig (见文档,的视频)
-
反过滤器添加到错误变量login.html.twig(见的 DOC ):
{{错误|反}}
-
在您的翻译文件的src / YourBundlePath /资源/翻译/信息{}区域.yml 补充:
坏凭据:您的错误文本
I need to display, for example, the "Bad credentials" message in another language.
So far I found that it is thrown as an exception in
\vendor\symfony\src\Symfony\Component\Security\Core\Authentication\Provider\UserAuthenticationProvider.php
authenticate
function as
throw new BadCredentialsException('Bad credentials', 0, $notFound);
I am wondering what would be the recommended way for showing this message in another language. Just changing the string in this place seems non-optimal... Also there are other messages that might probably be shown during authentication.
I am using the JMSSecurityExtraBundle
and FOSUserBundle
and I guess there could be some built in functionality to handle this...?
Override login template: copy FOSUserBundle/Resources/views/Security/login.html.twig to app/Resources/views/Security/login.html.twig (see doc, video)
Add trans filter to error variable in login.html.twig (see doc):
{{ error|trans }}
In your translate file src/YourBundlePath/Resources/translations/messages.{locale}.yml add:
Bad credentials: Your error text
这篇关于在Symfony2的翻译身份验证错误的方式推荐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!