Merge pull request #3555 from open-webui/dev

fix: default locale
This commit is contained in:
Timothy Jaeryang Baek 2024-06-30 14:53:27 -07:00 committed by GitHub
commit 824966ad4a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 20 additions and 14 deletions

View File

@ -674,6 +674,13 @@ ENABLE_SIGNUP = PersistentConfig(
else os.environ.get("ENABLE_SIGNUP", "True").lower() == "true" else os.environ.get("ENABLE_SIGNUP", "True").lower() == "true"
), ),
) )
DEFAULT_LOCALE = PersistentConfig(
"DEFAULT_LOCALE",
"ui.default_locale",
os.environ.get("DEFAULT_LOCALE", ""),
)
DEFAULT_MODELS = PersistentConfig( DEFAULT_MODELS = PersistentConfig(
"DEFAULT_MODELS", "ui.default_models", os.environ.get("DEFAULT_MODELS", None) "DEFAULT_MODELS", "ui.default_models", os.environ.get("DEFAULT_MODELS", None)
) )

View File

@ -101,6 +101,7 @@ from config import (
UPLOAD_DIR, UPLOAD_DIR,
CACHE_DIR, CACHE_DIR,
STATIC_DIR, STATIC_DIR,
DEFAULT_LOCALE,
ENABLE_OPENAI_API, ENABLE_OPENAI_API,
ENABLE_OLLAMA_API, ENABLE_OLLAMA_API,
ENABLE_MODEL_FILTER, ENABLE_MODEL_FILTER,
@ -1722,18 +1723,11 @@ async def update_pipeline_valves(
@app.get("/api/config") @app.get("/api/config")
async def get_app_config(): async def get_app_config():
# Checking and Handling the Absence of 'ui' in CONFIG_DATA
default_locale = "en-US"
if "ui" in CONFIG_DATA:
default_locale = CONFIG_DATA["ui"].get("default_locale", "en-US")
# The Rest of the Function Now Uses the Variables Defined Above
return { return {
"status": True, "status": True,
"name": WEBUI_NAME, "name": WEBUI_NAME,
"version": VERSION, "version": VERSION,
"default_locale": default_locale, "default_locale": str(DEFAULT_LOCALE),
"default_models": webui_app.state.config.DEFAULT_MODELS, "default_models": webui_app.state.config.DEFAULT_MODELS,
"default_prompt_suggestions": webui_app.state.config.DEFAULT_PROMPT_SUGGESTIONS, "default_prompt_suggestions": webui_app.state.config.DEFAULT_PROMPT_SUGGESTIONS,
"features": { "features": {

View File

@ -92,12 +92,17 @@
// Initialize i18n even if we didn't get a backend config, // Initialize i18n even if we didn't get a backend config,
// so `/error` can show something that's not `undefined`. // so `/error` can show something that's not `undefined`.
const languages = await getLanguages(); initI18n();
const browserLanguages = navigator.languages if (!localStorage.locale) {
? navigator.languages const languages = await getLanguages();
: [navigator.language || navigator.userLanguage]; const browserLanguages = navigator.languages
? navigator.languages
initI18n(bestMatchingLanguage(languages, browserLanguages, backendConfig.default_locale)); : [navigator.language || navigator.userLanguage];
const lang = backendConfig.default_locale
? backendConfig.default_locale
: bestMatchingLanguage(languages, browserLanguages, 'en-US');
$i18n.changeLanguage(lang);
}
if (backendConfig) { if (backendConfig) {
// Save Backend Status to Store // Save Backend Status to Store