mirror of
https://github.com/dscalzi/HeliosLauncher.git
synced 2024-12-22 19:52:14 -08:00
43 lines
1.1 KiB
JavaScript
43 lines
1.1 KiB
JavaScript
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 = merge(lang || {}, toml.parse(fs.readFileSync(path.join(__dirname, '..', 'lang', `${id}.toml`))) || {})
|
|
}
|
|
|
|
exports.query = function(id, placeHolders){
|
|
let query = id.split('.')
|
|
let res = lang
|
|
for(let q of query){
|
|
res = res[q]
|
|
}
|
|
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.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('ko_KR')
|
|
|
|
// Load Custom Language File for Launcher Customizer
|
|
exports.loadLanguage('_custom')
|
|
} |