Registry / testing / wp-textdomain

wp-textdomain

JSON →
library1.0.1jsnpmunverified

A linting and fixing tool for WordPress plugin and theme textdomains in PHP files. Version 1.0.1 is latest. It scans PHP files using glob patterns and validates/replaces textdomain arguments in gettext functions like __, _e, _x, etc. Supports multiple domains in an array, automatic fixes (fix option), and custom keyword definitions. Key differentiators: specifically designed for WordPress, unlike general PHP linters; can fix missing or incorrect textdomains; configurable via options like engine (php-parser), variableDomain, and missingDomain.

npm install wp-textdomain
INSTALL
IMPORT
SIG · WP-TEXTDOMAIN
W
wp-textdomain
testingjavascriptv1.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

wpTextdomain
const wpTextdomain = require('wp-textdomain');
import wpTextdomain from 'wp-textdomain';
Package exports a single function via CommonJS; ESM import is not supported by default
wpTextdomain
import wpTextdomain from 'wp-textdomain';
In TypeScript, if module resolution allows, you can use ESM but the package is CJS

Shows basic linting and fixing of WordPress textdomains in PHP files using wp-textdomain.

const wpTextdomain = require('wp-textdomain'); // Lint PHP files for textdomain 'my-theme' wpTextdomain('**/*.php', { domain: 'my-theme', fix: false }); // With automatic fix using multiple domains wpTextdomain('**/*.php', { domain: ['my-theme', 'kirki'], fix: true });
wp-textdomain --version
Debug
Known issues
gotchaWhen using multiple domains, fixing uses the first domain as replacement; others are only valid.
fix
Always ensure the primary domain is listed first in the domain array when fix:true.
affects: >=0.0.0
gotchaThe package uses php-parser for parsing PHP; complex PHP syntax may cause errors.
fix
Test with your codebase and consider reporting issues on GitHub.
affects: >=0.0.0
deprecatedThe 'logfile' option with moment.js timestamp may be deprecated; moment is a heavy dependency.
fix
Consider using a custom date function or a lightweight alternative.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot read properties of undefined (reading 'domain')
Missing or incorrectly formatted options object, or domain not specified.
fix
Ensure options object is provided with a 'domain' property (string or array).
No files matched for pattern: **/*.php
Provided glob pattern does not find any PHP files.
fix
Double-check the pattern and working directory; use an absolute path if needed.
Error: php-parser: Parse Error on line X
PHP file contains syntax that php-parser cannot parse.
fix
Temporarily remove or fix the problematic PHP syntax, or update php-parser settings.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies
php-parserrequiredParses PHP files to analyze and modify gettext calls
globrequiredMatches file patterns to locate PHP files
momentoptionalFormats timestamps for logfile configuration
Agent activity
17 hits · last 30 days
node
16
Resources