forked from vgrizly/rogalik
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdict.js
76 lines (70 loc) · 2.14 KB
/
dict.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
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
dict.init = function() {
window.TT = function(text, args) {
text = T(text);
text.match(/{[^}]+}/g).forEach(function(v) {
text = text.replace(v, T(args[v.slice(1, -1)]));
});
return text;
};
window.TS = function(text) {
return T(text, true);
};
if (!game.config.language.Russian) {
dict.update = function(){};
window.T = function(text) {
return text;
};
return;
}
window.T = function(text, symbol) {
if (game.config.language.Russian) {
var info = Items[text];
if (info && info.name.ru)
return info.name.ru;
}
if (symbol)
text = util.symbolToString(text);
return dict[text] || text;
};
dict.update = function(elem) {
var list = {};
function update(elem) {
if (elem.nodeType == 3) {
var text = elem.textContent;
elem.textContent = T(text);
list[text] = elem.textContent;
} else if (elem.childNodes.length) {
[].forEach.call(elem.childNodes, update);
}
}
update(elem || document.body);
// console.log(JSON.stringify(list));
};
dict.update();
}
dict.getTranslations = function() {
for (var type in Entity.templates) {
var entity = Entity.templates[type];
var title = entity.title.replace(/\[.*$/, "");
if (!dict[title])
dict[title] = "";
for (var action in entity.getActions()) {
action = util.symbolToString(action);
if (action in dict)
continue;
dict[action] = "";
}
}
for (type in Entity.recipes) {
var recipe = Entity.recipes[type];
for (var kind in recipe.Ingredients) {
kind = util.symbolToString(kind);
if (!dict[kind])
dict[kind] = "";
}
}
var textarea = document.createElement("textarea");
textarea.value = JSON.stringify(dict);
var panel = new Panel("Translations", "translations", [textarea]);
panel.show();
};