Added unused translations counter
This commit is contained in:
63
scripts/translations/unused.js
Normal file
63
scripts/translations/unused.js
Normal file
@@ -0,0 +1,63 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const SRC_DIR = '../../client/src/'
|
||||
const LOCALES_DIR = '../../client/src/__locales';
|
||||
const BASE_FILE = path.join(LOCALES_DIR, 'en.json');
|
||||
|
||||
// Strings that may be found by the algorithm,
|
||||
// but in fact they are used.
|
||||
const KNOWN_USED_STRINGS = {
|
||||
'blocking_mode_refused': true,
|
||||
'blocking_mode_nxdomain': true,
|
||||
'blocking_mode_custom_ip': true,
|
||||
}
|
||||
|
||||
function traverseDir(dir, callback) {
|
||||
fs.readdirSync(dir).forEach(file => {
|
||||
let fullPath = path.join(dir, file);
|
||||
if (fs.lstatSync(fullPath).isDirectory()) {
|
||||
traverseDir(fullPath, callback);
|
||||
} else {
|
||||
callback(fullPath);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const contains = (key, files) => {
|
||||
for (let file of files) {
|
||||
if (file.includes(key)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
const main = () => {
|
||||
const baseLanguage = require(BASE_FILE);
|
||||
const files = [];
|
||||
|
||||
traverseDir(SRC_DIR, (path) => {
|
||||
const canContain = (path.endsWith('.js') || path.endsWith('.json')) &&
|
||||
!path.includes(LOCALES_DIR);
|
||||
|
||||
if (canContain) {
|
||||
files.push(fs.readFileSync(path).toString());
|
||||
}
|
||||
});
|
||||
|
||||
const unused = [];
|
||||
for (let key in baseLanguage) {
|
||||
if (!contains(key, files) && !KNOWN_USED_STRINGS[key]) {
|
||||
unused.push(key);
|
||||
}
|
||||
}
|
||||
|
||||
console.log('Unused keys:');
|
||||
for (let key of unused) {
|
||||
console.log(key);
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
Reference in New Issue
Block a user