2019-04-07 20:33:40 -07:00
|
|
|
const fs = require('fs-extra')
|
|
|
|
const path = require('path')
|
2023-09-02 11:34:04 -07:00
|
|
|
const toml = require('toml')
|
2019-04-07 20:33:40 -07:00
|
|
|
|
|
|
|
let lang
|
|
|
|
|
|
|
|
exports.loadLanguage = function(id){
|
2023-09-02 11:34:04 -07:00
|
|
|
lang = toml.parse(fs.readFileSync(path.join(__dirname, '..', 'lang', `${id}.toml`))) || {}
|
2019-04-07 20:33:40 -07:00
|
|
|
}
|
|
|
|
|
2023-09-01 16:39:01 -07:00
|
|
|
exports.query = function(id, placeHolders){
|
2019-04-07 20:33:40 -07:00
|
|
|
let query = id.split('.')
|
|
|
|
let res = lang
|
|
|
|
for(let q of query){
|
|
|
|
res = res[q]
|
|
|
|
}
|
2023-09-01 16:39:01 -07:00
|
|
|
let text = res === lang ? '' : res
|
|
|
|
if (placeHolders) {
|
|
|
|
Object.entries(placeHolders).forEach(([key, value]) => {
|
|
|
|
text = text.replace(`{${key}}`, value)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return text
|
2019-04-07 20:33:40 -07:00
|
|
|
}
|
|
|
|
|
2023-09-01 16:39:01 -07:00
|
|
|
exports.queryJS = function(id, placeHolders){
|
|
|
|
return exports.query(`js.${id}`, placeHolders)
|
2023-08-05 01:25:35 -07:00
|
|
|
}
|
|
|
|
|
2023-09-01 16:39:01 -07:00
|
|
|
exports.queryEJS = function(id, placeHolders){
|
|
|
|
return exports.query(`ejs.${id}`, placeHolders)
|
2019-04-07 20:33:40 -07:00
|
|
|
}
|