Skip to content

Instantly share code, notes, and snippets.

@BinaryMoon
Last active November 16, 2016 11:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BinaryMoon/edb39e27ec0327d01f63d8b9bc55e071 to your computer and use it in GitHub Desktop.
Save BinaryMoon/edb39e27ec0327d01f63d8b9bc55e071 to your computer and use it in GitHub Desktop.
Use gulp to check the textdomain in a WordPress theme
/**
* Get theme folder from theme parameter or use granule
*
* @returns {String|util.env.theme}
*/
function utilGetTheme() {
var theme = 'granule';
if ( util.env.theme ) {
// check for a command line variable
// use it if it exists
theme = util.env.theme;
}
console.log( 'Theme Name: ' + UtilUpperCaseFirstWord( theme ) );
return theme;
}
gulp.task(
'checktextdomain',
function() {
var theme_slug = utilGetTheme();
return gulp
.src( './' + theme_slug + '/**/*.php')
.pipe(
checktextdomain(
{
text_domain: theme_slug, //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'
],
}
)
);
}
);
var gulp = require( 'gulp' );
var util = require( 'gulp-util' );
var checktextdomain = require( 'gulp-checktextdomain' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment