From 66efac703519b2ff68cf53333facc672f891ab1f Mon Sep 17 00:00:00 2001 From: Kamesuta Date: Wed, 27 Sep 2023 01:37:41 +0900 Subject: [PATCH] cascadable langloader --- app/assets/js/langloader.js | 11 ++++++++++- app/assets/js/preloader.js | 2 +- app/assets/js/scripts/landing.js | 2 +- app/settings.ejs | 2 +- index.js | 4 ++-- package.json | 1 + 6 files changed, 16 insertions(+), 6 deletions(-) diff --git a/app/assets/js/langloader.js b/app/assets/js/langloader.js index a4bacbe1..c023aed6 100644 --- a/app/assets/js/langloader.js +++ b/app/assets/js/langloader.js @@ -1,11 +1,12 @@ const fs = require('fs-extra') const path = require('path') const toml = require('toml') +const merge = require('lodash.merge') let lang exports.loadLanguage = function(id){ - lang = toml.parse(fs.readFileSync(path.join(__dirname, '..', 'lang', `${id}.toml`))) || {} + lang = merge(lang || {}, toml.parse(fs.readFileSync(path.join(__dirname, '..', 'lang', `${id}.toml`))) || {}) } exports.query = function(id, placeHolders){ @@ -29,4 +30,12 @@ exports.queryJS = function(id, placeHolders){ exports.queryEJS = function(id, placeHolders){ return exports.query(`ejs.${id}`, placeHolders) +} + +exports.setupLanguage = function(){ + // Load Language Files + exports.loadLanguage('en_US') + + // Uncomment this when translations are ready + //exports.loadLanguage('xx_XX') } \ No newline at end of file diff --git a/app/assets/js/preloader.js b/app/assets/js/preloader.js index ae01bb83..95ead733 100644 --- a/app/assets/js/preloader.js +++ b/app/assets/js/preloader.js @@ -23,7 +23,7 @@ DistroAPI['commonDir'] = ConfigManager.getCommonDirectory() DistroAPI['instanceDir'] = ConfigManager.getInstanceDirectory() // Load Strings -LangLoader.loadLanguage('en_US') +LangLoader.setupLanguage() /** * diff --git a/app/assets/js/scripts/landing.js b/app/assets/js/scripts/landing.js index b675cea9..06d29ecb 100644 --- a/app/assets/js/scripts/landing.js +++ b/app/assets/js/scripts/landing.js @@ -738,7 +738,7 @@ let newsLoadingListener = null */ function setNewsLoading(val){ if(val){ - const nLStr = Lang.queryJS('landing.news.loading') + const nLStr = Lang.queryJS('landing.news.checking') let dotStr = '..' nELoadSpan.innerHTML = nLStr + dotStr newsLoadingListener = setInterval(() => { diff --git a/app/settings.ejs b/app/settings.ejs index 18bec3c5..fd83121f 100644 --- a/app/settings.ejs +++ b/app/settings.ejs @@ -245,7 +245,7 @@ -
<%- lang('settings.javaExecDesc') %> <%- lang('settings.javaReqDesc') %>
<%- lang('settings.javaPathDesc', {'pathSuffix': `bin${process.platform === 'win32' ? '\\\\javaw.exe' : '/java'}`}) %>
+
<%- lang('settings.javaExecDesc') %> <%- lang('settings.javaReqDesc') %>
<%- lang('settings.javaPathDesc', {'pathSuffix': `bin${process.platform === 'win32' ? '\\javaw.exe' : '/java'}`}) %>
<%- lang('settings.jvmOptsTitle') %>
diff --git a/index.js b/index.js index 74183b80..90ad8e98 100644 --- a/index.js +++ b/index.js @@ -12,10 +12,10 @@ const path = require('path') const semver = require('semver') const { pathToFileURL } = require('url') const { AZURE_CLIENT_ID, MSFT_OPCODE, MSFT_REPLY_TYPE, MSFT_ERROR, SHELL_OPCODE } = require('./app/assets/js/ipcconstants') +const LangLoader = require('./app/assets/js/langloader') // Setup Lang -const LangLoader = require('./app/assets/js/langloader') -LangLoader.loadLanguage('en_US') +LangLoader.setupLanguage() // Setup auto updater. function initAutoUpdater(event, data) { diff --git a/package.json b/package.json index 2ba4abbd..7cce4d87 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "helios-core": "~2.0.5", "helios-distribution-types": "^1.2.0", "jquery": "^3.7.0", + "lodash.merge": "^4.6.2", "semver": "^7.5.4", "toml": "^3.0.0" },