gettext / twig-scanner
Twig scanner for gettext
Installs: 6 161
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 2
Forks: 2
Open Issues: 4
Requires
- php: ^7.2 || ^8.0
- gettext/gettext: ^v5.5.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.15
- oscarotero/php-cs-fixer-config: ^1.0
- phpunit/phpunit: ^8.0
- squizlabs/php_codesniffer: ^3.0
- timber/timber: dev-master
This package is auto-updated.
Last update: 2024-11-18 23:27:20 UTC
README
Created by Raphaël Droz raphael.droz@gmail.com (GPL-3 License)
Twig code scanner to use with gettext/gettext
Warning
In order to be usable, upstream ParsedFunction class at php-gettext/Gettext must be slightly modified to ease inheritance.
Installation
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( Translations::create('domain1'), Translations::create('domain2'), Translations::create('domain3') ); //Set a default domain, so any translations with no domain specified, will be added to that domain $twigScanner->setDefaultDomain('domain1'); //Extract all comments starting with 'notes:' $twigScanner->extractCommentsStartingWith('notes:'); //Scan files foreach (glob('*.twig') as $file) { $twigScanner->scanFile($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.