forked from RocketChat/Rocket.Chat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck-unused-i18n.js
More file actions
71 lines (66 loc) · 1.8 KB
/
Copy pathcheck-unused-i18n.js
File metadata and controls
71 lines (66 loc) · 1.8 KB
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 fs = require('fs');
var path = require('path');
var _ = require('underscore');
var contents = fs.readFileSync(__dirname + '/../../packages/rocketchat-lib/i18n/en.i18n.json', 'utf-8');
var keys = _.keys(JSON.parse(contents));
// var keys = _.keys(JSON.parse(contents)).filter(function(key) { return ['_Description', '_male', '_female', 'theme-color-'].every(function(word) { return key.indexOf(word) === -1; }); });
var keysFound = [];
function inspectFile(key, contents) {
if (contents && contents.indexOf(key) !== -1) {
return true;
}
}
function ignoreFunc(file) {
if (['/.meteor/', '/node_modules/', '/moment-locales/'].some(function(word) { return file.indexOf(word) !== -1; })) {
return true;
}
var ext = path.extname(file);
return ext !== '.coffee' && ext !== '.js' && ext !== '.html';
}
var walk = function(dir, done) {
var results = [];
fs.readdir(dir, function(err, list) {
if (err) {
return done(err);
}
var pending = list.length;
if (!pending) {
return done(null, results);
}
list.forEach(function(file) {
file = path.resolve(dir, file);
fs.stat(file, function(err, stat) {
if (stat && stat.isDirectory()) {
walk(file, function(err, res) {
results = results.concat(res);
if (!--pending) {
done(null, results);
}
});
} else {
if (!ignoreFunc(file)) {
results.push(file);
}
if (!--pending) {
done(null, results);
}
}
});
});
});
};
walk(__dirname + '/../..', function(err, files) {
if (err) {
throw err;
}
files.forEach(function(file) {
contents = fs.readFileSync(file, 'utf-8');
var searchKeys = _.difference(keys, keysFound);
searchKeys.forEach(function(key) {
if (inspectFile(key, contents)) {
keysFound.push(key);
}
});
});
console.log(_.difference(keys, keysFound));
});