0
votes

I started working on a project using Silex and Twig and now I'm trying to set up translations. I registered TranslationServiceProvider before TwigServiceProvider and basically this work's:

{{ app.translator.trans('Homepage') }}

but this doesn't:

{{ 'Homepage'|trans }}

and it returns the following error:

Twig_Error_Syntax in ExpressionParser.php line 573: The filter "trans" does not exist in "homepage.twig" at line 6

I have read the Silex documentation stating that

when using the Twig bridge provided by Symfony (see TwigServiceProvider), you will be allowed to translate strings in the Twig way

but I still don't understand what I am doing wrong and how does the trans filter work.

1
Can you show how you register them, and which version of symfony/translation and silex are you using?Maerlyn
Thank's for the hint ;)iosifv

1 Answers

0
votes

In my particular case, the issue was that I did not have, twig-bridge declared in composer.json:

"require": {
    "silex/silex"           : "1.2.2",    
    "symfony/twig-bridge"   : "~2.3",
    "twig/twig"             : "1.16.2"
}

only silex and twig.