agentic_huge_data_base / wiki
页面 Open WebUI · 14 国际化·DeepWiki 中文全文译文

14 · 国际化(Internationalization)

多模型对话工作台与知识应用入口 · 本章是 Open WebUI DeepWiki 中文译文的独立章节页,保留原始链接、源码锚点、模块标签和章节层级。

项目Open WebUI 章节14 状态全文译文 模块界面与交互、系统架构
源码线索
  • src/lib/i18n/index.ts
  • src/lib/i18n/locales/ca-ES/translation.json
  • src/lib/i18n/locales/de-DE/translation.json
  • src/lib/i18n/locales/en-GB/translation.json
  • src/lib/i18n/locales/en-US/translation.json
  • src/lib/i18n/locales/es-ES/translation.json
  • src/lib/i18n/locales/fa-IR/translation.json
  • src/lib/i18n/locales/fr-CA/translation.json
  • src/lib/i18n/locales/fr-FR/translation.json
  • src/lib/i18n/locales/languages.json
模块标签
  • 界面与交互
  • 系统架构

中文译文

国际化(中文译文)

原始 DeepWiki 页面:https://deepwiki.com/open-webui/open-webui/14-internationalization
翻译时间:2026-06-09T16:11:19.276Z
翻译模型:deepseek-chat
原文字符数:9837
项目:Open WebUI (open-webui)

---

国际化

相关源文件

以下文件为本 wiki 页面的生成提供了上下文:

  • src/lib/i18n/index.ts
  • src/lib/i18n/locales/ca-ES/translation.json
  • src/lib/i18n/locales/de-DE/translation.json
  • src/lib/i18n/locales/en-GB/translation.json
  • src/lib/i18n/locales/en-US/translation.json
  • src/lib/i18n/locales/es-ES/translation.json
  • src/lib/i18n/locales/fa-IR/translation.json
  • src/lib/i18n/locales/fr-CA/translation.json
  • src/lib/i18n/locales/fr-FR/translation.json
  • src/lib/i18n/locales/languages.json
  • src/lib/i18n/locales/ru-RU/translation.json
  • src/lib/i18n/locales/uk-UA/translation.json
  • src/lib/i18n/locales/zh-CN/translation.json
  • src/lib/i18n/locales/zh-TW/translation.json

本文档介绍 Open WebUI 中的国际化(i18n)系统,该系统为整个应用提供多语言支持。当前系统支持超过 30 个区域设置,具备动态翻译加载功能,并采用占位符变量机制实现运行时内容插值。

有关用户界面设置和主题管理的信息,请参阅设置与配置

---

目的与范围

