diff --git a/suramadu/web/javascript/nls/en/msg.json b/suramadu/web/javascript/nls/en/msg.json new file mode 100644 index 0000000..6603e99 --- /dev/null +++ b/suramadu/web/javascript/nls/en/msg.json @@ -0,0 +1,3 @@ +{ + "dialog.startingDialog": "Loading combat simulation" +} diff --git a/suramadu/web/lang.js b/suramadu/web/lang.js new file mode 100644 index 0000000..c7516cd --- /dev/null +++ b/suramadu/web/lang.js @@ -0,0 +1,47 @@ +/* + * Pin the frontend's language to English, before Suramadu's loader reads it. + * + * The boot screen's status line is not in this repo's markup - the client + * builds that dialog itself and fills it from a message table compiled into + * the bundle. The supported way to change a string is to serve a translation + * file the client merges over that table, per key: + * + * javascript/nls/en/msg.json + * + * which is what suramadu/web/javascript/nls/en/msg.json is. No config change + * is needed for the server to find it. PrimaryUrlHandler routes anything under + * /javascript/nls to the app's langFolder first; that is unset here, so the + * lookup returns nothing and falls through to the web folder with the path + * intact - and the web folder is ours. + * + * The catch is which file the client asks for. It reads + * localStorage.webswingLang, falls back to navigator.language, and tries the + * result with the tag progressively shortened: en-US, then en, then it gives + * up. There is no locale-independent fallback. So a player on a de-DE browser + * asks for de, gets a 404, and sees upstream's "Starting your application" + * while everyone on an English browser sees ours - the kind of split nobody + * finds until a screenshot arrives from the wrong continent. + * + * Pinning the tag costs nothing to lose: the war ships no javascript/nls + * directory at all, so no locale resolves to a translation today, and every + * string in the bundle is English already. This only makes the file we do ship + * apply to everyone. + * + * Load order matters and is the one thing that can silently undo this: it must + * run before webswing-loader-stub.js, which is why index.html puts it directly + * above that tag rather than beside perf.js and flare.js at the end of the + * body. tests/shell/test-boot-screen.sh checks the order holds. + */ +(function () { + "use strict"; + try { + if (window.localStorage.getItem("webswingLang") !== "en") { + window.localStorage.setItem("webswingLang", "en"); + } + } catch (e) { + // Storage disabled or partitioned away. The client then falls back to + // navigator.language on its own, which is where it started; an English + // browser still gets our string, and any other sees upstream's default. + // Not worth failing the boot over. + } +})();