PHPackages                             jdgrimes/wp-l10n-validator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [CLI &amp; Console](/categories/cli)
4. /
5. jdgrimes/wp-l10n-validator

ActiveLibrary[CLI &amp; Console](/categories/cli)

jdgrimes/wp-l10n-validator
==========================

Gettext localization validator for WordPress

0.4.0(8y ago)1834.6k[3 issues](https://github.com/JDGrimes/wp-l10n-validator/issues)MITPHPPHP &gt;=5.3.0

Since Mar 30Pushed 8y ago1 watchersCompare

[ Source](https://github.com/JDGrimes/wp-l10n-validator)[ Packagist](https://packagist.org/packages/jdgrimes/wp-l10n-validator)[ Docs](https://github.com/JDGrimes/wp-l10n-validator)[ RSS](/packages/jdgrimes-wp-l10n-validator/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelog (6)DependenciesVersions (6)Used By (0)

WP L10n Validator [![Build Status](https://camo.githubusercontent.com/1ab6c3ed443d19bb47053719cf579afc716b5be32112646145ea90caf5996ce4/68747470733a2f2f7472617669732d63692e6f72672f4a444772696d65732f77702d6c31306e2d76616c696461746f722e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/JDGrimes/wp-l10n-validator)
===============================================================================================================================================================================================================================================================================================================================

[](#wp-l10n-validator-)

Command-line tool for checking that all strings are properly gettexted for localization in WordPress plugins and themes.

- Finds any untranslated strings in HTML
- Finds any untranslated `'encapsed strings'` in PHP code
- Makes sure all gettext function parameters are valid –no variables, function calls, etc., where there should just be an encapsed string– and that all required arguments are present.
- Makes sure the expected textdomain(s) are always used
- As a side effect, it also checks that no l10n functions are deprecated.

Installation
------------

[](#installation)

**Requires:** PHP 5.3 or later.

Download a zip, clone the repo, or add to composer dependencies. Add the `/bin` directory to your `$PATH` (or use `/path/to/wp-l10n-validator/bin/wp-l10n-validator` instead of just `wp-l10n-validator`in your commands.

To see the basic usage and check that everything is working, type the command:

`$ wp-l10n-validator`

Usage
-----

[](#usage)

`$ wp-l10n-validator -[1c] TEXTDOMAIN [CONFIG] [-- FILE ...]`

This validates all `.php` files in the current directory for proper gettexting.

Arguments:

- `TEXTDOMAIN` - The textdomain used in your project.
- `CONFIG` - Configuration to use. Corressponds to one of the directories in `/config` (`wordpress` by default).
- `FILE` - One or more files to validate. You must pass `--` before the list of files, like this: `wp-l10n-validator textdomain -- a.php b.php`

Flags:

- `1` - Parse only one file at a time.
- `c` - Generate a specific ignores cache. This is a JSON file that contains a list of specific occurrences of strings to ignore. When you have fixed all of the real problems with your project, there may be left many strings that do not need to be gettexted. Running the command with this flag will cache all of those by file name and line number, so that they will be ignored in future. This is especially useful for strings that you want to ignore only in a specific location. If the line number that a string is on changes, but by less than 5 lines, it will continue to be ignored and the line number will be updated in the cache. You can change the number of lines tolerance using the `ignores-tolerance` [configuration option](#configuration).

The validator will display any errors it finds.

Example validating a plugin:

```
$ cd /path/to/my-plugin
$ wp-l10n-validator my-plugin

```

You can also add a `wp-l10n-validator.json` file in the main directory of your project, which specifies the basic configuration for your project ([see below](#configuration)). With this file in place you can run the parser without any arguments.

Configuration
-------------

[](#configuration)

The validator can be configured specifically for your project as needed. Although it can be completely customized, the main reason for additional configuration is to help the parser weed out false positives. The strategy employed for weeding out most false positives is as follows:

- Ignore non-translatable strings inside calls to certain functions
- Ignore specific function arguments that don't need to be gettexted
- Ignore certain HTML attributes' values
- Ignore specific strings
- Ignore specific string occurrences

All of these are configurable to match your particular project, though custom configuration is optional. To configure the parser, you can add a JSON file named `wp-l10n-validator.json` in the root directory of your project (or wherever you wish to run the parser from).

These are the options that you can specify in the the JSON config file:

- `textdomain` - Your project's textdomain.
- `basedir` - The main directory of your project (if different from the current directory).
- `config` - The configuration to use ([see CLI arguments above](#usage)).
- `cache` - The file to store the cache in. The default is `.wp-l10n-validator-cache.json`.
- `ignores-cache` - The file to store the specific ignores cache in. The default is `.wp-l10n-validator-ignores-cache.json`. See the `-c` flag above for more information.
- `ignores-tolerance` - The number of lines of difference to allow for when checking against the ignores cache. The default is 5.
- `ignores-rules` - Configure which rules are used to determine if a string should be ignored. It is an associative array with boolean values:
    - `all-lowercase` — Ignore all strings that contain no uppercase characters. This is a very useful rule to enable if you don't use any translatable strings that are all lowercase. It is disabled by default to avoid false negatives. Add this to your config to enable it: ```
        	"ignores-rules": {
        		"all-lowercase": true
        	},
        ```
- `ignored-functions` - An associative array of functions to ignore. The value can be an array of specific arguments to be ignored (by argument number), or simply `true`. To ignore a class method, add it like this: `My_Class::my_method`. This will only ignore the method when it is being called statically from outside the class like `My_Class::my_method()`, or inside the class with `self::` or `$this->`. The parser does not know what class is assigned to a variable, though it does know the variable name. So you can ignore `$wpdb->query`, (which the parser does ignore by default,) but adding `wpdb::query` will not match a call to `$wpdb->query()`. Adding a class constructor (`My_Class::__construct`) will ignore `new My_Class()`. Calls within a class to `parent::method()` will be mapped to the class that is specified in the `extends` statement. If a method is being ignored in a parent class, it will also be ignored in child classes as well. If a method is being ignored in an interface, all classes that implement that interface will have that method ignored as well (since 0.3.0).
- `ignored-properties` - (0.3.0+) An associative array of class properties to ignore. The values are currently just expected to be `true`. To ignore any strings in the default value for a property, add it like this: `My_Class::$my_property`. This will only ignore the declared value of the property, it will not ignore assignments (yet). It is possible to ignore the default values for the property in all classes that extend a particular parent class by using the parent class name: `Parent_Class::$property`.
- `ignored-strings` - An array of strings that should always be ignored.
- `ignored-atts` - An array of HTML attributes to ignore.
- `ignored-paths` - An array of file and folder paths to ignore. (Since 0.2.0)
- `bootstrap` - A PHP file providing further, more advanced configuration. You can even write your own child class to extend the validator. This allows you to change the output method by overriding the `report_*` functions, for example. Just assign and instance of your class to the `$parser` variable: `$parser = new My_L10n_Validator`.

See [example-config.json](example-config.json) for an example.

Notes
-----

[](#notes)

- Though written primarily as a CLI app, it may also be used directly from within another script to validate a single file or a directory. Only the later option is available from the default CLI usage.
- Don't let the `WP` fool you. Though written primarily for WordPress, it can easily be configured for other frameworks that use similar gettexting methods.

Credits
-------

[](#credits)

- [Codestyling Localization](http://wordpress.org/plugins/codestyling-localization/) for initial parser code.
- [@nikola-tmw](https://github.com/nikolov-tmw) for pointing me in the right direction on wp-hackers.

License
-------

[](#license)

Dual licensed under GPLv2 and MIT licenses.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity29

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~332 days

Total

4

Last Release

3062d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4005415?v=4)[J.D. Grimes](/maintainers/jdgrimes)[@JDGrimes](https://github.com/JDGrimes)

---

Top Contributors

[![JDGrimes](https://avatars.githubusercontent.com/u/4005415?v=4)](https://github.com/JDGrimes "JDGrimes (115 commits)")

---

Tags

cligettexti18nl10nphpwordpress

### Embed Badge

![Health badge](/badges/jdgrimes-wp-l10n-validator/health.svg)

```
[![Health](https://phpackages.com/badges/jdgrimes-wp-l10n-validator/health.svg)](https://phpackages.com/packages/jdgrimes-wp-l10n-validator)
```

###  Alternatives

[wp-cli/wp-cli

WP-CLI framework

5.0k17.2M319](/packages/wp-cli-wp-cli)[consolidation/annotated-command

Initialize Symfony Console commands from annotated command class methods.

22569.8M18](/packages/consolidation-annotated-command)[chi-teck/drupal-code-generator

Drupal code generator

26947.8M5](/packages/chi-teck-drupal-code-generator)[seld/cli-prompt

Allows you to prompt for user input on the command line, and optionally hide the characters they type

24725.8M17](/packages/seld-cli-prompt)[illuminate/console

The Illuminate Console package.

12944.1M5.1k](/packages/illuminate-console)[php-tui/php-tui

Comprehensive TUI library heavily influenced by Ratatui

589747.0k6](/packages/php-tui-php-tui)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
