-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtranslation.js
27 lines (23 loc) · 863 Bytes
/
translation.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const fs = require("fs");
/**
* Returns
* @param {("en"|"de")} language
* @param {String|Number} id
* @param {String|Number} [subID]
* @returns {String}
*/
const translate = (language, id, subID) => {
let trFileName = `./translations/${language}.json`;
if(!fs.existsSync(trFileName))
return `err_no-translation-found @ ${language}:${id}.${subID}`;
let tr = JSON.parse(fs.readFileSync(trFileName).toString());
if(tr[id] && !subID)
return tr[id];
else if(Object.keys(tr[id]).length > 0 && subID && (typeof tr[id][subID] != "boolean" && tr[id][subID]))
return tr[id][subID];
else if(Object.keys(tr[id]).length > 0 && subID && typeof tr[id][subID] == "boolean")
return tr[id][subID];
else
return `err_no-translation-found @ ${language}:${id}.${subID}`;
}
module.exports = translate;