open-webui/src/lib/i18n/index.ts

31 lines
870 B
TypeScript
Raw Normal View History

2024-03-01 04:40:36 +00:00
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;