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

gulp-checktextdomain

v2.3.0

Published

A Gulp plugin to checks gettext function calls for missing or incorrect text domain.

Downloads

3,134

Readme

gulp-checktextdomain

Build Status

Package Quality

A Gulp plugin to checks gettext function calls for missing or incorrect text domain.

Inspired by grunt-checktextdomain.

Getting Started

npm install gulp-checktextdomain --save-dev

The "checktextdomain" task

Important: Before you start

For the task to run you need to specify:

  1. Text domain(s) - a string or array of valid text domain(s)
  2. Keywords - gettext functions, along with a specification indicating where to look for the text domain

Keyword specifications

This task extends the original keyword specification to indicate where to look for the text domain. The default specification is of the form

    [function name]:[argument-specifier],[argument-specifier],...

where an argument specificier, [argument-specifier], is of the form

  • [number] - indicating that this argument is a translatable string
  • [number]c - indicating that this argument is a context specifier

For example:

  • gettext - the translated string is the first argument of gettext()
  • ngettext:1,2 - the translated strings are arguments 1 and 2 of of ngettext()
  • pgettext:1c,2 - argument 1 is a context specifier and the translated string is argument 2 of pgettext()

This task requires an additional argument specifier (in fact this is the only required one): [number]d - indicating that the argument is a domain specifier. For example:

  • __:1,2d - the translated string is the first argument of __() and the domain is the second argument
  • _n:1,2,4d - the translated strings are arguments 1 and 2 of _n() and the fourth is the domain specifier.
  • _nx:1,2,3c,5d - the translated strings are arguments 1 and 2 of _nx(), the third is a context specifier and the fifth is the domain specifier.

Example keyword specifications (WordPress)

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'
];

Options

text_domain

Type: String|Array

Must be provided. A text domain (or an array of text domains) indicating the domains to check against.

keywords

Type: Array

An array of keyword specifications to look for. See above section for details & examples.

report_missing

Type: Bool Default value: true

Whether to report use of keywords without a domain being passed.

report_success

Type: Bool Default value: false

Whether to report a "no problem" message when a file passes validation.

report_variable_domain

Type: Bool Default value: true

Whether to report use of keywords with a variable being used as the domain.

correct_domain

Type: Bool Default value: false

Whether to automatically correct incorrect domains. Please note that this does not add in missing domains, and can only be used when one text domain is supplied. This will also correct instances where a variable, rather than string is used as a text doman, unless you set report_variable_domain to false.

create_report_file

Type: Bool Default value: false

Create a hidden .[target].json file with reported errors.

force

Type: Bool Default value: false

Set force to true to report text domain errors but not fail the task

Usage Examples

This is a typical set-up for WordPress development. The only thing specific to WordPress here is the keywords list.

var gulp = require('gulp');
var checktextdomain = require('gulp-checktextdomain');

gulp.task('checktextdomain', function() {
	return gulp
	.src('**/*.php')
	.pipe(checktextdomain({
		text_domain: 'my-domain', //Specify allowed domain(s)
		keywords: [ //List keyword specifications
			'__: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'
		],
	}));
});

Release History

Read the full changelog.

License

ISC © Félix Zapata