-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathlangs.html
188 lines (150 loc) · 3.89 KB
/
langs.html
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<html lang="en">
<head>
<title>Language Verifier</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="utf-8">
<script src="https://code.jquery.com/jquery-3.6.0.slim.min.js" integrity="sha256-u7e5khyithlIdTpu22PHhENmPcRdFiHRjhAuHcs05RI=" crossorigin="anonymous"></script>
<script>
const languages = {
'en' : 'English',
// in alphabetical order
'de' : 'Deutsch',
'es-ES' : 'Español',
'fr-FR' : 'Français',
'it-IT' : 'Italiano',
'nl' : 'Nederlands',
'pl-PL' : 'Polski',
'pt-BR' : 'Português',
'tr-TR' : 'Türkçe',
'be-BY' : 'Беларуская',
'ru-RU' : 'Русский',
'ua-UA' : 'Українська',
'zh-CN' : '中文',
'ja-JP' : '日本語',
'vi-VN' : 'Tiếng Việt',
};
const special_space_handling = {
'ja-JP' : true,
};
var unpack_keys = ['items', 'enchants'];
var skip_keys = ['use_russain_plurals'];
var dicts = {};
var keys = {};
loadLangs();
async function loadLangs(){
// Load language data
for (const lang_id in languages){
dicts[lang_id] = await loadJsonLanguage(lang_id);
for (const str_id in dicts[lang_id]){
if (unpack_keys.includes(str_id)){
for (const str_id2 in dicts[lang_id][str_id]){
keys[str_id + '/' + str_id2] = 1;
}
}else{
keys[str_id] = 1;
}
}
}
for (var i=0; i<skip_keys.length; i++){
delete keys[skip_keys[i]];
}
var s_keys = Object.keys(keys);
s_keys.sort();
// build output table
var tb = $('table tbody');
var tr = $('<tr>');
var cell = $('<th>');
cell.text('ID');
tr.append(cell);
for (const lang_id in languages){
var cell = $('<th>');
cell.text(lang_id + ': ' + languages[lang_id]);
tr.append(cell);
}
tb.append(tr);
for (var i=0; i<s_keys.length; i++){
var key = s_keys[i];
var tr = $('<tr>');
var cell = $('<td>');
cell.text(key);
tr.append(cell);
var num_pre_spaces = 0;
var num_strs = 0;
for (const lang_id in languages){
var cell = $('<td>');
var val = dicts[lang_id][key];
if (key.includes('/')){
var parts = key.split('/');
val = dicts[lang_id][parts[0]][parts[1]];
}
// should we skip this string?
var skip_cell = false;
if (key.match(/_(s)$/) && dicts[lang_id].use_russain_plurals) skip_cell = true;
if (key.match(/_(low|high)$/) && !dicts[lang_id].use_russain_plurals) skip_cell = true;
if (skip_cell){
cell.text('not applicable');
cell.css('color', '#666');
cell.css('fontStyle', 'italic');
}else{
if (val === undefined){
cell.text('missing');
cell.css('backgroundColor', 'red');
}else{
var has_pre_space = (String(val).substring(0, 1) === ' ');
if (has_pre_space) val = '>>' + val;
cell.text(val);
num_strs++;
if (special_space_handling[lang_id]){
// skip space prefix processing for some languaes (e.g. japanese)
if (num_pre_spaces) num_pre_spaces++;
}else{
if (has_pre_space) num_pre_spaces++;
}
}
}
if (num_pre_spaces && num_pre_spaces != num_strs){
tr.css('backgroundColor', 'yellow');
}
tr.append(cell);
}
tb.append(tr);
}
//add_row(tb, ['a', 'b', 'c'], 1);
//add_row(tb, ['a', 'b', 'd']);
console.log(keys);
}
function loadJsonLanguage(language) {
const cache_key = Date.now();
return fetch('languages/'+language+'.json?'+cache_key)
.then(response => {
if (!response.ok) {
throw new Error('Can\'t load language file');
}
return response.json();
})
.then(data => {
return data;
})
.catch(error => {
console.error('Language file error:', error);
return null;
});
}
function add_row(tb, cells, header){
var tr = $('<tr>');
for (var i=0; i<cells.length; i++){
var td = header ? $('<th>') : $('<td>');
td.text(cells[i]);
tr.append(td);
}
tb.append(tr);
}
</script>
</head>
<body>
<table border="1">
<tbody>
</tbody>
</table>
</body>
</html>