-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
i18n.js
47 lines (45 loc) · 1.49 KB
/
i18n.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
const locales = require("./locales.json");
const { PrismaClient } = require("@prisma/client");
const DEFAULT_LANG = "en";
module.exports = {
"loader": false,
"locales": locales,
"defaultLocale": DEFAULT_LANG,
"pages": {
"*": ["common"],
"/information": ["information"],
"/payment": ["payment"],
"/seatselection/[id]": ["seatselection"],
"/checkout": ["checkout"],
"/refund": ["refund"]
},
"logger": () => {},
"logBuild": false,
"loadLocaleFrom": async (lang, ns) => {
const prisma = new PrismaClient();
let result = (await import(`./locale/${DEFAULT_LANG}/${ns}.json`)).default;
try {
result = {...result , ...(await import(`./locale/${lang}/${ns}.json`)).default};
} catch (e) {
throw e;
}
try {
const translations = await prisma.translation.findMany({
where: {
namespace: ns
}
});
const db = translations
.filter((translation) => JSON.parse(translation.translations)[lang])
.reduce((result, translation) => {
return { ...result, [translation.key]: JSON.parse(translation.translations)[lang]};
}, {});
result = { ...result, ...db }; // override locales by database
} catch (e) {
throw e
} finally {
prisma.$disconnect();
}
return result;
}
}