2019-04-08 03:33:40 +00:00
|
|
|
const fs = require('fs-extra')
|
|
|
|
const path = require('path')
|
2023-10-05 19:26:32 +00:00
|
|
|
const toml = require('toml')
|
|
|
|
const merge = require('lodash.merge')
|
2019-04-08 03:33:40 +00:00
|
|
|
|
|
|
|
let lang
|
|
|
|
|
|
|
|
exports.loadLanguage = function(id){
|
2023-10-05 19:26:32 +00:00
|
|
|
lang = merge(lang || {}, toml.parse(fs.readFileSync(path.join(__dirname, '..', 'lang', `${id}.toml`))) || {})
|
2019-04-08 03:33:40 +00:00
|
|
|
}
|
|
|
|
|
2023-10-05 19:26:32 +00:00
|
|
|
exports.query = function(id, placeHolders){
|
2019-04-08 03:33:40 +00:00
|
|
|
let query = id.split('.')
|
|
|
|
let res = lang
|
|
|
|
for(let q of query){
|
|
|
|
res = res[q]
|
|
|
|
}
|
2023-10-05 19:26:32 +00:00
|
|
|
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)
|
2019-04-08 03:33:40 +00:00
|
|
|
}
|
|
|
|
|
2023-10-05 19:26:32 +00:00
|
|
|
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
|
2024-01-08 15:20:49 +00:00
|
|
|
exports.loadLanguage('ru_RU')
|
2023-10-05 19:26:32 +00:00
|
|
|
|
|
|
|
// Load Custom Language File for Launcher Customizer
|
|
|
|
exports.loadLanguage('_custom')
|
2019-04-08 03:33:40 +00:00
|
|
|
}
|