mirror of
https://github.com/dscalzi/HeliosLauncher.git
synced 2024-12-23 12:12:12 -08:00
31 lines
766 B
JavaScript
31 lines
766 B
JavaScript
const fs = require('fs-extra')
|
|
const path = require('path')
|
|
|
|
let lang
|
|
|
|
exports.loadLanguage = function(id){
|
|
lang = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'lang', `${id}.json`))) || {}
|
|
}
|
|
|
|
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)
|
|
} |