title: How to return a localized property of an entity in Symfony 2
body: <p>I have a "Category" entity containing</p>
  
  <pre><code>/**
   * @ORM\Column(type="string", length=255)
   */
  protected $nameFr;
  
  /**
   * @ORM\Column(type="string", length=255)
   */
  protected $nameEn;
  </code></pre>
  
  <p>Now, I'm trying to display the localized name in the view, I can display one or the other using:</p>
  
  <pre><code>{{ categories.nameFr }} and {{ categories.nameEn }}
  </code></pre>
  
  <p>So I made a method called <code>getName()</code> so I can use <code>{{ categories.name }}</code></p>
  
  <p>I only needed to access the locale so I added a <code>protected $locale</code> property to the entity with the setter and getter and I set the locale before calling the view (I use @Template for the return by the way):</p>
  
  <pre><code>$locale = $this-&gt;getRequest()-&gt;getLocale();
  $categories-&gt;setLocale($locale);
  
  return array(
      'categories' =&gt; $categories
  );
  </code></pre>
  
  <p>This was working, but now I implemented a pagination bundle <a href="https://github.com/KnpLabs/KnpPaginatorBundle" rel="nofollow">KnpLabs/KnpPaginatorBundle</a> which requires to send a query instead of the entity:</p>
  
  <pre><code>$em = $this-&gt;getDoctrine()-&gt;getManager();
  
  $categoriesQuery = $em-&gt;createQueryBuilder()
      -&gt;select('category')
      -&gt;from('OylexCategoryBundle:Category', 'category')
  ;
  
  $locale = $this-&gt;getRequest()-&gt;getLocale();
  
  $categoriesQuery-&gt;setLocale($locale);
  
  $paginator  = $this-&gt;get('knp_paginator');
  $categoriesPagination = $paginator-&gt;paginate(
      $categoriesQuery,
      $this-&gt;get('request')-&gt;query-&gt;get('page', 1),
      30
  );
  
  return array(
      'categoriesPagination' =&gt; $categoriesPagination
  );
  </code></pre>
  
  <p>This fails with the error message: <code>FatalErrorException: Error: Call to undefined method Doctrine\ORM\QueryBuilder::setLocale()</code>.</p>
  
  <p>If I try the method <code>setLocale()</code> on <code>$categoriesPagination</code> instead, it fails with the error message: <code>FatalErrorException: Error: Call to undefined method Knp\Bundle\PaginatorBundle\Pagination\SlidingPagination::setLocale()</code></p>
  
  <p>Is there a way to pass the locale to the entity? or Is there even a better way to handle this situation?</p>
  
  <p>Thanks,</p>