npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

wp-textdomain

v1.0.1

Published

Lint and fix textdomain and usage in PHP files in plugins and themes.

Downloads

40,167

Readme

wp-textdomain

Lint and fix textdomain and usage in PHP files in plugins and themes.

Install

Install with yarn:

$ yarn add wp-textdomain --dev

OR

Install with npm:

$ npm install wp-textdomain --save-dev

Examples

Typical usage is done during a build process for plugins or themes. This code shows how to add linting on your php files, and output the results to console:

const wpTextdomain = require( 'wp-textdomain' );

wpTextdomain( '**/*.php', {
	domain: 'theme-name',
} );

Alternatively, you can pass the configuration option to automatically fix the issues found during the linting report:

const wpTextdomain = require( 'wp-textdomain' );

wpTextdomain( '**/*.php', {
	domain: 'theme-name',
	fix: true
} );

In some cases, you might need more than one textdomain while linting files to be checked against. A common use case for this is by including a framework, such as Kirki, in a theme which does supply it's own translations:

const wpTextdomain = require( 'wp-textdomain' );

wpTextdomain( '**/*.php', {
	domain: [ 'theme-name', 'kirki' ],
	fix: true
} );

When using the fix option, only errors found that aren't kirki are fixed. When fixing errors, the first textdomain listed is the one used as the primary textdomain.

Usage

const wpTextdomain = require( 'wp-textdomain' );
wpTextdomain( pattern, options );

pattern: String A glob pattern for matching files. options: Object wp-textdomain configuration options.

Options

domain

String/Array Textdomain(s) to lint and fix.

If a string is passed, this will be the textdomain that is used to compare against in linting. When passing an array of textdomains, all are checked against as valid textdomains to be used in a theme or plugin.

When running wp-textdomain with the fix option set, the first textdomain in the array is used as the primary textdomain that is used to replace or be added to gettext calls missing or with alternate textdomains.

fix

Bool Whether or not to write files with fixes applied.

When using the fix option, errors that are found are fixed using the first textdomain listed.

engine

Object php-parser configuration options.

missingDomain

Bool Whether or not to perform lints/fixes against gettext methods that are missing textdomains.

variableDomain

Bool Whether or not to perform lints/fixes against gettext methods that are using a variable instead of a string in the textdomain field.

keywords

Array A pattern list of strings containing available gettext methods, and argument positions.

Example:

options.keywords = [
	'__:1,2d',
	'_e:1,2d',
	'_x:1,2c,3d',
	'esc_html__:1,2d',
	'esc_html_e:1,2d',
	'esc_html_x:1,2c,3d',
	'esc_attr__:1,2d',
	'esc_attr_e:1,2d',
	'esc_attr_x:1,2c,3d',
	'_ex:1,2c,3d',
	'_n:1,2,4d',
	'_nx:1,2,4c,5d',
	'_n_noop:1,2,3d',
	'_nx_noop:1,2,3c,4d',
];

fileOpts

Object Configuration options for calls made to fs.readFileSync.

glob

Object minimatch/glob configuration options to pass in.

force

Bool Option to force build fails by exiting process or just warn in console on error.

logfile

Object Logfile configuration options.

  • create Bool
  • path String
  • format Object Filename output format.
    • prefix String String to prepend at beginning of filename.
    • timestamp String A moment.js date/time string.
    • suffix String String to append to end of filename before extension.