update unused translations script more:

* fine-tune search by excluding more search patterns
* print more context when sensible
* sort keys alphabetically
pull/1/head
ansuz 4 years ago
parent 3424a2c96f
commit 9a42df3e08

@ -39,12 +39,16 @@ var grep = function (pattern, cb) {
'LICENSE', 'LICENSE',
'package*.json', 'package*.json',
'www/debug/chainpad.dist.js', 'www/debug/chainpad.dist.js',
'www/pad/mathjax/MathJax.js', 'www/pad/mathjax/*',
'www/common/hyperscript.js', 'www/common/hyperscript.js',
'www/common/jscolor.js', 'www/common/jscolor.js',
'.//scripts/*', './/scripts/*',
'./lib/*', './lib/*',
'./docs/*', './docs/*',
'./github/*',
'*.svg',
'*.md',
'./config/*',
].map(function (patt) { ].map(function (patt) {
return "':(exclude)" + patt + "'"; return "':(exclude)" + patt + "'";
}).join(' '); }).join(' ');
@ -58,18 +62,18 @@ var grep = function (pattern, cb) {
if (isPossiblyGenerated(pattern)) { if (isPossiblyGenerated(pattern)) {
return cb(void 0, true, 'POSSIBLY_GENERATED'); return cb(void 0, true, 'POSSIBLY_GENERATED');
} }
return cb(void 0, true, "NOT_FOUND"); return cb(void 0, true, "NOT_FOUND", stdout);
} }
stdout = ignoreLines(stdout, /Binary file/); stdout = ignoreLines(stdout, /Binary file/);
if (err) { if (err) {
if (err.code === 'ERR_CHILD_PROCESS_STDIO_MAXBUFFER') { if (err.code === 'ERR_CHILD_PROCESS_STDIO_MAXBUFFER') {
return cb(void 0, true, 'TOO_MUCH'); return cb(void 0, true, 'TOO_MUCH', stdout);
} }
return void cb(err); return void cb(err);
} }
if (/data\-localization/.test(stdout)) { if (/data\-localization/.test(stdout)) {
return cb(void 0, true, "DATA_LOCALIZATION"); return cb(void 0, true, "DATA_LOCALIZATION", stdout);
} }
if (/(Messages|Msg|messages)\./.test(stdout)) { if (/(Messages|Msg|messages)\./.test(stdout)) {
return cb(void 0, false); return cb(void 0, false);
@ -80,11 +84,31 @@ var grep = function (pattern, cb) {
}); });
}; };
var keys = Object.keys(Messages); var keys = Object.keys(Messages).sort();
var total = keys.length; var total = keys.length;
var limit = total; var limit = total;
var lineCount = function (s) {
var i = 0;
s.replace(/\n/g, function () { i++; return ''; });
return i;
};
var conditionallyPrintContent = function (output) {
if (!output) { return; }
if (lineCount(output) < 12) {
output.split('\n').map(function (line) {
if (!line) { return; }
console.log('\t> ' + line);
});
//console.log(output);
console.log();
} else {
console.log("\t> too much content to print");
}
};
var next = function () { var next = function () {
var key = keys[0]; var key = keys[0];
if (!key) { return; } if (!key) { return; }
@ -100,10 +124,11 @@ var next = function () {
} else if (!flagged) { } else if (!flagged) {
} else if (reason === 'OTHER') { } else if (reason === 'OTHER') {
console.log('[%s] flagged for [OTHER]', key, output); console.log('[%s] flagged for [OTHER]', key);
console.log(); conditionallyPrintContent(output);
} else { } else {
console.log("[%s] flagged for [%s]", key, reason || '???'); console.log("[%s] flagged for [%s]", key, reason || '???');
conditionallyPrintContent(output);
} }
next(); next();

Loading…
Cancel
Save