How to use a Symfony Translator in my Twig template?
<p>I've been working on translating my application, I pull the translations from my database and add them to a catalogue. Everything works within Symfony, if I echo a translation with <code>$translator-&gt;trans('TEST_TRANSLATION')</code> for example it echoes the correct value, so I assume that my translations are correct.</p>

<p>Now I use Twig as my template engine, which supports translations with the {% trans %} tags. Sadly the translations from the translator variable don't work within Twig and after Googling for quite a while I can't seem to find a working solution.<br>
  I've read about doing something with adding extensions using <code>$twig-&gt;addExtension()</code>, but I can't get that to work. </p>

<p>I would appreciate it if someone could point me in the right direction or maybe even provide a clearer explanation on how to achieve using the translator with the {% trans %} tags.</p>

<p>Thanks in advance.</p>

<p>Edit: Here's the code from the Controller I use to create a translator:</p>

<pre><code>$this-&gt;translator = new Translator('en');
$this-&gt;translator-&gt;addLoader('array', new ArrayLoader());
$this-&gt;translator-&gt;addResource('array', $translations, 'en');

echo $this-&gt;translator-&gt;trans('TEST_TRANSLATION');
</code></pre>

<p>The $translations variable contains an array with the translations, when using echo it shows the given translation correctly. How can I get this translator to work in Twig when using <code>&lt;p&gt;{% trans %}TEST_TRANSLATION{% endtrans %}&lt;/p&gt;</code>?</p>

<p><strong>Edit 2</strong>: I've been trying all kinds of stuff in the last 1,5 hours, but nothing works. I have found out however that giving the translator to the array for the render function of the Twig template enables me to acces its variables, I do this as follows:</p>

<pre><code>return $this-&gt;render('test/transTest.html.twig', array('translator'=&gt;$this-&gt;translator));
</code></pre>

<p>If I use the above I can access the translation variables within Twig by doing:</p>

<pre><code>&lt;p&gt;{{ translator.trans('TEST_TRANSLATION') }}&lt;/p&gt;
</code></pre>

<p>Using<code>&lt;p&gt;{{ translator.locale }}&lt;/p&gt;</code> also gives me the right locale information.</p>

<p>I am pretty sure now that nothing is wrong with translations, but the site I'm working on uses {% trans %} for translations within Twig and I still have no idea how to get my Translator translations to work with those. Any help would be greatly appreciated.</p>