forked from MetaMask/metamask-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmissing-locale-strings.js
executable file
·79 lines (69 loc) · 2.25 KB
/
missing-locale-strings.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
72
73
74
75
76
77
78
79
#!/usr/bin/env node
// //////////////////////////////////////////////////////////////////////////////
//
// Reports on missing localized strings
//
// usage:
//
// node app/scripts/missing-locale-strings.js [<locale>] [--verbose]
//
// This script will report on any missing localized strings. It will compare the
// chosen locale (or all locales, if none is chosen) with the `en` locale, and
// report the coverage percentage.
//
// The optional '--verbose' argument will print the key for each localized string
// to the console.
//
// //////////////////////////////////////////////////////////////////////////////
const log = require('loglevel');
const localeIndex = require('../app/_locales/index.json');
const { compareLocalesForMissingItems, getLocale } = require('./lib/locales');
log.setDefaultLevel('info');
let verbose = false;
let specifiedLocale;
for (const arg of process.argv.slice(2)) {
if (arg === '--verbose') {
verbose = true;
} else {
specifiedLocale = arg;
}
}
main().catch((error) => {
log.error(error);
process.exit(1);
});
async function main() {
if (specifiedLocale === 'en') {
throw new Error(
`Can't compare 'en' locale to itself to find missing messages`,
);
} else if (specifiedLocale) {
await reportMissingMessages(specifiedLocale);
} else {
const localeCodes = localeIndex
.filter((localeMeta) => localeMeta.code !== 'en')
.map((localeMeta) => localeMeta.code);
for (const code of localeCodes) {
await reportMissingMessages(code);
}
}
}
async function reportMissingMessages(code) {
const englishLocale = await getLocale('en');
const targetLocale = await getLocale(code);
const missingItems = compareLocalesForMissingItems({
base: englishLocale,
subject: targetLocale,
});
const englishEntryCount = Object.keys(englishLocale).length;
const coveragePercent =
(100 * (englishEntryCount - missingItems.length)) / englishEntryCount;
log.info(`**${code}**: ${coveragePercent.toFixed(2)}% coverage`);
if (missingItems.length && verbose) {
console.log(`**${code}**: ${missingItems.length} missing messages`);
log.info('Extra items that should not be localized:');
missingItems.forEach(function (key) {
log.info(` - [ ] ${key}`);
});
}
}