mirror of
https://github.com/open-webui/open-webui
synced 2025-01-18 00:30:51 +00:00
refactor: Remove changes to i18n/index.ts
This commit is contained in:
parent
586de1f5ba
commit
8634140306
@ -1,6 +1,6 @@
|
|||||||
import i18next from 'i18next';
|
import i18next from 'i18next';
|
||||||
import LanguageDetector from 'i18next-browser-languagedetector';
|
|
||||||
import resourcesToBackend from 'i18next-resources-to-backend';
|
import resourcesToBackend from 'i18next-resources-to-backend';
|
||||||
|
import LanguageDetector from 'i18next-browser-languagedetector';
|
||||||
import type { i18n as i18nType } from 'i18next';
|
import type { i18n as i18nType } from 'i18next';
|
||||||
import { writable } from 'svelte/store';
|
import { writable } from 'svelte/store';
|
||||||
|
|
||||||
@ -37,32 +37,36 @@ const createIsLoadingStore = (i18n: i18nType) => {
|
|||||||
return isLoading;
|
return isLoading;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const initI18n = (defaultLocale?: string) => {
|
export const initI18n = (defaultLocale: string | undefined) => {
|
||||||
// Use object destructuring for cleaner code
|
let detectionOrder = defaultLocale
|
||||||
const [defaultDetection, fallbackDetection] = defaultLocale ? ['querystring', 'localStorage'] : ['querystring', 'localStorage', 'navigator'];
|
? ['querystring', 'localStorage']
|
||||||
|
: ['querystring', 'localStorage', 'navigator'];
|
||||||
// Use nullish coalescing operator to simplify the ternary expression
|
let fallbackDefaultLocale = defaultLocale ? [defaultLocale] : ['en-US'];
|
||||||
const fallbackDefaultLocale = defaultLocale ?? 'en-US';
|
|
||||||
|
const loadResource = (language: string, namespace: string) =>
|
||||||
const loadResource = (language: string, namespace: string) => import(`./locales/${language}/${namespace}.json`);
|
import(`./locales/${language}/${namespace}.json`);
|
||||||
|
|
||||||
i18next
|
i18next
|
||||||
.use(resourcesToBackend(loadResource))
|
.use(resourcesToBackend(loadResource))
|
||||||
.use(LanguageDetector)
|
.use(LanguageDetector)
|
||||||
.init({
|
.init({
|
||||||
debug: false,
|
debug: false,
|
||||||
detection: {
|
detection: {
|
||||||
order: [defaultDetection, fallbackDetection],
|
order: detectionOrder,
|
||||||
caches: ['localStorage'],
|
caches: ['localStorage'],
|
||||||
lookupQuerystring: 'lang',
|
lookupQuerystring: 'lang',
|
||||||
lookupLocalStorage: 'locale'
|
lookupLocalStorage: 'locale'
|
||||||
},
|
},
|
||||||
fallbackLng: fallbackDefaultLocale,
|
fallbackLng: {
|
||||||
ns: 'translation',
|
default: fallbackDefaultLocale
|
||||||
returnEmptyString: false,
|
},
|
||||||
interpolation: { escapeValue: false }
|
ns: 'translation',
|
||||||
});
|
returnEmptyString: false,
|
||||||
};
|
interpolation: {
|
||||||
|
escapeValue: false // not needed for svelte as it escapes by default
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const i18n = createI18nStore(i18next);
|
const i18n = createI18nStore(i18next);
|
||||||
const isLoadingStore = createIsLoadingStore(i18next);
|
const isLoadingStore = createIsLoadingStore(i18next);
|
||||||
|
Loading…
Reference in New Issue
Block a user