summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorthe lemons <citrons@mondecitronne.com>2021-03-31 00:23:01 -0500
committerthe lemons <citrons@mondecitronne.com>2021-03-31 00:23:01 -0500
commitc8e422eb258451640c9692b61b6261a8f1f0f549 (patch)
treeeface10c50ec7498a633a395d0828171b0650949
parent80a74d4709a30db3012d8131ebe9fa83fa910e8f (diff)
language support things
-rw-r--r--game.js39
-rw-r--r--index.html1
-rw-r--r--lang.js111
3 files changed, 122 insertions, 29 deletions
diff --git a/game.js b/game.js
index a8c8eb5..a248c4d 100644
--- a/game.js
+++ b/game.js
@@ -1,32 +1,13 @@
+
(()=>{
var root = document.body;
const cdata = {
- thing: {
- singular:"thing",
- plural:"things",
- color:"lime",
- },
- apioform: {
- singular:"apioform",
- plural:"apioforms",
- color:"yellow",
- },
- violetstar: {
- singular:"violet star",
- plural:"violet stars",
- color:"#8050FF",
- },
- undefinedium: {
- singular:"undefinedium",
- plural:"undefinedium",
- color:"#FF00FF",
- },
- four: {
- singular:"four",
- plural:"fours",
- color:"#3040FF",
- },
+ thing: { color:"lime" },
+ apioform: { color:"yellow" },
+ violetstar: { color:"#8050FF" },
+ undefinedium: { color:"#FF00FF" },
+ four: { color:"#3040FF" },
}
let sdata;
@@ -53,17 +34,17 @@
view: ()=>{
return m("button",{
onclick:()=>{if (!sdata.autothing) am.thing.amount+=1}
- },sdata.autothing?"Unavailable":"Attain a thing");
+ },sdata.autothing?get_msg('unavailable'):get_msg('attain_a_thing'));
}
}
var AutoThing = {
view: ()=>{
return m("button",{onclick:()=>sdata.autothing = !sdata.autothing},[
- "AutoThing™ ",
+ get_msg('autothing'),
m("span",{
style:"color:"+(sdata.autothing?"lime":"grey")+";"},
- sdata.autothing?"ON":"OFF"),
+ sdata.autothing?get_msg('on'):get_msg('off')),
]);
}
}
@@ -115,7 +96,7 @@
m(CIcon,{currency:a.currency}),
m(".currencycount",{
style:"color:"+cdata[a.currency].color},
- a.amount==undefined?"oh bee something broke":a.amount),
+ a.amount==undefined?get_msg('something_broke'):a.amount),
]);
}
}
diff --git a/index.html b/index.html
index 5305b13..4c6664b 100644
--- a/index.html
+++ b/index.html
@@ -45,6 +45,7 @@
</head>
<body>
<script src="mithril.js"></script>
+ <script src="lang.js"></script>
<script src="game.js"></script>
</body>
</html>
diff --git a/lang.js b/lang.js
new file mode 100644
index 0000000..7639508
--- /dev/null
+++ b/lang.js
@@ -0,0 +1,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);
+}