10quality / gettext-wp-scanner
WordPress scanner for gettext.
Installs: 1 074
Dependents: 1
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- gettext/gettext: ^5.7
- gettext/js-scanner: ^1.1
- gettext/php-scanner: ^1.3
Requires (Dev)
- phpunit/phpunit: ^9.6
This package is auto-updated.
Last update: 2024-11-05 09:32:32 UTC
README
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
- gettext/gettext
- PHP >= 7.2.
License
The MIT License (MIT). Please see LICENSE
File for more information.