umpirsky / Twig-Gettext-Extractor

The Twig Gettext Extractor is Poedit friendly tool which extracts translations from twig templates.
MIT License
113 stars 32 forks source link

Uncaught Twig_Error_Syntax: Unexpected token "punctuation" #41

Closed bjornpost closed 8 years ago

bjornpost commented 8 years ago

Fatal error: Uncaught Twig_Error_Syntax: Unexpected token "punctuation" of value "{" ("end of statement block" expected) in "path/to/template.html" at line 19. in /path/vendor/twig/twig/lib/Twig/TokenStream.php on line 87

The parsing fails on lines like:

{% trans with {'%name%': 'Fabien'} %}Hello %name%{% endtrans %}

(src)

If I'm rendering the template from my application (Silex 2), there's no issue. Do I need to load an extra Twig extension in Twig-Gettext-Extension?

umpirsky commented 8 years ago

Yes, {% trans with {'%name%': 'Fabien'} is not part of twig, but symfony/twig-bridge. You will need to load TranslationExtension.

bjornpost commented 8 years ago

But that extension is loaded by default, according to the source?

umpirsky commented 8 years ago

Hehum...in deed...

umpirsky commented 8 years ago

TransTokenParser does this magic, and it should be loaded by this extension...

bjornpost commented 8 years ago

Would you mind re-opening this issue? I will look into this. Maybe it's something that's changed between 2.7 and 3.0 (I'm testing on a local fork which updated the deps to symfony/* ~3.0).

bjornpost commented 8 years ago

Ok, what I've discovered:

Seems like it's just a matter of swapping the initialisation of Twig_Extensions_Extension_I18n and TranslationExtension. Will prepare PR.

umpirsky commented 8 years ago

Thanks @bjornpost!