Skip to content

Instantly share code, notes, and snippets.

@NazarkinRoman
Last active March 19, 2019 21:01
Show Gist options
  • Save NazarkinRoman/2cf27ec83c4d2ebd3b56b5d371591cf0 to your computer and use it in GitHub Desktop.
Save NazarkinRoman/2cf27ec83c4d2ebd3b56b5d371591cf0 to your computer and use it in GitHub Desktop.
Gulp wrapper for node-wp-i18n
/* eslint-env node */
/** global: Buffer */
'use strict';
const gutil = require('gulp-util');
const through = require('through2');
const wpi18n = require('node-wp-i18n');
const PluginError = gutil.PluginError;
/**
* Determine if `obj` is a object or not.
*
* @param {object} obj
*
* @return {boolean}
*/
function isObject (obj) {
return Object.prototype.toString.call(obj) === '[object Object]';
}
/**
* Run the wp pot generator.
*
* @param {object} options
*
* @return {object}
*/
function gulpWP_i18n (options) {
if (options !== undefined && !isObject(options)) {
throw new PluginError('gulp-wp-i18n', 'Require a argument of type object.');
}
const files = [];
const stream = through.obj(function (file, enc, cb) {
if (file.isStream()) {
throw new PluginError('gulp-wp-i18n', 'Streams are not supported.');
}
files.push(file.path);
cb();
}, function (cb) {
if (!options) { options = {}; }
wpi18n.addtextdomain(files, options).then(cb);
});
return stream;
}
module.exports = gulpWP_i18n;
{
"name": "gulp-wp-i18n",
"version": "1.0.0",
"description": "Gulp wrapper for node-wp-i18n",
"license": "MIT",
"author": {
"name": "Roman Nazarkin",
"email": "[email protected]",
"url": "https://github.com/NazarkinRoman"
},
"engines": {
"node": ">=4"
},
"files": [
"index.js"
],
"keywords": [
"gulpplugin",
"pot",
"wordpress",
"translation"
],
"dependencies": {
"gulp-util": "^3.0.8",
"through2": "^2.0.3",
"node-wp-i18n": "NazarkinRoman/node-wp-i18n"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment