dify/web/i18n-config/client.ts
Stephen Zhou a84c2d36a3
style: format with vp fmt (#38803)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2026-07-12 15:57:46 +00:00

33 lines
949 B
TypeScript

'use client'
import type { Resource } from 'i18next'
import type { Locale } from '.'
import type { Namespace, NamespaceInFileName } from './resources'
import { createInstance } from 'i18next'
import resourcesToBackend from 'i18next-resources-to-backend'
import { getI18n, initReactI18next } from 'react-i18next'
import { loadI18nResource } from './load-resource'
import { getInitOptions } from './settings'
export function createI18nextInstance(lng: Locale, resources: Resource) {
const instance = createInstance()
instance
.use(initReactI18next)
.use(
resourcesToBackend((language: Locale, namespace: NamespaceInFileName | Namespace) =>
loadI18nResource(language, namespace),
),
)
.init({
...getInitOptions(),
lng,
resources,
})
return instance
}
export const changeLanguage = async (lng?: Locale) => {
if (!lng) return
const i18n = getI18n()
await i18n.changeLanguage(lng)
}