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
|
String.prototype.format = function () {
var r = this;
for (arg of arguments) r = r.replace('♯',arg);
return r;
};
/*
the languages thing holds all of the message things.
each message thing holds:
* things: the names of the collectable things in the languages
the values are fed to number_handler to get the string
* messages: all of the interface strings
* number_handler: a function to handle grammatical number features
*/
var languages = {
en: {
things: {
thing: {
singular:"thing",
plural:"things",
},
apioform: {
singular:"apioform",
plural:"apioforms",
},
violetstar: {
singular:"violet star",
plural:"violet stars",
},
undefinedium: {
singular:"undefinedium",
plural:"undefinedium",
},
four: {
singular:"four",
plural:"fours",
},
},
messages: {
unavailable: "Unavailable",
attain_a_thing: "Attain a thing",
autothing: "AutoThing™ ",
on: "ON",
off: "OFF",
something_broke: "oh bee something broke",
},
number_handler: function (thing,n) {
if (n === undefined) return thing.singular;
else if (n == 1) return `{n} {thing.singular}`;
else return `{n} {thing.plural}`;
}
},
tp: {
things: {
thing: 'ijo',
apioform: 'pipi',
violetstar: 'suno pi laso loje',
undefinedium: 'undefinedium',
four: 'po'
},
messages: {
unavailable: "ken ala",
attain_a_thing: "o kama jo e ijo",
autothing: "IloIjo™ ",
on: "PALI",
off: "PALI ALA",
something_broke: "pipi a- pakala li lon"
},
number_handler: function (thing,n) {
if (n == undefined) return thing;
// "x pi y z" should become "x n pi y z", not "x pi y z n"
if (thing.test(/\spi\s/)) {
return thing.replace(/\spi\s/, " {n} pi ");
}
else return `{thing} {n}`;
}
}
};
var messages = languages.en;
function set_language(lang) {
if (lang in Object.keys(languages))
messages = langauges[lang];
else
messages = languages.en;
}
function get_msg(id) {
if (messages.messages[id] == undefined) {
if (languages.en.messages[id] == undefined) return id;
else return languages.en.messages[id];
} else return messages.messages[id];
}
// thing_text(thing) -> get text for name of thing
// thing_text(thing,n) -> get label text for n things
function thing_text(thing,n) {
let source;
if (thing in Object.keys(messages))
source = lang;
else // fallback on english
source = languages.en;
let thing_data = source[thing];
if (thing == undefined) // ultimate fallback on identifier
return (n == undefined) ? thing : `{n} {thing}`;
return source.number_handler(thing_data, n);
}
|