title: Symfony2 Login ajax translate error message
body: <p>I would like to translate in my ajax login error messages.
  I am using FOSUserBundle, and I would take advantage of the translation files I properly overwritten folder Resources/translations.</p>
  
  <p>My AthenticationHandler.php:</p>
  
  <pre><code>class AuthenticationHandler
  implements AuthenticationSuccessHandlerInterface,
         AuthenticationFailureHandlerInterface
  {
  
  protected $router;
  protected $security;
  protected $userManager;
  protected $service_container;
  
  public function __construct(RouterInterface $router,SecurityContext $security, $userManager, $service_container)
  {
      $this-&gt;router = $router;
      $this-&gt;security = $security;
      $this-&gt;userManager = $userManager;
      $this-&gt;service_container = $service_container;
  
  }
  public function onAuthenticationSuccess(Request $request, TokenInterface $token) {
      if ($request-&gt;isXmlHttpRequest()) {
          //...
      }
      return new RedirectResponse($this-&gt;router-&gt;generate('anag_new'));
  }
  public function onAuthenticationFailure(Request $request, AuthenticationException $exception) {
  
      if ($request-&gt;isXmlHttpRequest()) {
          $error = $exception-&gt;getMessage();
          $result = array('success' =&gt; false, 'message' =&gt; $request-&gt;get('translator')-&gt;trans($error, array(), 'FOSUserBundle'));
          $response = new Response(json_encode($result));
          $response-&gt;headers-&gt;set('Content-Type', 'application/json');
          return $response;
      } else {
          //...
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>But return this error:</p>
  
  <pre><code>Fatal error: Call to a member function trans() on a non-object in /var/www/MyBusiness/src/My/UserBundle/Handler/AuthenticationHandler.php
  </code></pre>
  
  <p>How do I translate the error messages?</p>