-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
52 lines (40 loc) · 1.18 KB
/
index.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
var through = require('through2'),
gutil = require('gulp-util'),
po = require('node-po'),
PluginError = gutil.PluginError;
module.exports = function () {
function write (f, enc, cb){
if (f.isNull()) {
this.push(f);
return cb();
}
if (f.isStream()) {
this.emit('error', new PluginError('gulp-po-json',
'Streaming not supported'));
return cb();
}
var pofile = po.parse(f.contents.toString('utf-8')),
res = {},
dic = {},
i,
l;
if (!pofile) {
this.emit('error', new PluginError('gulp-po-json',
'Unable to parse file ' + f.path));
return cb();
}
res.meta = pofile.headers;
res.dic = dic;
for (i = 0, l = pofile.items.length; i < l; i += 1) {
res.dic[pofile.items[i].msgid] = pofile.items[i].msgstr[0];
}
f.path = f.path.replace(/\.po$/gi, '.json');
f.contents = new Buffer(JSON.stringify(res));
this.push(f);
cb();
}
function end (cb) {
cb();
}
return through.obj(write, end);
};