forked from open-webui/open-webui
feat: WIP: Initial setup for i18next
This commit is contained in:
parent
9b86e0bb41
commit
fab89a76b1
17 changed files with 180 additions and 25 deletions
30
src/lib/i18n/index.ts
Normal file
30
src/lib/i18n/index.ts
Normal file
|
@ -0,0 +1,30 @@
|
|||
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;
|
10
src/lib/i18n/locales/de/common.json
Normal file
10
src/lib/i18n/locales/de/common.json
Normal file
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"NewChat": "Neuer Chat",
|
||||
"Modelfiles": "Modelfiles",
|
||||
"GreetingPlaceholder": "Wie kann ich dir heute behilflich sein?",
|
||||
"Hello": "Hallo, {{name}}",
|
||||
"ChatInputPlaceholderListening": "nimmt auf...",
|
||||
"ChatInputPlaceholder": "Sende eine Nachricht",
|
||||
"ModelSelectorPlaceholder": "Wähle ein Modell",
|
||||
"SetAsDefault": "Als Standard festlegen"
|
||||
}
|
10
src/lib/i18n/locales/en/common.json
Normal file
10
src/lib/i18n/locales/en/common.json
Normal file
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"NewChat": "New Chat",
|
||||
"Modelfiles": "Modelfiles",
|
||||
"GreetingPlaceholder": "How can I help you today?",
|
||||
"Hello": "Hello, {{name}}",
|
||||
"ChatInputPlaceholderListening": "Listening...",
|
||||
"ChatInputPlaceholder": "Send a Message",
|
||||
"ModelSelectorPlaceholder": "Select a model",
|
||||
"SetAsDefault": "Set as default"
|
||||
}
|
10
src/lib/i18n/locales/fa/common.json
Normal file
10
src/lib/i18n/locales/fa/common.json
Normal file
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"NewChat": "چت جدید",
|
||||
"Modelfiles": "فایلهای مدل",
|
||||
"GreetingPlaceholder": "امروز چطور می توانم کمک تان کنم؟",
|
||||
"Hello": "سلام، {{name}}",
|
||||
"ChatInputPlaceholderListening": "در حال گوش دادن...",
|
||||
"ChatInputPlaceholder": "یک پیام ارسال کنید",
|
||||
"ModelSelectorPlaceholder": "یک مدل انتخاب کنید",
|
||||
"SetAsDefault": "تنظیم به عنوان پیشفرض"
|
||||
}
|
10
src/lib/i18n/locales/fr/common.json
Normal file
10
src/lib/i18n/locales/fr/common.json
Normal file
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"NewChat": "New Chat",
|
||||
"Modelfiles": "Modelfiles",
|
||||
"GreetingPlaceholder": "How can I help you today?",
|
||||
"Hello": "Hello, {{name}}",
|
||||
"ChatInputPlaceholderListening": "Listening...",
|
||||
"ChatInputPlaceholder": "Send a Message",
|
||||
"ModelSelectorPlaceholder": "Select a model",
|
||||
"SetAsDefault": "Set as default"
|
||||
}
|
34
src/lib/i18n/store.ts
Normal file
34
src/lib/i18n/store.ts
Normal file
|
@ -0,0 +1,34 @@
|
|||
import type { i18n } from 'i18next';
|
||||
import { writable } from 'svelte/store';
|
||||
|
||||
export const createI18nStore = (i18n: i18n) => {
|
||||
const i18nWritable = writable(i18n);
|
||||
|
||||
i18n.on('initialized', () => {
|
||||
i18nWritable.set(i18n);
|
||||
});
|
||||
i18n.on('loaded', () => {
|
||||
i18nWritable.set(i18n);
|
||||
});
|
||||
i18n.on('added', () => i18nWritable.set(i18n));
|
||||
i18n.on('languageChanged', () => {
|
||||
i18nWritable.set(i18n);
|
||||
});
|
||||
return i18nWritable;
|
||||
};
|
||||
|
||||
export const isLoading = (i18n: i18n) => {
|
||||
const isLoading = writable(false);
|
||||
|
||||
// if loaded resources are empty || {}, set loading to true
|
||||
i18n.on('loaded', (resources) => {
|
||||
Object.keys(resources).length !== 0 && isLoading.set(false);
|
||||
});
|
||||
|
||||
// if resources failed loading, set loading to true
|
||||
i18n.on('failedLoading', () => {
|
||||
isLoading.set(true);
|
||||
});
|
||||
|
||||
return isLoading;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue