umpirsky/twig-gettext-extractor

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

Installs: 350 050

Dependents: 1

Suggesters: 0

Security: 0

Stars: 112

Watchers: 9

Forks: 32

Open Issues: 16

Type:application

v1.3.1 2018-07-20 19:04 UTC

README

68747470733a2f2f6661726d322e737461746963666c69636b722e636f6d2f313730392f32353039383532363838345f616534643530343635665f6f5f642e706e67

symfony upgrade fixertwig gettext extractorwisdomcentipedepermissions handlerextraloadgravatarlocurrocountry listtransliterator

Twig Gettext Extractor Build Status

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

Installation

Manual

Local

Download the twig-gettext-extractor.phar file and store it somewhere on your computer.

Global

You can run these commands to easily access twig-gettext-extractor from anywhere on your system:

$ 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

Then, just run twig-gettext-extractor.

Composer

Local

$ composer require umpirsky/twig-gettext-extractor

Global

$ composer global require umpirsky/twig-gettext-extractor

Make sure you have ~/.composer/vendor/bin in your PATH and you're good to go:

$ export PATH="$PATH:$HOME/.composer/vendor/bin"

Don't forget to add this line in your .bashrc file if you want to keep this change after reboot.

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 (replace <project> with absolute path to your project)
    • An item in keyword list: -k%k
    • An item in input file list: %f
    • Source code charset: --from-code=%c

687474703a2f2f692e696d6775722e636f6d2f66397078322e706e67

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));

Command Line Arguments

You can also specify custom extensions and filters via command line, by adding the --functions and --filters arguments, e.g.:

--functions formRow,formElement --filters localizedCurrency

You can specify an unlimited amount of comma-separated function and filter names.

Similarly, you can specify the location of the gettext executable you want to use with --exec

--exec /usr/local/bin/xgettext