gettext / php-scanner
PHP scanner for gettext
Installs: 277 480
Dependents: 10
Suggesters: 0
Security: 0
Stars: 14
Watchers: 2
Forks: 6
Open Issues: 1
Requires
- php: >=7.4
- gettext/gettext: ^5.5.0
- nikic/php-parser: ^5
Requires (Dev)
README
Created by Oscar Otero http://oscarotero.com oom@oscarotero.com (MIT License)
PHP code scanner to use with gettext/gettext
Installation
composer require gettext/php-scanner
Usage example
use Gettext\Scanner\PhpScanner; use Gettext\Generator\PoGenerator; use Gettext\Translations; //Create a new scanner, adding a translation for each domain we want to get: $phpScanner = new PhpScanner( 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 $phpScanner->setDefaultDomain('domain1'); //Extract all comments starting with 'i18n:' and 'Translators:' $phpScanner->extractCommentsStartingWith('i18n:', 'Translators:'); //Scan files foreach (glob('*.php') as $file) { $phpScanner->scanFile($file); } //Save the translations in .po files $generator = new PoGenerator(); foreach ($phpScanner->getTranslations() as $domain => $translations) { $generator->generateFile($translations, "locales/{$domain}.po"); }
Please see CHANGELOG for more information about recent changes and CONTRIBUTING for contributing details.
The MIT License (MIT). Please see LICENSE for more information.