-
Notifications
You must be signed in to change notification settings - Fork 252
/
explore.html
246 lines (217 loc) · 9.99 KB
/
explore.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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Dododex Translations</title>
<link href="https://www.dododex.com/css/style.css" rel="stylesheet">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
<script src="translations.js"></script>
<script>
window.onload = function() {
function translate() {
var key = document.getElementById("key").value;
var translations = document.getElementById("translations");
translations.innerHTML = `<tr>
<td width="18%" class="bold light cap right smaller uppercase">Language</th>
<td width="82%" class="bold light cap left smaller uppercase">Translation</th>
</tr>`;
for (var lang in window.translations) {
if (window.translations.hasOwnProperty(lang)) {
var translation = document.createElement("tr");
translation.innerHTML = '<td class="light right">' + lang + "</td><td>" + (window.translations[lang][key] == null ? '<span class="neg">MISSING</span>' : window.translations[lang][key]) + '</td>';
translations.appendChild(translation);
}
}
}
function lookUpLanguage() {
var language = document.getElementById("language").value;
var languageTable = document.getElementById("languageTranslations");
languageTable.innerHTML = `<tr>
<td width="18%" class="bold light cap right smaller uppercase">Translation Key</td>
<td width="41%" class="bold light cap left smaller uppercase">English</td>
<td width="41%" class="bold light cap left smaller uppercase">${language}</td>
</tr>`;
for (var key in window.translations.en) {
if (window.translations.en.hasOwnProperty(key)) {
var englishText = window.translations.en[key];
var translatedText = window.translations[language] && window.translations[language][key] ? window.translations[language][key] : '<span class="neg">MISSING</span>';
var row = document.createElement("tr");
row.innerHTML = `<td class="light right">${key}</td><td>${englishText}</td><td>${translatedText}</td>`;
languageTable.appendChild(row);
}
}
}
var keyInput = document.getElementById("key");
keyInput.addEventListener("input", translate);
var languageInput = document.getElementById("language");
languageInput.addEventListener("change", lookUpLanguage);
// Count total number of translations
var totalLanguages = Object.keys(window.translations).length;
var totalEnKeys = Object.keys(window.translations.en).length;
totalTranslated = 0;
// Display percentage translated for each language
var langList = document.getElementById("langList");
for (var lang in window.translations) {
if (window.translations.hasOwnProperty(lang)) {
var numTranslated = Object.keys(window.translations[lang]).filter(function(key) {
return window.translations[lang][key] !== null;
}).length;
var totalKeys = Object.keys(window.translations[lang]).length;
var percentage = Math.round(numTranslated / totalKeys * 100);
// Add progress bar for the language
var progressBar = `
<tr style="${percentage >= 100 && "color:#BF7 !important"}">
<td class="right">
<span class="light">${lang}</span>
</td>
<td class="right">
${languages[lang].name}
</td>
<td class="right">
${percentage}%
</td>
<td class="small light marginLeftS marginRightS right">${numTranslated} / ${totalKeys != totalEnKeys ? '<span class="neg">' + totalKeys + '</span>' : totalKeys}</td>
<td>
<div class="miniBarWrap rowItem flex3">
<div class="miniBar" style="width:${percentage}%;${percentage >= 100 && "background-color:#BF7"}"></div>
</div>
</td>
</tr>`;
totalTranslated += numTranslated;
langList.innerHTML += progressBar;
}
}
// Stats
percentTranslated = Math.round((totalTranslated / (totalLanguages * totalEnKeys) * 1000))/10;
document.getElementById("stats").innerHTML = `
<div class="miniBarWrap marginBottom" style="background-color:var(--neg)">
<div class="miniBar" style="width:${percentTranslated}%;background-color:var(--action)"></div>
</div>
<div class="row marginBottom2">
<div class="rowItem">
<div class="bigNum bold actionColor">${percentTranslated}%</div>
<div class="actionColor marginTopS">TRANSLATED</div>
</div>
<div class="rowItem center">
<div class="bigNum">${totalLanguages}</div>
<div class="light marginTopS">TOTAL LANGUAGES</div>
</div>
<div class="rowItem right">
<div class="bigNum neg">${(totalLanguages * totalEnKeys) - totalTranslated}</div>
<div class="neg light marginTopS">MISSING TRANSLATIONS</div>
</div>
</div>
`
// Find missing or unused keys
var numIssues = 0;
for (var lang in translations) {
// Skip the "en" language
if (lang === "en") {
continue;
}
// Get the keys for the current language and the "en" language
var langKeys = Object.keys(translations[lang]);
var enKeys = Object.keys(translations.en);
// Find any missing keys (in the "en" object but not in the current language object)
var missingKeys = enKeys.filter(function(key) {
return langKeys.indexOf(key) === -1;
});
// Find any unnecessary keys (in the current language object but not in the "en" object)
var unnecessaryKeys = langKeys.filter(function(key) {
return enKeys.indexOf(key) === -1;
});
if(missingKeys.length == 0 && unnecessaryKeys.length == 0){
continue;
}
numIssues++;
// Generate the HTML list for this language
var html = "<tr><td>" + languages[lang].name + " (" + lang + ")</td><td>";
if (missingKeys.length > 0) {
html += "<ol class=\"small normallist\">";
missingKeys.forEach(function(key) {
html += "<li>" + key + "</li>";
});
html += "</ol>";
}
html += "</td>";
if (unnecessaryKeys.length > 0) {
html += "<td><ol class=\"small normallist\">";
unnecessaryKeys.forEach(function(key) {
html += "<li>" + key + "</li>";
});
html += "</ol>";
}
html += "</td></tr>";
document.getElementById("misMatched").innerHTML += html;
}
// Hide section if there's none.
if(numIssues == 0){
document.getElementById("misMatchedHolder").remove();
}
// Autocomplete possible keys
var keys = Object.keys(window.translations.en);
var keyInput = document.getElementById("key");
var keyList = document.createElement("datalist");
keyList.id = "key-list";
keys.forEach(function(key) {
var keyOption = document.createElement("option");
keyOption.value = key;
keyList.appendChild(keyOption);
});
keyInput.setAttribute("list", "key-list");
document.body.appendChild(keyList);
};
</script>
</head>
<body>
<header id="dodoheader">
<div class="wrap">
<div><a class="button marginTop" href="./">← Back to GitHub</a></div>
<h1 class="center">Dododex Translation Browser</h1>
</div>
</header>
<div class="wrap marginBottom2">
<h2 class="marginTop2">Look Up a Language</h2>
<select id="language" class="whiteinput">
<option value="">Select a language</option>
<script>
for (var lang in window.translations) {
if (window.translations.hasOwnProperty(lang)) {
document.write('<option value="' + lang + '">' + languages[lang].name + ' (' + lang + ')</option>');
}
}
</script>
</select>
<table class="btable marginTop" width="100%" id="languageTranslations"></table>
<h2 class="marginTop2">Look Up a Phrase</h2>
<input class="whiteinput" type="text" id="key" name="key" list="key-list" onchange="translate()" size="30" placeholder="Enter a key" />
<table class="btable marginTop" width="100%" id="translations">
</table>
<div class="lightbox marginTop2">
<h2 class="marginTop0">Progress</h2>
<div id="stats"></div>
<table class="btable marginTop" width="100%">
<tr>
<td width="10%" class="bold light cap right smaller uppercase">Language</td>
<td width="10%" class="bold light cap right smaller uppercase">Name</td>
<td width="10%" class="bold light cap right smaller uppercase">%</td>
<td width="10%" class="bold light cap right smaller uppercase">Keys</td>
<td width="60%" class="bold light cap left smaller uppercase">Progress</td>
</tr>
<tbody id="langList"></tbody>
</table>
</div>
<div id="misMatchedHolder">
<h3 class="neg">Mismatched Keys</h3>
<table class="btable marginTop" width="100%">
<tr>
<td width="10%" class="bold light cap right smaller uppercase">Language</td>
<td width="45%" class="bold light cap left smaller uppercase">Missing</td>
<td width="45%" class="bold light cap left smaller uppercase">Unused</td>
</tr>
<tbody id="misMatched"></tbody>
</table>
</div>
</div>
</body>
</html>