i18n 系统通过以下方式使 Open WebUI 能够以多种语言呈现界面:

  • 维护 30 多个受支持区域设置的翻译文件 src/lib/i18n/locales/languages.json:1-242
  • 提供基于键的翻译查找机制,以英文短语作为键。
  • 支持用于运行时值插入的动态占位符变量(例如 {{COUNT}}{{model}}src/lib/i18n/locales/zh-CN/translation.json:11-33
  • 支持通过前端界面在运行时切换区域设置。
  • 使用 Moment.js 标记管理每个区域设置的日期/时间格式模式 src/lib/i18n/locales/zh-CN/translation.json:8-10

有关架构细节,请参阅翻译系统架构

---

翻译系统架构

i18n 系统采用扁平的 JSON 键值结构,其中英文短语键映射到本地化字符串。每个区域设置文件包含一个单层 JSON 对象形式的翻译条目,存储在 src/lib/i18n/locales/{locale}/translation.json 中。

翻译文件组织

区域设置加载与文件结构

下图展示了区域设置注册表与各个翻译资源之间的关系。

graph TB
    subgraph "注册表"
        LocaleRegistry["src/lib/i18n/locales/languages.json"]
    end

    subgraph "区域设置资源"
        enUS["en-US/translation.json"]
        zhCN["zh-CN/translation.json"]
        deDE["de-DE/translation.json"]
        esES["es-ES/translation.json"]
        frFR["fr-FR/translation.json"]
        ukUA["uk-UA/translation.json"]
        doge["dg-DG/translation.json"]
    end

    LocaleRegistry --> enUS
    LocaleRegistry --> zhCN
    LocaleRegistry --> deDE
    LocaleRegistry --> esES
    LocaleRegistry --> frFR
    LocaleRegistry --> ukUA
    LocaleRegistry --> doge

    zhCN --> FileContent["JSON 结构<br/>(扁平键值)"]

    FileContent --> K1["\"-1 for no limit...\": \"-1 表示无限制...\""]
    FileContent --> K2["\"Account\": \"账号\""]
    FileContent --> K3["\"{{COUNT}} files\": \"{{COUNT}} 个文件\""]

来源:src/lib/i18n/locales/languages.json:1-242src/lib/i18n/locales/zh-CN/translation.json:1-21

JSON 文件格式规范

位于 src/lib/i18n/locales/{locale}/translation.json 的翻译文件符合以下规范:

  • 单层 JSON 对象(无嵌套结构)src/lib/i18n/locales/zh-CN/translation.json:1-21
  • :英文短语(区分大小写,UTF-8 编码)。
  • :本地化翻译(UTF-8 字符串)。
  • 占位符语法{{VARIABLE}}(双花括号)src/lib/i18n/locales/zh-CN/translation.json:12-21
  • en-US/translation.json 中的空字符串表示未翻译的键,或该键本身即为显示文本 src/lib/i18n/locales/en-US/translation.json:1-20

有关实现的深入探讨,请参阅翻译系统架构

---

受支持的区域设置

Open WebUI 支持多种语言和区域变体,包括从右到左(RTL)的语言(如波斯语 fa-IR)以及社区驱动的区域设置(如“Doge”)src/lib/i18n/locales/languages.json:151-245

区域设置配置

受支持语言的主列表定义在 src/lib/i18n/locales/languages.json 中,该文件将区域设置代码映射到其显示标题。

区域设置代码标题示例文件路径
en-US英语(美国)src/lib/i18n/locales/en-US/translation.json
zh-CN中文(简体中文)src/lib/i18n/locales/zh-CN/translation.json
de-DE德语(Deutsch)src/lib/i18n/locales/de-DE/translation.json
fa-IR波斯语(فارسی)src/lib/i18n/locales/fa-IR/translation.json
uk-UA乌克兰语(Українська)src/lib/i18n/locales/uk-UA/translation.json
dg-DG狗狗语(🐶)src/lib/i18n/locales/dg-DG/translation.json

关键功能领域分布

前缀模式组件上下文示例键
"Allow "设置权限"Allow Chat Delete" src/lib/i18n/locales/zh-CN/translation.json:127"Allow File Upload" src/lib/i18n/locales/zh-CN/translation.json:136
"Add "操作按钮"Add User" src/lib/i18n/locales/zh-CN/translation.json:95"Add Model" src/lib/i18n/locales/zh-CN/translation.json:87"Add Connection" src/lib/i18n/locales/zh-CN/translation.json:74
"Are you sure"确认对话框"Are you sure you want to archive all chats? This action cannot be undone." src/lib/i18n/locales/en-US/translation.json:189
"{{COUNT}}"计数显示"{{COUNT}} Sources" src/lib/i18n/locales/zh-CN/translation.json:21"{{COUNT}} Available Tools" src/lib/i18n/locales/zh-CN/translation.json:12

有关受支持语言及其代码的完整列表,请参阅受支持的区域设置

来源:src/lib/i18n/locales/languages.json:1-242src/lib/i18n/locales/zh-CN/translation.json:1-150src/lib/i18n/locales/en-US/translation.json:189

---

变量插值系统

i18n 系统支持使用双花括号语法 {{VARIABLE}} 进行运行时变量插值。变量在渲染时由前端 i18n 引擎替换。

占位符变量类型
变量名示例键使用上下文
{{COUNT}}"{{COUNT}} Available Tools"项目计数、复数形式 src/lib/i18n/locales/zh-CN/translation.json:12
{{user}}"{{user}}'s Chats"用户显示名称 src/lib/i18n/locales/zh-CN/translation.json:32
{{model}}"{{model}} download has been canceled"模型标识符 src/lib/i18n/locales/zh-CN/translation.json:29
{{LATEST_VERSION}}"A new version (v{{LATEST_VERSION}}) is now available."版本号 src/lib/i18n/locales/zh-CN/translation.json:44
{{LOCALIZED_DATE}}"{{LOCALIZED_DATE}} at {{LOCALIZED_TIME}}"格式化时间戳 src/lib/i18n/locales/zh-CN/translation.json:28
日期和时间格式化

日期和时间键使用 Moment.js 格式标记,并结合方括号 [] 中的文字文本。这些模式按区域设置进行本地化,以符合文化习惯显示。

键(en-US)zh-CN 翻译
"[Today at] h:mm A""[今天] h:mm A" src/lib/i18n/locales/zh-CN/translation.json:9
"[Yesterday at] h:mm A""[昨天] h:mm A" src/lib/i18n/locales/zh-CN/translation.json:10
"[Last] dddd [at] h:mm A""[上次] dddd [于] h:mm A" src/lib/i18n/locales/zh-CN/translation.json:8

有关变量如何替换和格式化的详细信息,请参阅翻译中的变量插值

来源:src/lib/i18n/locales/zh-CN/translation.json:8-44

---

前端集成

i18n 系统通过响应式翻译存储与 Svelte 组件集成。组件订阅翻译更新,从而在用户切换语言时能够立即更改 UI。

翻译流程示意图

此图展示了 svelte-i18n 引擎如何将静态翻译资源与动态 Svelte 组件桥接起来。

graph LR
    Component["Svelte 组件<br/>(例如 Chat.svelte)"]
    Store["svelte-i18n 存储<br/>($t, $locale)"]
    JSON["translation.json 资源<br/>(zh-CN, fr-FR 等)"]

    JSON -- "动态加载" --> Store
    Store -- "响应式更新" --> Component

    Component -- "查找键:<br/>'Add User'" --> Store
    Store -- "返回值:<br/>'添加用户'" --> Component
回退机制

如果所选区域设置中缺少翻译或值为空字符串,系统将默认显示英文键字符串本身。这确保了即使翻译不完整,UI 也能保持功能正常 src/lib/i18n/locales/en-US/translation.json:1-10

来源:src/lib/i18n/locales/en-US/translation.json:1-10src/lib/i18n/locales/zh-CN/translation.json:1-10