-
Notifications
You must be signed in to change notification settings - Fork 4.9k
/
Copy pathi18next.ts
72 lines (65 loc) · 1.69 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
63
64
65
66
67
68
69
70
71
72
import i18n, { Resource } from "i18next"
// eslint-disable-next-line no-restricted-imports
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.
export const ns = [
"common",
"glossary",
"glossary-tooltip",
"learn-quizzes",
"page-about",
"page-index",
"page-learn",
"page-upgrades",
"page-developers-index",
"page-what-is-ethereum",
"page-upgrades-index",
"page-wallets-find-wallet",
"page-developers-docs",
"table",
] as const
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
}, {})
console.log("🚀 ~ constresources:Resource=ns.reduce ~ resources:", resources)
i18n.use(initReactI18next).init({
debug: true,
fallbackLng: "en",
interpolation: { escapeValue: false },
react: { useSuspense: false },
supportedLngs,
resources,
defaultNS: "common",
})
export default i18n