-
Notifications
You must be signed in to change notification settings - Fork 4.9k
/
Copy pathi18next.ts
42 lines (37 loc) · 1.16 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
import i18n, { Resource } from "i18next"
import { initReactI18next } from "gatsby-plugin-react-i18next"
import { supportedLanguages } from "../src/utils/languages"
export const baseLocales = {
en: { title: "English", left: "En" },
zh: { title: "中国人", left: "Zh" },
ru: { title: "Русский", left: "Ru" },
uk: { title: "українська", left: "Uk" },
}
// Only i18 files named in this array are being exposed to Storybook. Add filenames as necessary.
const ns = ["common", "page-about"]
const supportedLngs = [...Object.keys(baseLocales), ...supportedLanguages]
/**
* Taking the ns array and combining all the ids
* under a single ns per language, set to the default of "translation"
*/
const resources: Resource = ns.reduce((acc, n) => {
supportedLngs.forEach((lng) => {
if (!acc[lng]) acc[lng] = {}
acc[lng] = {
translation: {
...acc[lng],
...require(`../src/intl/${lng}/${n}.json`),
},
}
})
return acc
}, {})
i18n.use(initReactI18next).init({
debug: true,
fallbackLng: "en",
interpolation: { escapeValue: false },
react: { useSuspense: false },
supportedLngs,
resources,
})
export default i18n