2011-12-13 84 views
1

我使用FOSUserBundle登录表单,我想翻译错误消息。这些消息将在这里展开:供应商/ symfony中/ src目录/ Symfony的/分量/安全/核心/认证/供应商/ DaoAuthenticationProvider.php翻译登录表单的错误信息

protected function checkAuthentication(UserInterface $user, UsernamePasswordToken $token) 
    { 
     $currentUser = $token->getUser(); 
     if ($currentUser instanceof UserInterface) { 
      if ($currentUser->getPassword() !== $user->getPassword()) { 
       throw new BadCredentialsException('The credentials were changed from another session.'); 
      } 
     } else { 
      if (!$presentedPassword = $token->getCredentials()) { 
       throw new BadCredentialsException('The presented password cannot be empty.'); 
      } 

      if (!$this->encoderFactory->getEncoder($user)->isPasswordValid($user->getPassword(), $presentedPassword, $user->getSalt())) { 
       throw new BadCredentialsException('The presented password is invalid.'); 
      } 
     } 
    } 

我已经写应用程序/资源/翻译/ validators.fr .yml

"The presented password cannot be empty.":  "Veuillez saisir un mot de passe." 

我已经写应用程序/资源/翻译/ messages.fr.yml

"The presented password cannot be empty.":  "Veuillez saisir un mot de passe." 

但它不起作用。 其他翻译正在工作(=> fr),但我遇到了这些消息的问题。

这些消息的特殊过程?

回答

7

在文件索纳塔/ UserBundle /资源/视图/管理/安全性/ login.html.twig您有:

<div class="alert-message error">{{ error|trans({}, 'SonataUserBundle') }}</div> 

,所以你必须改变SonataUserBundle到任何翻译文件正在使用或添加 的src /你的/包/资源/译/ SonataUserBundle {}现场.yml

和翻译文件中:

'Bad credentials': 'Your translation' 
'The presented password is invalid.': 'Your translation' 
'The presented password cannot be empty.': 'Your translation' 

我希望这是很清楚;]

0

我不这么认为。 你必须捕捉错误并做你需要做的事情...例如显示带有闪存会话消息的消息并重定向到忘记密码页面。

+0

是的,这是一个想法,我会尝试。 – bux 2011-12-14 11:42:39

+1

识别是FOSUserBundle的内部:/我不能赶上 – bux 2011-12-14 12:05:40

2

在FOSUserBundle“Bad Credentials”的1.3版中,它实际上是“Bad Credentials”。 (介意最后一个点)。