Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
xbon60 authored Dec 13, 2023
2 parents 5959556 + 258cd0d commit 6db1c99
Show file tree
Hide file tree
Showing 26 changed files with 1,117 additions and 725 deletions.
10 changes: 3 additions & 7 deletions app/app.ejs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" http-equiv="Content-Security-Policy" content="script-src 'self' 'sha256-In6B8teKZQll5heMl9bS7CESTbGvuAt3VVV86BUQBDk='"/>
<title>Fromagerie Launcher</title>

<title><%= lang('app.title') %></title>

<script src="./assets/js/scripts/uicore.js"></script>
<script src="./assets/js/scripts/uibinder.js"></script>
<link type="text/css" rel="stylesheet" href="./assets/css/launcher.css">
Expand Down Expand Up @@ -45,11 +47,5 @@
</div>
</div>
</div>
<script>
// Load language
for(let key of Object.keys(Lang.query('html'))){
document.getElementById(key).innerHTML = Lang.query(`html.${key}`)
}
</script>
</body>
</html>
6 changes: 4 additions & 2 deletions app/assets/js/discordwrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ const logger = LoggerUtil.getLogger('DiscordWrapper')

const { Client } = require('discord-rpc-patch')

const Lang = require('./langloader')

let client
let activity

exports.initRPC = function(genSettings, servSettings, initialDetails = 'Waiting for Client..'){
exports.initRPC = function(genSettings, servSettings, initialDetails = Lang.queryJS('discord.waiting')){
client = new Client({ transport: 'ipc' })

activity = {
details: initialDetails,
state: 'Server: ' + servSettings.shortId,
state: Lang.queryJS('discord.state', {shortId: servSettings.shortId}),
largeImageKey: servSettings.largeImageKey,
largeImageText: servSettings.largeImageText,
smallImageKey: genSettings.smallImageKey,
Expand Down
32 changes: 27 additions & 5 deletions app/assets/js/langloader.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,43 @@
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 = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'lang', `${id}.json`))) || {}
lang = merge(lang || {}, toml.parse(fs.readFileSync(path.join(__dirname, '..', 'lang', `${id}.toml`))) || {})
}

exports.query = function(id){
exports.query = function(id, placeHolders){
let query = id.split('.')
let res = lang
for(let q of query){
res = res[q]
}
return res === lang ? {} : res
let text = res === lang ? '' : res
if (placeHolders) {
Object.entries(placeHolders).forEach(([key, value]) => {
text = text.replace(`{${key}}`, value)
})
}
return text
}

exports.queryJS = function(id, placeHolders){
return exports.query(`js.${id}`, placeHolders)
}

exports.queryJS = function(id){
return exports.query(`js.${id}`)
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')

// Load Custom Language File for Launcher Customizer
exports.loadLanguage('_custom')
}
2 changes: 1 addition & 1 deletion app/assets/js/preloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ DistroAPI['commonDir'] = ConfigManager.getCommonDirectory()
DistroAPI['instanceDir'] = ConfigManager.getInstanceDirectory()

// Load Strings
LangLoader.loadLanguage('en_US')
LangLoader.setupLanguage()

/**
*
Expand Down
Loading

0 comments on commit 6db1c99

Please sign in to comment.