gettext/js-scanner

Javascript scanner for gettext

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

This package is auto-updated.

Last update: 2024-10-15 03:06:46 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.