-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathstring.js
More file actions
93 lines (78 loc) · 2.35 KB
/
string.js
File metadata and controls
93 lines (78 loc) · 2.35 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
const fs = require('fs');
function sortObjectKeys(obj) {
return Object.fromEntries(Object.entries(obj).sort((a, b) => a[0].localeCompare(b[0])));
}
function discardGarbage(lines) {
while (lines.length && ![
'A4Q2ExpansionSuccessTyrael',
'Cutthroat1',
'WarrivAct1IntroGossip1',
].includes(lines[0])) {
lines.shift();
}
return lines;
}
function processLanguage(lang) {
let strings = {};
[
'string.tbl',
'expansionstring.tbl',
'patchstring.tbl',
].forEach(name => {
console.log('Processing: ', lang, name);
let lines = discardGarbage(fs.readFileSync('tbl/' + lang + '/' + name).toString().split('\0'));
while (lines.length) {
let key = lines.shift(), str = lines.shift();
if (key.trim().length) {
strings[key.trim()] = str;
}
}
});
fs.writeFileSync('./json/localestrings-' + lang + '.json', JSON.stringify(sortObjectKeys(strings), null, ' '));
return strings;
}
[
'chi',
'deu',
'esp',
'fra',
'ita',
'kor',
'pol',
].forEach(processLanguage);
let allStrings = processLanguage('eng');
[
'tbl/strings/bnet.json',
'tbl/strings/chinese-overlay.json',
'tbl/strings/commands.json',
'tbl/strings/item-gems.json',
'tbl/strings/item-modifiers.json',
'tbl/strings/item-nameaffixes.json',
'tbl/strings/item-names.json',
'tbl/strings/item-runes.json',
'tbl/strings/keybinds.json',
'tbl/strings/levels.json',
'tbl/strings/mercenaries.json',
'tbl/strings/monsters.json',
'tbl/strings/npcs.json',
'tbl/strings/objects.json',
'tbl/strings/presence-states.json',
'tbl/strings/quests.json',
'tbl/strings/shrines.json',
'tbl/strings/skills.json',
'tbl/strings/ui-controller.json',
'tbl/strings/ui.json',
'tbl/strings/vo.json',
].forEach(filename => {
console.log('Reading: ', filename);
let data = JSON.parse(fs.readFileSync(filename).toString().trim());
data.forEach(entry => {
if (entry.Key && entry.enUS) {
if (entry.Key in allStrings) {
console.warn('Duplicate key: ', entry.Key);
}
allStrings[entry.Key] = entry.enUS;
}
});
});
fs.writeFileSync('./json/allstrings-eng.json', JSON.stringify(sortObjectKeys(allStrings), null, ' '));