forked from arathunku/gulp-translator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtranslator-gulp.js
37 lines (29 loc) · 921 Bytes
/
translator-gulp.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
var fs = require('fs');
var through = require('through2');
var gutil = require('gulp-util');
var PluginError = gutil.PluginError;
var Translator = require("./lib/translator.js");
const PLUGIN_NAME = 'gulp-translator';
var plugin = function (options) {
var translator = new Translator(options);
return through.obj(function(file, enc, cb){
var self = this;
if(file.isNull()) {
this.push(file);
return cb();
}
if(file.isStream()) {
this.emit('error', new PluginError(PLUGIN_NAME, 'Streaming not supported'));
return cb();
}
translator.translate(String(file.contents)).then(function(content){
file.contents = new Buffer(content);
self.push(file);
return cb();
}, function(error){
self.emit('error', new PluginError(PLUGIN_NAME, (error||'') + " and is used in " + file.path));
return cb();
});
});
};
module.exports = plugin;