Twig scanner for gettext

dev-master 2020-05-23 15:21 UTC

This package is auto-updated.

Last update: 2020-09-23 16:17:30 UTC


Latest Version on Packagist Software License Build Status Quality Score Total Downloads

Created by Raphaël Droz (GPL-3 License)

Twig code scanner to use with gettext/gettext


In order to be usable, upstream ParsedFunction class at php-gettext/Gettext must be slightly modified to ease inheritance.


composer require gettext/twig-scanner

About dependencies

We do not require a specific version of Twig.

ToDo: Support symfony/twig-bridge trans filter.

Usage example

use Gettext\Scanner\TwigScanner;
use Gettext\Generator\PoGenerator;
use Gettext\Translations;

//Create a new scanner, adding a translation for each domain we want to get:
$twigScanner = new TwigScanner(

//Set a default domain, so any translations with no domain specified, will be added to that domain

//Extract all comments starting with 'notes:'

//Scan files
foreach (glob('*.twig') as $file) {

//Save the translations in .po files
$generator = new PoGenerator();

foreach ($twigScanner->getTranslations() as $domain => $translations) {
    $generator->generateFile($translations, "locales/{$domain}.po");

Please see CHANGELOG for more information about recent changes.

The GPL-3 License (GPL-3). Please see LICENSE for more information.