-
Notifications
You must be signed in to change notification settings - Fork 4.9k
/
Copy pathi18next.ts
62 lines (55 loc) · 1.36 KB
/
i18next.ts
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
import i18n, { Resource } from "i18next"
import { initReactI18next } from "react-i18next"
export const baseLocales = {
en: { title: "English", left: "En" },
zh: { title: "中国人", left: "Zh" },
ru: { title: "Русский", left: "Ru" },
uk: { title: "українська", left: "Uk" },
fa: { title: "فارسی", left: "Fa" },
}
// Only i18n files named in this array are being exposed to Storybook. Add filenames as necessary.
const ns = [
"common",
"glossary",
"page-about",
"page-index",
"page-learn",
"page-upgrades",
"page-developers-index",
]
const supportedLngs = Object.keys(baseLocales)
/**
* Taking the ns array and generating those files for each language available.
*/
const resources: Resource = ns.reduce((acc, n) => {
supportedLngs.forEach((lng) => {
if (!acc[lng]) acc[lng] = {}
try {
acc[lng] = {
...acc[lng],
[n]: {
...acc[lng][n],
...require(`../src/intl/${lng}/${n}.json`),
},
}
} catch {
acc[lng] = {
...acc[lng],
[n]: {
...acc[lng][n],
...require(`../src/intl/en/${n}.json`),
},
}
}
})
return acc
}, {})
i18n.use(initReactI18next).init({
debug: true,
fallbackLng: "en",
interpolation: { escapeValue: false },
react: { useSuspense: false },
supportedLngs,
resources,
})
export default i18n