From b0e0e919ee5d94a3a0d935018f08d3b0fa603245 Mon Sep 17 00:00:00 2001 From: 0neGal Date: Wed, 13 Apr 2022 22:38:18 +0200 Subject: the user can now manually select a language This allows someone to have their system in any language, and then have Viper in a separate language. This is also useful for testing. --- src/app/index.html | 29 +++++++++++++++++++++++++++-- src/app/main.css | 6 +++--- src/app/main.js | 2 ++ src/app/settings.js | 19 +++++++++++++++++++ src/lang.js | 11 ++++++++++- src/lang/en.json | 7 +++++++ src/lang/es.json | 2 ++ src/lang/fr.json | 2 ++ src/utils.js | 2 ++ 9 files changed, 74 insertions(+), 6 deletions(-) diff --git a/src/app/index.html b/src/app/index.html index 8ad5ecf..e0718a8 100644 --- a/src/app/index.html +++ b/src/app/index.html @@ -36,7 +36,7 @@
-

Northstar

+

%%gui.settings.title.ns%%

%%gui.settings.nsargs.title%% @@ -48,7 +48,32 @@
-

Updates

+

%%gui.settings.title.language%%

+
+
+ %%gui.settings.autolang.title%% +
+ %%gui.settings.autolang.desc%% +
+
+
+ +
+
+
+
+ %%gui.settings.forcedlang.title%% +
+ %%gui.settings.forcedlang.desc%% +
+
+
+ +
+
+

%%gui.settings.title.updates%%

%%gui.settings.autoupdate.title%% diff --git a/src/app/main.css b/src/app/main.css index 3f542ec..87d89e0 100644 --- a/src/app/main.css +++ b/src/app/main.css @@ -129,7 +129,7 @@ button { transition: 0.15s ease-in-out; } -.popup .el, .popup #search, .option .actions input, .popup #close, .popup .misc button { +.popup .el, .popup #search, .option .actions select, .option .actions input, .popup #close, .popup .misc button { color: white; display: flex; align-items: center; @@ -149,7 +149,7 @@ button { display: flex; } -.popup #search, .option .actions input { +.popup #search, .option .actions input, .option .actions select { border: none; outline: none; transition: filter 0.15s ease-in-out; @@ -292,7 +292,7 @@ button { margin-top: calc(var(--padding) / 3); } -.option .actions input { +.option .actions input, .option .actions select { width: 100%; margin: 0px; --spacing: calc(var(--padding) / 3); diff --git a/src/app/main.js b/src/app/main.js index 1688ab2..9206ae6 100644 --- a/src/app/main.js +++ b/src/app/main.js @@ -11,6 +11,8 @@ var settings = { nsargs: "", gamepath: "", nsupdate: true, + autolang: true, + forcedlang: "en", autoupdate: true, zip: "/northstar.zip", lang: navigator.language, diff --git a/src/app/settings.js b/src/app/settings.js index 902e57b..853cd0b 100644 --- a/src/app/settings.js +++ b/src/app/settings.js @@ -58,6 +58,8 @@ var Settings = { } else { opts[optName] = input; } + } else if (options[i].querySelector(".actions select")) { + opts[optName] = options[i].querySelector(".actions select").value; } else if (options[i].querySelector(".actions .switch")) { if (options[i].querySelector(".actions .switch.on")) { opts[optName] = true; @@ -74,6 +76,23 @@ var Settings = { for (let i = 0; i < options.length; i++) { let optName = options[i].getAttribute("name"); + if (optName == "forcedlang") { + let div = options[i].querySelector("select"); + + div.innerHTML = ""; + let langs = fs.readdirSync(__dirname + "/../lang"); + for (let i in langs) { + title = JSON.parse(fs.readFileSync(__dirname + `/../lang/${langs[i]}`, "utf8"))["lang.title"]; + if (title) { + div.innerHTML += `` + } + + } + + div.value = settings.forcedlang; + continue; + } + if (settings[optName] != undefined) { switch(typeof settings[optName]) { case "string": diff --git a/src/lang.js b/src/lang.js index 8174174..041ef35 100644 --- a/src/lang.js +++ b/src/lang.js @@ -7,8 +7,16 @@ var langObj = {}; function _loadTranslation() { if (fs.existsSync("viper.json")) { - lang = JSON.parse(fs.readFileSync("viper.json", "utf8")).lang; + opts = JSON.parse(fs.readFileSync("viper.json", "utf8")); + lang = opts.lang; + if (! lang) {lang = "en"} + + if (opts.autolang == false) { + lang = opts.forcedlang; + if (! lang) {lang = "en"} + } + if (! fs.existsSync(__dirname + `/lang/${lang}.json`)) { if (fs.existsSync(__dirname + `/lang/${lang.replace(/-.*$/, "")}.json`)) { lang = lang.replace(/-.*$/, ""); @@ -19,6 +27,7 @@ function _loadTranslation() { } else { lang = "en"; } + langObj = JSON.parse(fs.readFileSync(__dirname + `/lang/${lang}.json`, "utf8")); } diff --git a/src/lang/en.json b/src/lang/en.json index 8defc7d..501eadd 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -1,4 +1,6 @@ { + "lang.title": "English", + "cli.help.help": "shows this help message", "cli.help.debug": "opens the dev/debug tools", "cli.help.version": "outputs version info", @@ -82,9 +84,14 @@ "gui.settings.save": "Save", "gui.settings.discard": "Discard", "gui.settings.title.ns": "Northstar", + "gui.settings.title.language": "Language", "gui.settings.title.updates": "Updates", "gui.settings.nsargs.title": "Launch options", "gui.settings.nsargs.desc": "Here you can add launch options for Northstar/Titanfall.", + "gui.settings.autolang.title": "Auto-Detect Language", + "gui.settings.autolang.desc": "When enabled, Viper tries to automatically detect your system language, when disabled you can manually change the language below.", + "gui.settings.forcedlang.title": "Language", + "gui.settings.forcedlang.desc": "When \"Auto-Detect Language\" is disabled, this will decide the language. Requires a restart to take effect.", "gui.settings.autoupdate.title": "Viper Auto-Updates", "gui.settings.autoupdate.desc": "Viper will automatically keep itself up-to-date.", "gui.settings.nsupdate.title": "Northstar Auto-Updates", diff --git a/src/lang/es.json b/src/lang/es.json index a5b3685..18c00a5 100644 --- a/src/lang/es.json +++ b/src/lang/es.json @@ -1,4 +1,6 @@ { + "lang.title": "Spanish - Española", + "cli.help.help": "muestra este mensaje de ayuda", "cli.help.debug": "habre las herramientas de desarrollador/depuración ", "cli.help.version": "muestra la información de la versión", diff --git a/src/lang/fr.json b/src/lang/fr.json index c1797e4..018676c 100644 --- a/src/lang/fr.json +++ b/src/lang/fr.json @@ -1,4 +1,6 @@ { + "lang.title": "French - Français", + "cli.help.help": "affiche ce message d'aide", "cli.help.debug": "affiche les outils de développement", "cli.help.version": "retourne des informations sur la version du logiciel", diff --git a/src/utils.js b/src/utils.js index 7c1c22b..92197d1 100644 --- a/src/utils.js +++ b/src/utils.js @@ -23,6 +23,8 @@ var settings = { gamepath: "", lang: "en-US", nsupdate: true, + autolang: true, + forcedlang: "en", autoupdate: true, nsargs: "-multiple", zip: "/northstar.zip", -- cgit v1.2.3