forked from dododex/translations
-
Notifications
You must be signed in to change notification settings - Fork 0
/
explore.html
196 lines (173 loc) · 7.69 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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Dododex Translations</title>
<link href="https://www.dododex.com/css/style.css" rel="stylesheet">
<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="10%" class="bold light cap right smaller uppercase">Language</th>
<td width="90%" 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);
}
}
}
var keyInput = document.getElementById("key");
keyInput.addEventListener("input", translate);
// 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">
${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>" + 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>
<div class="wrap marginBottom2" style="max-width:700px;">
<a class="button marginTop" href="./">← Back to GitHub</a>
<h1>Dododex Translation Browser</h1>
<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>
<h2>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">%</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 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>