WordPress code scanner to use with gettext/gettext.
The scanner is a PHP based same as the gettext package.
composer require 10quality/gettext-wp-scanner
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");
}
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");
}
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()
- gettext/gettext
- PHP >= 7.2.
The MIT License (MIT). Please see LICENSE
File for more information.