dify/web/i18n/i18next-config.ts

49 lines
1.7 KiB
TypeScript
Raw Permalink Normal View History

2023-05-15 08:51:32 +08:00
'use client'
import i18n from 'i18next'
import { initReactI18next } from 'react-i18next'
2024-02-23 14:31:06 +08:00
import { LanguagesSupported } from '@/i18n/language'
const loadLangResources = (lang: string) => ({
translation: {
common: require(`./${lang}/common`).default,
layout: require(`./${lang}/layout`).default,
login: require(`./${lang}/login`).default,
register: require(`./${lang}/register`).default,
app: require(`./${lang}/app`).default,
appOverview: require(`./${lang}/app-overview`).default,
appDebug: require(`./${lang}/app-debug`).default,
appApi: require(`./${lang}/app-api`).default,
appLog: require(`./${lang}/app-log`).default,
appAnnotation: require(`./${lang}/app-annotation`).default,
share: require(`./${lang}/share-app`).default,
dataset: require(`./${lang}/dataset`).default,
datasetDocuments: require(`./${lang}/dataset-documents`).default,
datasetHitTesting: require(`./${lang}/dataset-hit-testing`).default,
datasetSettings: require(`./${lang}/dataset-settings`).default,
datasetCreation: require(`./${lang}/dataset-creation`).default,
explore: require(`./${lang}/explore`).default,
billing: require(`./${lang}/billing`).default,
custom: require(`./${lang}/custom`).default,
tools: require(`./${lang}/tools`).default,
workflow: require(`./${lang}/workflow`).default,
runLog: require(`./${lang}/run-log`).default,
},
2024-02-23 14:31:06 +08:00
})
// Automatically generate the resources object
const resources = LanguagesSupported.reduce((acc: any, lang: string) => {
acc[lang] = loadLangResources(lang)
return acc
}, {})
2023-05-15 08:51:32 +08:00
i18n.use(initReactI18next)
.init({
2023-10-18 16:00:56 +08:00
lng: undefined,
2024-01-23 21:14:53 +08:00
fallbackLng: 'en-US',
2023-05-15 08:51:32 +08:00
resources,
})
export const changeLanguage = i18n.changeLanguage
export default i18n