Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
open-webui
Commits
26121c5d
Commit
26121c5d
authored
Mar 24, 2024
by
Ased Mammad
Browse files
wip: Set default language from config
parent
cb364f0a
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
39 additions
and
29 deletions
+39
-29
backend/data/config.json
backend/data/config.json
+1
-0
backend/main.py
backend/main.py
+2
-4
src/lib/i18n/index.ts
src/lib/i18n/index.ts
+30
-24
src/routes/+layout.svelte
src/routes/+layout.svelte
+6
-1
No files found.
backend/data/config.json
View file @
26121c5d
{
{
"version"
:
0
,
"version"
:
0
,
"ui"
:
{
"ui"
:
{
"locale"
:
"en-US"
,
"prompt_suggestions"
:
[
"prompt_suggestions"
:
[
{
{
"title"
:
[
"title"
:
[
...
...
backend/main.py
View file @
26121c5d
...
@@ -32,6 +32,7 @@ from utils.utils import get_admin_user
...
@@ -32,6 +32,7 @@ from utils.utils import get_admin_user
from
apps.rag.utils
import
rag_messages
from
apps.rag.utils
import
rag_messages
from
config
import
(
from
config
import
(
CONFIG_DATA
,
WEBUI_NAME
,
WEBUI_NAME
,
ENV
,
ENV
,
VERSION
,
VERSION
,
...
@@ -88,7 +89,6 @@ class RAGMiddleware(BaseHTTPMiddleware):
...
@@ -88,7 +89,6 @@ class RAGMiddleware(BaseHTTPMiddleware):
# Example: Add a new key-value pair or modify existing ones
# Example: Add a new key-value pair or modify existing ones
# data["modified"] = True # Example modification
# data["modified"] = True # Example modification
if
"docs"
in
data
:
if
"docs"
in
data
:
data
=
{
**
data
}
data
=
{
**
data
}
data
[
"messages"
]
=
rag_messages
(
data
[
"messages"
]
=
rag_messages
(
data
[
"docs"
],
data
[
"docs"
],
...
@@ -163,11 +163,11 @@ app.mount("/rag/api/v1", rag_app)
...
@@ -163,11 +163,11 @@ app.mount("/rag/api/v1", rag_app)
@
app
.
get
(
"/api/config"
)
@
app
.
get
(
"/api/config"
)
async
def
get_app_config
():
async
def
get_app_config
():
return
{
return
{
"status"
:
True
,
"status"
:
True
,
"name"
:
WEBUI_NAME
,
"name"
:
WEBUI_NAME
,
"version"
:
VERSION
,
"version"
:
VERSION
,
"locale"
:
CONFIG_DATA
[
"ui"
][
"locale"
],
"images"
:
images_app
.
state
.
ENABLED
,
"images"
:
images_app
.
state
.
ENABLED
,
"default_models"
:
webui_app
.
state
.
DEFAULT_MODELS
,
"default_models"
:
webui_app
.
state
.
DEFAULT_MODELS
,
"default_prompt_suggestions"
:
webui_app
.
state
.
DEFAULT_PROMPT_SUGGESTIONS
,
"default_prompt_suggestions"
:
webui_app
.
state
.
DEFAULT_PROMPT_SUGGESTIONS
,
...
@@ -191,7 +191,6 @@ class ModelFilterConfigForm(BaseModel):
...
@@ -191,7 +191,6 @@ class ModelFilterConfigForm(BaseModel):
async
def
update_model_filter_config
(
async
def
update_model_filter_config
(
form_data
:
ModelFilterConfigForm
,
user
=
Depends
(
get_admin_user
)
form_data
:
ModelFilterConfigForm
,
user
=
Depends
(
get_admin_user
)
):
):
app
.
state
.
MODEL_FILTER_ENABLED
=
form_data
.
enabled
app
.
state
.
MODEL_FILTER_ENABLED
=
form_data
.
enabled
app
.
state
.
MODEL_FILTER_LIST
=
form_data
.
models
app
.
state
.
MODEL_FILTER_LIST
=
form_data
.
models
...
@@ -231,7 +230,6 @@ async def update_webhook_url(form_data: UrlForm, user=Depends(get_admin_user)):
...
@@ -231,7 +230,6 @@ async def update_webhook_url(form_data: UrlForm, user=Depends(get_admin_user)):
@
app
.
get
(
"/api/version"
)
@
app
.
get
(
"/api/version"
)
async
def
get_app_config
():
async
def
get_app_config
():
return
{
return
{
"version"
:
VERSION
,
"version"
:
VERSION
,
}
}
...
...
src/lib/i18n/index.ts
View file @
26121c5d
...
@@ -37,23 +37,28 @@ const createIsLoadingStore = (i18n: i18nType) => {
...
@@ -37,23 +37,28 @@ const createIsLoadingStore = (i18n: i18nType) => {
return
isLoading
;
return
isLoading
;
};
};
i18next
export
const
initI18n
=
(
defaultLocale
:
string
)
=>
{
.
use
(
let
detectionOrder
=
defaultLocale
resourcesToBackend
(
?
[
'
querystring
'
,
'
localStorage
'
]
(
language
:
string
,
namespace
:
string
)
=>
import
(
`./locales/
${
language
}
/
${
namespace
}
.json`
)
:
[
'
querystring
'
,
'
localStorage
'
,
'
navigator
'
];
)
let
fallbackDefaultLocale
=
defaultLocale
?
[
defaultLocale
]
:
[
'
en-US
'
];
)
const
loadResource
=
(
language
:
string
,
namespace
:
string
)
=>
import
(
`./locales/
${
language
}
/
${
namespace
}
.json`
);
i18next
.
use
(
resourcesToBackend
(
loadResource
))
.
use
(
LanguageDetector
)
.
use
(
LanguageDetector
)
.
init
({
.
init
({
debug
:
false
,
debug
:
false
,
detection
:
{
detection
:
{
order
:
[
'
querystring
'
,
'
localStorage
'
,
'
navigator
'
]
,
order
:
detectionOrder
,
caches
:
[
'
localStorage
'
],
caches
:
[
'
localStorage
'
],
lookupQuerystring
:
'
lang
'
,
lookupQuerystring
:
'
lang
'
,
lookupLocalStorage
:
'
locale
'
lookupLocalStorage
:
'
locale
'
},
},
fallbackLng
:
{
fallbackLng
:
{
default
:
[
'
en-US
'
]
default
:
fallbackDefaultLocale
},
},
ns
:
'
translation
'
,
ns
:
'
translation
'
,
returnEmptyString
:
false
,
returnEmptyString
:
false
,
...
@@ -61,6 +66,7 @@ i18next
...
@@ -61,6 +66,7 @@ i18next
escapeValue
:
false
// not needed for svelte as it escapes by default
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
);
...
...
src/routes/+layout.svelte
View file @
26121c5d
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,7 @@
import '../tailwind.css';
import '../tailwind.css';
import 'tippy.js/dist/tippy.css';
import 'tippy.js/dist/tippy.css';
import { WEBUI_BASE_URL } from '$lib/constants';
import { WEBUI_BASE_URL } from '$lib/constants';
import i18n from '$lib/i18n';
import i18n
, { initI18n }
from '$lib/i18n';
setContext('i18n', i18n);
setContext('i18n', i18n);
...
@@ -25,6 +25,11 @@
...
@@ -25,6 +25,11 @@
if (backendConfig) {
if (backendConfig) {
// Save Backend Status to Store
// Save Backend Status to Store
await config.set(backendConfig);
await config.set(backendConfig);
if ($config.locale) {
initI18n($config.locale);
} else {
initI18n();
}
await WEBUI_NAME.set(backendConfig.name);
await WEBUI_NAME.set(backendConfig.name);
console.log(backendConfig);
console.log(backendConfig);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment