Skip to content

Commit 61c14b3

Browse files
committed
langloader, index, preloader: Fix lang() not accessible on ejs
1 parent 7a5d590 commit 61c14b3

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

app/assets/js/langloader.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
const fs = require('fs-extra')
22
const path = require('path')
3+
const toml = require('toml')
4+
const merge = require('lodash.merge')
35

46
let lang
57

68
exports.loadLanguage = function(id){
7-
lang = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'lang', `${id}.json`))) || {}
9+
try { lang = merge(lang || {}, toml.parse(fs.readFileSync(path.join(__dirname, '..', 'lang', `${id}.toml`))) || {}) } catch (err) { console.log(err) }
10+
try { lang = merge(lang || {}, JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'lang', `${id}.json`))) || {}) } catch (err) { console.log(err) }
811
}
912

1013
exports.query = function(id){
@@ -28,8 +31,8 @@ exports.setupLanguage = function(){
2831
// Load Language Files
2932
exports.loadLanguage('en_US')
3033
// Uncomment this when translations are ready
31-
// exports.loadLanguage('fr_FR')
34+
exports.loadLanguage('fr_FR')
3235

3336
// Load Custom Language File for Launcher Customizer
34-
exports.loadLanguage('_custom')
37+
// exports.loadLanguage('_custom')
3538
}

app/assets/js/preloader.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ DistroAPI['instanceDir'] = ConfigManager.getInstanceDirectory()
2626
LangLoader.setupLanguage()
2727

2828
/**
29-
*
30-
* @param {HeliosDistribution} data
29+
*
30+
* @param {HeliosDistribution} data
3131
*/
3232
function onDistroLoad(data){
3333
if(data != null){
34-
34+
3535
// Resolve the selected server if its value has yet to be set.
3636
if(ConfigManager.getSelectedServer() == null || data.getServerById(ConfigManager.getSelectedServer()) == null){
3737
logger.info('Determining default selected server..')
@@ -57,7 +57,7 @@ DistroAPI.getDistribution()
5757
onDistroLoad(null)
5858
})
5959

60-
// Clean up temp dir incase previous launches ended unexpectedly.
60+
// Clean up temp dir incase previous launches ended unexpectedly.
6161
fs.remove(path.join(os.tmpdir(), ConfigManager.getTempNativeFolder()), (err) => {
6262
if(err){
6363
logger.warn('Error while cleaning natives directory', err)

index.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ const path = require('path')
1111
const semver = require('semver')
1212
const { pathToFileURL } = require('url')
1313
const { AZURE_CLIENT_ID, MSFT_OPCODE, MSFT_REPLY_TYPE, MSFT_ERROR, SHELL_OPCODE } = require('./app/assets/js/ipcconstants')
14+
const LangLoader = require('./app/assets/js/langloader')
15+
16+
// Setup Lang
17+
LangLoader.setupLanguage()
1418

1519
// Setup auto updater.
1620
function initAutoUpdater(event, data) {
@@ -236,7 +240,12 @@ function createWindow() {
236240
})
237241
remoteMain.enable(win.webContents)
238242

239-
ejse.data('bkid', Math.floor((Math.random() * fs.readdirSync(path.join(__dirname, 'app', 'assets', 'images', 'backgrounds')).length)))
243+
244+
const data = {
245+
bkid: Math.floor((Math.random() * fs.readdirSync(path.join(__dirname, 'app', 'assets', 'images', 'backgrounds')).length)),
246+
lang: (str, placeHolders) => LangLoader.queryEJS(str, placeHolders)
247+
}
248+
Object.entries(data).forEach(([key, val]) => ejse.data(key, val))
240249

241250
win.loadURL(pathToFileURL(path.join(__dirname, 'app', 'app.ejs')).toString())
242251

0 commit comments

Comments
 (0)