Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
The Twig Gettext Extractor is Poedit friendly tool which extracts translations from twig templates.
PHP
branch: master

README.md

Twig Gettext Extractor Build Status

The Twig Gettext Extractor is Poedit friendly tool which extracts translations from twig templates.

Installation

The recommended way to install Twig Gettext Extractor is through composer.

{
    "require": {
        "umpirsky/twig-gettext-extractor": "1.1.*"
    }
}

Setup

By default, Poedit does not have the ability to parse Twig templates. This can be resolved by adding an additional parser (Edit > Preferences > Parsers) with the following options:

  • Language: Twig
  • List of extensions: *.twig
  • Invocation:
    • Parser command: <project>/vendor/bin/twig-gettext-extractor --sort-output --force-po -o %o %C %K -L PHP --files %F
    • An item in keyword list: -k%k
    • An item in input file list: %f
    • Source code charset: --from-code=%c

Now you can update your catalog and Poedit will synchronize it with your twig templates.

Custom extensions

Twig-Gettext-Extractor registers some default twig extensions. However, if you are using custom extensions, you need to register them first before you can extract the data. In order to achieve that, copy the binfile into some custom place. A common practice would be: cp vendor/bin/twig-gettext-extractor bin/twig-gettext-extractor

Now you may add your custom extensions here:

$twig->addFunction(new \Twig_SimpleFunction('myCustomExtension', true));
$twig->addFunction(new \Twig_SimpleFunction('myCustomExtension2', true));

Tests

To run the test suite, you need composer and PHPUnit.

$ composer install --dev
$ phpunit

License

Twig Gettext Extractor is licensed under the MIT license.

Something went wrong with that request. Please try again.