gettext/php-scanner

PHP scanner for gettext

v1.2.1 2020-05-28 10:39 UTC

This package is auto-updated.

Last update: 2020-09-28 11:19:43 UTC


README

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

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.