-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathi18n.js
51 lines (43 loc) · 1.31 KB
/
i18n.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
var lang = 'chs';
var langs;
if (location.hash[0] == '#') lang = location.hash.substr(1);
function getString(key) {
if (langs[key] == undefined) return undefined;
return langs[key][lang];
}
function setLang(newlang) {
if (['chs', 'cht'].indexOf(lang) == -1) return false;
var oldlang = lang;
lang = newlang;
updateImg(oldlang, lang);
updateStrings();
setResult();
genTables();
$("button.i18n.filter.f1:empty[ftype!=rarity]").click();
filterChanged();
}
function updateImg(oldlang, newlang) {
for (var img of $("img.i18n").toArray()) {
img.src = img.src.replace(oldlang, newlang);
}
}
function updateStrings() {
for (var btn of $("button.i18n").toArray()) {
var ftype = btn.getAttribute('ftype');
var t = ftype.match(/^\d+$/) ? ingredientNames[lang][ftype] : getString(ftype);
btn.innerText = t ? t : '';
}
for (var ele of $(".i18n[label]").toArray()) {
ele.innerText = getString(ele.getAttribute('label'));
}
}
onhashchange = function() {
if (location.hash[0] == '#') setLang(location.hash.substr(1));
}
$(function() {
updateImg("chs", lang);
$("#server").click(function() {
if ($("#server img").attr("src").indexOf("chs") != -1) location.hash = "#cht";
else location.hash = "#chs";
});
})