4

I'm using Zend Framework 2.3.1 with Twig as my template engine and ZfTwig extension.

I want to use the Twig translate syntax but with the Zend translator, so PoEdit can parse it.

Is there a (simple) way to realize my ideas? Thanks in advance!

edigu
  • 9,878
  • 5
  • 57
  • 80
Kiselli
  • 63
  • 5

1 Answers1

0

When you use Twig as a template engine you'll handle .twig files and not .phtml files. Twig files have different syntax from PHP files, and by default Poedit does not have the ability to parse twig templates.

However, you can add a new extractor to Poedit which will allow you to parse Twig templates just like you do with plain PHP templates. You can use Twig-Gettext-Extractor. It can be easily installed through composer. Once you install all dependencies you can configure Poedit by adding new Twig parser.

This is the parser command :

<project>/vendor/bin/twig-gettext-extractor --sort-output --force-po -o %o %C %K -L PHP --files %F

In Poedit, Edit > Preferences > Parsers, enter the following options :

enter image description here

Or you may prefer to use it in command line like this :

./twig-gettext-extractor --sort-output --force-po -o messages.po -L PHP --files file1.twig file2.twig fileN.twig

Now your parser is configured and Poedit can scan the twig templates.

For more details about the installation and the configuration of Twig Gettext Extractor, you may refer to README file on Github.

Hope this helps.

blackbishop
  • 30,945
  • 11
  • 55
  • 76