Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.
Go agentagenticaichatbotdsh-pluginembeddingsevaluationgenerative-aigolangknowledge-basellmmulti-tenantollamaopenaiquestion-answeringragrerankingsemantic-searchvector-searchwiki
feat(i18n): 前端默认语言支持经 DEFAULT_LOCALE 环境变量运行时配置
sunmh23849a0c669d
diff --git a/.env.example b/.env.exampleindex da5f273ab..837b075fe 100644--- a/.env.example+++ b/.env.example@@ -55,6 +55,10 @@ TZ=Asia/Shanghai# 系统默认语言(BCP-47),用于 Prompt 中 {{language}} 占位符回退。# 优先级:Accept-Language 请求头 > 此变量 > 内置默认值 (en-US)。# WEKNORA_LANGUAGE=zh-CN+# 前端界面默认语言(BCP-47)。可选:zh-CN | en-US | ru-RU | ko-KR。+# 优先级:用户已选语言(localStorage) > 此变量 > 内置默认 zh-CN。+# 仅影响首次访问/未手动切换语言的用户;改完重启 frontend 容器即生效,无需重建镜像。+# DEFAULT_LOCALE=en-US# 启动时自动执行数据库迁移;设 false 禁用(默认启用)。AUTO_MIGRATE=true# 自动恢复脏数据迁移状态(默认 true)。diff --git a/docker-compose.yml b/docker-compose.ymlindex be4844375..c25547fb4 100644--- a/docker-compose.yml+++ b/docker-compose.yml@@ -9,6 +9,7 @@ services:- "${FRONTEND_PORT:-80}:80"environment:- MAX_FILE_SIZE_MB=${MAX_FILE_SIZE_MB:-50}+ - DEFAULT_LOCALE=${DEFAULT_LOCALE:-}- APP_HOST=${APP_HOST:-app}# APP_BACKEND_PORT: the port NGINX proxies to (default 8080).# For local deployment this is the App container's listening port, independent of host-mapped APP_PORT.diff --git a/frontend/docker-entrypoint.sh b/frontend/docker-entrypoint.shindex f0a7bd414..1262bc266 100644--- a/frontend/docker-entrypoint.sh+++ b/frontend/docker-entrypoint.sh@@ -3,7 +3,8 @@# 生成运行时配置文件,注入环境变量到前端cat > /usr/share/nginx/html/config.js << EOFwindow.__RUNTIME_CONFIG__ = {- MAX_FILE_SIZE_MB: ${MAX_FILE_SIZE_MB:-50}+ MAX_FILE_SIZE_MB: ${MAX_FILE_SIZE_MB:-50},+ DEFAULT_LOCALE: "${DEFAULT_LOCALE:-}"};EOFdiff --git a/frontend/src/i18n/index.ts b/frontend/src/i18n/index.tsindex da405b618..6028a7aba 100755--- a/frontend/src/i18n/index.ts+++ b/frontend/src/i18n/index.ts@@ -11,8 +11,22 @@ const messages = {'ko-KR': koKR}-// Получаем сохраненный язык из localStorage или используем китайский по умолчанию-const savedLocale = localStorage.getItem('locale') || 'zh-CN'+const SUPPORTED_LOCALES = Object.keys(messages)+const BUILT_IN_DEFAULT = 'zh-CN'++// Resolve the deployment default locale. Mirrors the MAX_FILE_SIZE_MB convention:+// runtime config (.env -> docker-entrypoint -> window.__RUNTIME_CONFIG__) wins over+// build-time env (VITE_DEFAULT_LOCALE), then the built-in default. Unknown values+// (e.g. a typo in .env) fall back to the built-in default instead of a blank UI.+function resolveDefaultLocale(): string {+ const candidate = window.__RUNTIME_CONFIG__?.DEFAULT_LOCALE+ || import.meta.env.VITE_DEFAULT_LOCALE+ || BUILT_IN_DEFAULT+ return SUPPORTED_LOCALES.includes(candidate) ? candidate : BUILT_IN_DEFAULT+}++// User's explicit past choice wins; otherwise use the deployment default.+const savedLocale = localStorage.getItem('locale') || resolveDefaultLocale()const i18n = createI18n({legacy: false,diff --git a/frontend/src/utils/index.ts b/frontend/src/utils/index.tsindex 235afda69..414609b6f 100644--- a/frontend/src/utils/index.ts+++ b/frontend/src/utils/index.ts@@ -7,6 +7,7 @@ declare global {interface Window {__RUNTIME_CONFIG__?: {MAX_FILE_SIZE_MB?: number;+ DEFAULT_LOCALE?: string;};}}