From 83469ae18e04c3e812c32c4e6a8dc10c9f74ee54 Mon Sep 17 00:00:00 2001 From: Alystrasz Date: Fri, 7 Jan 2022 21:42:21 +0100 Subject: [fix] loading up translation object each time a translation is needed --- src/lang.js | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/lang.js b/src/lang.js index b3cbb43..3e0ca42 100644 --- a/src/lang.js +++ b/src/lang.js @@ -1,35 +1,34 @@ const fs = require("fs"); -var lang = "en"; // Default language +const enLang = JSON.parse(fs.readFileSync(__dirname + `/lang/en.json`, "utf8")); +let lang = "en"; +var langObj = {}; -// Loads fallback/default language strings -var langDef = JSON.parse(fs.readFileSync(__dirname + `/lang/en.json`, "utf8")); -// If settins are set it'll try to set the language to that instead of -// the default, however if it can't find it, it'll still fallback to the -// default language. This might happen as the default language is -// retrieved from the renderer's navigator.language, which may have -// languages we don't support yet. -if (fs.existsSync("viper.json")) { - lang = JSON.parse(fs.readFileSync("viper.json", "utf8")).lang; - if (! lang) {lang = "en"} // Uses fallback, if language isn't set - if (! fs.existsSync(__dirname + `/lang/${lang}.json`)) { - if (fs.existsSync(__dirname + `/lang/${lang.replace(/-.*$/, "")}.json`)) { - lang = lang.replace(/-.*$/, ""); - } else { - lang = "en"; // Uses fallback if language doesn't exist +function _loadTranslation() { + if (fs.existsSync("viper.json")) { + lang = JSON.parse(fs.readFileSync("viper.json", "utf8")).lang; + if (! lang) {lang = "en"} + if (! fs.existsSync(__dirname + `/lang/${lang}.json`)) { + if (fs.existsSync(__dirname + `/lang/${lang.replace(/-.*$/, "")}.json`)) { + lang = lang.replace(/-.*$/, ""); + } else { + lang = "en"; + } } } + langObj = JSON.parse(fs.readFileSync(__dirname + `/lang/${lang}.json`, "utf8")); } -var langObj = JSON.parse(fs.readFileSync(__dirname + `/lang/${lang}.json`, "utf8")); module.exports = (string) => { - if (langObj[string]) { // Returns string from language + _loadTranslation(); + + if (langObj[string]) { return langObj[string]; - } else { // If string doesn't exist - if (langDef[string]) { // Retrieves from default lang instead - return langDef[string]; + } else { + if (enLang[string]) { + return enLang[string]; } else { // If it's not in the default lang either, it returns the // string, this is absolute fallback. -- cgit v1.2.3 From 17947210b3fc9bac6ea2219655c73af07113690e Mon Sep 17 00:00:00 2001 From: Alystrasz Date: Sat, 8 Jan 2022 15:00:38 +0100 Subject: [fix] translation file is only loaded is current context didn't set up lang variable --- src/lang.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/lang.js b/src/lang.js index 3e0ca42..8174174 100644 --- a/src/lang.js +++ b/src/lang.js @@ -1,7 +1,7 @@ const fs = require("fs"); const enLang = JSON.parse(fs.readFileSync(__dirname + `/lang/en.json`, "utf8")); -let lang = "en"; +let lang = ""; var langObj = {}; @@ -16,13 +16,16 @@ function _loadTranslation() { lang = "en"; } } + } else { + lang = "en"; } langObj = JSON.parse(fs.readFileSync(__dirname + `/lang/${lang}.json`, "utf8")); } module.exports = (string) => { - _loadTranslation(); + if (lang === "") + _loadTranslation(); if (langObj[string]) { return langObj[string]; -- cgit v1.2.3 From 848772b53a47eeb6e921e2a186332dbc2a95aadf Mon Sep 17 00:00:00 2001 From: Remy Raes Date: Mon, 21 Feb 2022 21:29:34 +0100 Subject: [fix] updates checking order --- src/utils.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/utils.js b/src/utils.js index 2ea91cd..336017f 100644 --- a/src/utils.js +++ b/src/utils.js @@ -73,9 +73,9 @@ async function isGameRunning() { // // It uses isGameRunning() to ensure it doesn't run while the game is // running, as that may have all kinds of issues. -northstar_auto_updates: { +function handleNorthstarAutoUpdating() { if (!settings.autoupdate || !fs.existsSync("viper.json") || settings.gamepath.length === 0) { - break northstar_auto_updates; + return; } async function _checkForUpdates() { @@ -306,7 +306,11 @@ function updatevp(autoinstall) { } autoUpdater.on("error", (info) => {cli.exit(1)}); - autoUpdater.on("update-not-available", (info) => {cli.exit()}); + autoUpdater.on("update-not-available", (info) => { + // only check for N* updates if Viper itself has no updates + handleNorthstarAutoUpdating(); + cli.exit(); + }); autoUpdater.checkForUpdatesAndNotify(); } -- cgit v1.2.3