-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
82 lines (75 loc) · 2.01 KB
/
index.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
let reroute;
require("colors");
const i18next = require("i18next");
const i18n_backend = require("i18next-fs-backend");
const readdirAsync = require("util").promisify(require("fs").readdir);
const path = require("path");
const translationsPath = path.join(__dirname, "locales");
const backendOptions = {
loadPath: path.join(translationsPath,"{{lng}}/{{ns}}.json") ,
jsonIndent: 2,
};
const i18n_node = {
getT: function getT() {
return reroute;
},
setT: function setT(t) {
reroute = t;
},
rand: function rand(string, params) {
const loc = reroute;
const options = loc(string, { returnObjects: true, ...params }, params);
const ran = Math.floor(Math.random() * options.length);
return options[ran];
},
};
const translateEngineStart = () => {
"Translation Engine Loading!";
return readdirAsync( translationsPath ).then((list) => {
i18next.use(i18n_backend).init(
{
backend: backendOptions,
lng: "en",
fallbackLng: ["en", "dev"],
fallbackToDefaultNS: true,
fallbackOnNull: true,
returnEmptyString: false,
preload: list,
load: "currentOnly",
ns: [
"bot_strings",
"events",
"commands",
"website",
"items",
"translation",
"games",
],
defaultNS: "bot_strings",
fallbackNS: "translation",
interpolation: {
escapeValue: false,
},
},
(err, t) => {
if (err) {
console.warn(
"•".yellow,
"Failed to Load Some Translations".yellow,
`\n${err.map((e) => e?.path?.replace(translationsPath," - locales")?.gray).join("\n")}`
);
}
console.log("• ".green, "Translation Engine Loaded");
i18n_node.setT(t);
global.i18n = i18next;
global.$t = i18n_node.getT();
global.rand$t = i18n_node.rand;
}
);
});
};
module.exports = {
translateEngineStart,
i18n_node,
translationsPath,
};