10quality/gettext-wp-scanner

WordPress scanner for gettext.

v1.0.1 2023-02-05 05:47 UTC

This package is auto-updated.

Last update: 2024-11-05 09:32:32 UTC


README

Packagist Version GitHub Workflow Status (with branch) GitHub

WordPress code scanner to use with gettext/gettext.

The scanner is a PHP based same as the gettext package.

Installation

composer require 10quality/gettext-wp-scanner

PHP usage example

use Gettext\Translations;
use Gettext\Generator\PoGenerator;
use TenQuality\Gettext\Scanner\WPPhpScanner;

// Create a new scanner, adding the plugin / theme domain we want to get:
$phpScanner = new WPPhpScanner(
    Translations::create('my-domain')
);

// Scan PHP 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");
}

JavaScript usage example

use Gettext\Translations;
use Gettext\Generator\PoGenerator;
use TenQuality\Gettext\Scanner\WPJsScanner;

// Create a new scanner, adding the plugin / theme domain we want to get:
$phpScanner = new WPJsScanner(
    Translations::create('my-domain')
);

// Scan PHP files
foreach (glob('*.js') 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");
}

Coverage

Languages

  • PHP
  • JavaScript

PHP functions

  • __()
  • _e()
  • _n()
  • _n_noop()
  • _x()
  • _nx()
  • _nx_noop()
  • esc_attr__()
  • esc_attr_e()
  • esc_attr_x()
  • esc_html__()
  • esc_html_e()
  • esc_html_x()

JavaScript functions

  • __()
  • _x()
  • _n()
  • _nx()

Requirements

License

The MIT License (MIT). Please see LICENSE File for more information.