forked from mckaywrigley/chatbot-ui
-
Notifications
You must be signed in to change notification settings - Fork 93
/
Copy pathi18n.ts
41 lines (36 loc) · 1023 Bytes
/
i18n.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
import i18nConfig from "@/i18nConfig"
import { createInstance } from "i18next"
import resourcesToBackend from "i18next-resources-to-backend"
import { initReactI18next } from "react-i18next/initReactI18next"
export default async function initTranslations(
locale: any,
namespaces: any,
i18nInstance?: any,
resources?: any
) {
i18nInstance = i18nInstance || createInstance()
i18nInstance.use(initReactI18next)
if (!resources) {
i18nInstance.use(
resourcesToBackend(
(language: string, namespace: string) =>
import(`/public/locales/${language}/${namespace}.json`)
)
)
}
await i18nInstance.init({
lng: locale,
resources,
fallbackLng: i18nConfig.defaultLocale,
supportedLngs: i18nConfig.locales,
defaultNS: namespaces[0],
fallbackNS: namespaces[0],
ns: namespaces,
preload: resources ? [] : i18nConfig.locales
})
return {
i18n: i18nInstance,
resources: i18nInstance.services.resourceStore.data,
t: i18nInstance.t
}
}