gettext/js-scanner

Javascript scanner for gettext

v1.1.2 2022-02-14 21:40 UTC

This package is auto-updated.

Last update: 2024-11-15 03:24:55 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)

Javascript code scanner to use with gettext/gettext

Installation

composer require gettext/js-scanner

Usage example

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

//Create a new scanner, adding a translation for each domain we want to get:
$jsScanner = new JsScanner(
    Translations::create('domain1'),
    Translations::create('domain2'),
    Translations::create('domain3')
);

//Scan files
foreach (glob('*.js') as $file) {
    $jsScanner->scanFile($file);
}

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

foreach ($jsScanner->getTranslations() as $translations) {
    $domain = $translations->getDomain();
    $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.