forked from stream-labs/desktop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
search-untranslated.js
67 lines (45 loc) · 1.61 KB
/
search-untranslated.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
/**
* Run this script to find the strings that missed in localization dictionaries.
*/
const searchExp = /\$t\(([\'\`\"])([ a-zA-Z\d\-_`@%;:,'’=&!~#\\\+\*\?\.\}\{\(\)\[\]\$\<\>/]+?)\1\)/gm;
const fs = require('fs');
const recursive = require('recursive-readdir');
(async function main() {
const dictionary = {};
// load dictionary
const dictionaryFiles = await recursive('./app/i18n/en-US', ['*.txt']);
dictionaryFiles.forEach(filePath => {
let fileDictionary;
try {
fileDictionary = JSON.parse(fs.readFileSync(filePath).toString());
} catch (e) {
console.log('parse error for', filePath);
process.exit(1);
}
Object.assign(dictionary, fileDictionary);
});
const sourceFiles = await recursive('./app', ['*.txt']);
// check missed strings in the sources files
sourceFiles.forEach(filePath => {
const foundStrings = [];
const missedStrings = [];
const fileContent = fs.readFileSync(filePath).toString();
let match;
while ((match = searchExp.exec(fileContent))) {
let string = match[2];
string = string.replace('\\', '');
if (!foundStrings.includes(string)) foundStrings.push(string);
}
foundStrings.forEach(str => {
if (dictionary[str] || missedStrings.includes(str)) return;
missedStrings.push(str);
});
if (!missedStrings.length) return;
console.log(`missed strings found in ${filePath}`);
const missedStringsMap = {};
missedStrings.forEach(missedString => {
missedStringsMap[missedString] = missedString;
});
console.log(JSON.stringify(missedStringsMap, null, 4));
});
})();