From 1695b51cf8c199a3636a7f994a0bcf2c04d3d4b6 Mon Sep 17 00:00:00 2001 From: Kamesuta Date: Sat, 5 Aug 2023 17:25:35 +0900 Subject: [PATCH] First step to use Language .json file in ejs --- app/assets/js/langloader.js | 4 ++++ app/assets/lang/en_US.json | 5 +++++ app/landing.ejs | 2 +- index.js | 6 ++++++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/assets/js/langloader.js b/app/assets/js/langloader.js index 24ab84ae..866c9da8 100644 --- a/app/assets/js/langloader.js +++ b/app/assets/js/langloader.js @@ -18,4 +18,8 @@ exports.query = function(id){ exports.queryJS = function(id){ return exports.query(`js.${id}`) +} + +exports.queryEJS = function(id){ + return exports.query(`ejs.${id}`) } \ No newline at end of file diff --git a/app/assets/lang/en_US.json b/app/assets/lang/en_US.json index 25b34c24..20e879ce 100644 --- a/app/assets/lang/en_US.json +++ b/app/assets/lang/en_US.json @@ -2,6 +2,11 @@ "html": { "avatarOverlay": "Edit" }, + "ejs": { + "landing": { + "news": "NEWS" + } + }, "js": { "login": { "error": { diff --git a/app/landing.ejs b/app/landing.ejs index 7e747818..b70e484b 100644 --- a/app/landing.ejs +++ b/app/landing.ejs @@ -133,7 +133,7 @@ - NEWS + <%- lang('landing.news') %> diff --git a/index.js b/index.js index 24397812..8f01ab7a 100644 --- a/index.js +++ b/index.js @@ -12,6 +12,10 @@ 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') +// Setup Lang +const LangLoader = require('./app/assets/js/langloader') +LangLoader.loadLanguage('en_US') + // Setup auto updater. function initAutoUpdater(event, data) { @@ -237,6 +241,8 @@ function createWindow() { remoteMain.enable(win.webContents) ejse.data('bkid', Math.floor((Math.random() * fs.readdirSync(path.join(__dirname, 'app', 'assets', 'images', 'backgrounds')).length))) + ejse.data('Lang', LangLoader) + ejse.data('lang', LangLoader.queryEJS) win.loadURL(pathToFileURL(path.join(__dirname, 'app', 'app.ejs')).toString())