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

Fatal error: Uncaught Twig_Error_Syntax: Unexpected token "punctuation" of value "|" #63

Open Petervw opened 5 years ago

Petervw commented 5 years ago

Hi there,

First of all, thanks for your repository! Great trick to extract the translations from our twig files.

While we are updating our translation files, we encountered this error. Can you help with a fix?

Thanks, Petervw


PHP Fatal error: Uncaught Twig_Error_Syntax: Unexpected token "punctuation" of value "|" ("name" expected) .... in phar:///usr/local/bin/twig-gettext-extractor/vendor/twig/twig/lib/Twig/TokenStream.php:87

Stack trace:

0 phar:///usr/local/bin/twig-gettext-extractor/vendor/twig/twig/lib/Twig/ExpressionParser.php(449): Twig_TokenStream->expect(5)

1 phar:///usr/local/bin/twig-gettext-extractor/vendor/twig/twig/lib/Twig/ExpressionParser.php(443): Twig_ExpressionParser->parseFilterExpressionRaw(Object(Twig_Node_Expression_Constant))

2 phar:///usr/local/bin/twig-gettext-extractor/vendor/twig/twig/lib/Twig/ExpressionParser.php(302): Twig_ExpressionParser->parseFilterExpression(Object(Twig_Node_Expression_Constant))

3 phar:///usr/local/bin/twig-gettext-extractor/vendor/twig/twig/lib/Twig/ExpressionParser.php(194): Twig_ExpressionParser->parsePostfixExpression(Object(Twig_Node_Expression_Constant))

4 phar:///usr/local/ in phar:///usr/local/bin/twig-gettext-extractor/vendor/twig/twig/lib/Twig/TokenStream.php on line 87

Code example (the pipes are on line 4):

    {% if form.api_key == '' || form.button_text == '' %}
        <div class="alert alert-info">
umpirsky commented 5 years ago

Does it happens with:

    {% if form.api_key == '' or form.button_text == '' %}
        <div class="alert alert-info">

:question:

Petervw commented 5 years ago

@umpirsky, yes your code example is a good workaround. Note that OR doesn't work.

What do you think of a || implementation? Twig supports this syntax.

umpirsky commented 5 years ago

It is a bug, sure, that's why I keep it open, we should fix it. Just wanted to know if there is a workaround. Thanks for reporting!