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); }