Last active
March 19, 2019 21:01
-
-
Save NazarkinRoman/2cf27ec83c4d2ebd3b56b5d371591cf0 to your computer and use it in GitHub Desktop.
Gulp wrapper for node-wp-i18n
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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