mirror of
https://github.com/privacy-scaling-explorations/pse.dev.git
synced 2026-01-10 06:38:03 -05:00
28 lines
803 B
TypeScript
28 lines
803 B
TypeScript
import { createInstance } from "i18next"
|
|
import resourcesToBackend from "i18next-resources-to-backend"
|
|
import { initReactI18next } from "react-i18next/initReactI18next"
|
|
|
|
import { getOptions } from "./settings"
|
|
|
|
const initI18next = async (lng: string, ns: string) => {
|
|
const i18nInstance = createInstance()
|
|
await i18nInstance
|
|
.use(initReactI18next)
|
|
.use(
|
|
resourcesToBackend(
|
|
(language: string, namespace: string) =>
|
|
import(`./locales/${language}/${namespace}.json`)
|
|
)
|
|
)
|
|
.init(getOptions(lng, ns))
|
|
return i18nInstance
|
|
}
|
|
|
|
export async function useTranslation(lng: string, ns: string) {
|
|
const i18nextInstance = await initI18next(lng, ns)
|
|
return {
|
|
t: i18nextInstance.getFixedT(lng, Array.isArray(ns) ? ns[0] : ns),
|
|
i18n: i18nextInstance,
|
|
}
|
|
}
|