open-webui/src/lib/i18n/index.ts
2024-03-02 14:47:37 +03:30

30 lines
870 B
TypeScript

import i18next from 'i18next';
import resourcesToBackend from 'i18next-resources-to-backend';
import LanguageDetector from 'i18next-browser-languagedetector';
import { createI18nStore, isLoading as isLoadingStore } from './store';
i18next
.use(
resourcesToBackend((language, namespace) => import(`./locales/${language}/${namespace}.json`))
)
.use(LanguageDetector)
.init({
debug: true,
detection: {
order: ['querystring', 'localStorage', 'navigator'],
caches: ['localStorage'],
lookupQuerystring: 'lang',
lookupLocalStorage: 'locale'
},
fallbackLng: 'en',
ns: 'common',
// backend: {
// loadPath: '/locales/{{lng}}/{{ns}}.json'
// }
interpolation: {
escapeValue: false // not needed for svelte as it escapes by default
}
});
const i18n = createI18nStore(i18next);
export default i18n;
export const isLoading = isLoadingStore;