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

Unknown "__" function #33

Closed dweipert-3138720606 closed 8 years ago

dweipert-3138720606 commented 8 years ago

I just discovered that poedit can't parse my twig files and immediately found your extractor!

I installed it like in your global approach: $ sudo wget https://github.com/umpirsky/Twig-Gettext-Extractor/releases/download/1.2.0/twig-gettext-extractor.phar -O /usr/local/bin/twig-gettext-extractor $ sudo chmod a+x /usr/local/bin/twig-gettext-extractor

But my poedit can't execute the given command from your setup.

Cannot execute program: twig-gettext-extractor --sort-output --force-po -o "/tmp/poeditWdeTGk/2extracted.pot" --from-code=UTF-8 -k__ -k_e -k_n:1,2 -k_x:1,2c -k_ex:1,2c -L PHP --files "menu/views/settings.twig" "post-type/views/archive.twig"

When navigating to my project folder and executing the command manually I get: PHP Fatal error: Uncaught exception 'Twig_Error_Syntax' with message 'Unknown "__" function in "/home/dweipert/PhpstormProjects/dealer-search/code-plugin-dealer-search/menu/views/settings.twig" at line 1.' in phar:///usr/local/bin/twig-gettext-extractor/vendor/twig/twig/lib/Twig/ExpressionParser.php:573

But I defined "__" and some more WordPress specific functions as keywords for my catalog.

umpirsky commented 8 years ago

@DRogue1337 You should define custom extensions like documented in https://github.com/umpirsky/Twig-Gettext-Extractor#custom-extensions.

__ is not available by default in twig.

Feel free to reopen if this does not fixes your issue.