-
Notifications
You must be signed in to change notification settings - Fork 12
/
validate_language_files.js
39 lines (31 loc) · 1.16 KB
/
validate_language_files.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
// run this from project root to check if the json structures of all langauges files are valid and if all tokens provided with the template are translated
// node validate_language_files.js
var fs = require('fs');
var colors = require('colors');
var template_file_name = '_template.json';
var template_keys = require('./languages/' + template_file_name );
fs.readdir('./languages', function(err, files) {
if (err) console.log(err);
files.forEach(function(fileName) {
if (fileName == template_file_name) { return; }
fs.readFile('./languages/' + fileName, function(err, data) {
if (err) console.log(jerror);
try {
var map = JSON.parse(data);
console.log("%s: validate json ".green, fileName);
for (var key in template_keys) {
if (map[key] == null) {
console.warn("\tno translation found for '%s'".red, key);
}
}
for (var key in map) {
if (!(key in template_keys)) {
console.log("\ttranslation found for '%s' not defined in template".gray, key);
}
}
} catch (e) {
console.log("%s: %s".red, fileName, e);
}
});
});
});