A Gulp plugin to checks gettext function calls for missing or incorrect text domain.
Inspired by grunt-checktextdomain.
npm install gulp-checktextdomain --save-dev
For the task to run you need to specify:
- Text domain(s) - a string or array of valid text domain(s)
- Keywords - gettext functions, along with a specification indicating where to look for the text domain
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 ofgettext()
ngettext:1,2
- the translated strings are arguments 1 and 2 of ofngettext()
pgettext:1c,2
- argument 1 is a context specifier and the translated string is argument 2 ofpgettext()
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.
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'
];
Type: String
|Array
Must be provided. A text domain (or an array of text domains) indicating the domains to check against.
Type: Array
An array of keyword specifications to look for. See above section for details & examples.
Type: Bool
Default value: true
Whether to report use of keywords without a domain being passed.
Type: Bool
Default value: false
Whether to report a "no problem" message when a file passes validation.
Type: Bool
Default value: true
Whether to report use of keywords with a variable being used as the 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
.
Type: Bool
Default value: false
Create a hidden .[target].json
file with reported errors.
Type: Bool
Default value: false
Set force to true to report text domain errors but not fail the task
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'
],
}));
});
Read the full changelog.
ISC © Félix Zapata