2011-12-13 6 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

<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

私は同様の方法を使用しました:私はエラーをキャッチし、 。 – bux

0

私はそうは思わない。 あなたはエラーをキャッチして、何をする必要があるのですか?たとえば、フラッシュセッションメッセージのメッセージを表示し、パスワードを忘れたページにリダイレクトします。あなたが持っているファイルのソナタ/ UserBundle /リソース/ビュー/管理/セキュリティ/ login.html.twigで

+0

はい、それはアイデアです、私はそれを試みます。 – bux

+1

IDはFOSUserBundleの内部にあります:/私は – bux

+0

をキャッチすることができませんそれは私が思う:キャッチエラーと何かで=) – bux

2

FOSUserBundleのバージョン1.3では、「Bad Credentials」は実際には「Bad Credentials」です。 (最後の点に気をつけてください)。

関連する問題