-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
71 lines (49 loc) · 2.05 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
var PluginError = require('plugin-error');
var through = require('through');
var PLUGIN_NAME = 'gulp-i18n-lint';
module.exports = function (parent) {
parent = parent || null;
var firstFile = null;
function validate(file) {
var parsed;
var successMsg = "File validated successfully";
var validationMsg = "";
if (file.isNull()) {
return this.queue(file);
}
if (file.isStream()) {
return this.emit('error', new PluginError(PLUGIN_NAME, 'Streaming not supported!'));
}
if (!firstFile) {
firstFile = file;
}
try {
parsed = JSON.parse(file.contents.toString('utf8'));
} catch (err) {
err.message = 'Error while parsing ' + file.path + ': ' + err.message;
return this.emit('error', new PluginError(PLUGIN_NAME, err));
}
for (var sourceFile in parsed) {
var source = parsed[sourceFile];
for (var i18nKey in source.content) {
if (!(i18nKey.indexOf('.') < 1)) {
if (parent != null) {
if (!(i18nKey.indexOf(parent) === 0)) {
var i18nKeyInitValue = i18nKey.substr(0, i18nKey.indexOf('.'));
validationMsg += "ERROR: " + i18nKeyInitValue + " was used as a part of the key : " + i18nKey + " in Module : " + parent + '\n';
}
}
else {
if (!(i18nKey.indexOf(sourceFile) === 0)) {
var i18nKeyInitValue = i18nKey.substr(0, i18nKey.indexOf('.'));
validationMsg += "ERROR: " + i18nKeyInitValue + " was used as a part of the key : " + i18nKey + " in SourceFile : " + sourceFile + '\n';
}
}
}
}
}
if (validationMsg.length > 0) { console.log(validationMsg); }
else { console.log(successMsg); }
}
return through(validate);
};