Repository navigation
fix(i18n): 向量搜索模型来源选项与 API Key 标签接入字典,不再露出 raw key - #384
Conversation
设置页「向量语义搜索」的模型来源按钮调用 t(`vectorSearchSettings.api-type-${type}`),
但 10 份语言包里从未加过 api-type-* 键,i18next 查不到就回退成 key 本体,界面因此
直接显示 vectorSearchSettings.api-type-siliconflow 这类原始键名。
- zh/en/ja/es/pt-BR/ru/zh-TW/fr/de/ko 各补 6 个 api-type-* 键:品牌名保留英文,
可翻译部分(兼容端点/本地/compatible/lokal/ローカル/로컬)按各自语言本地化
- 同一面板的 API Key 标签由硬编码改为 t('vectorSearchSettings.api-key'),
各语言沿用字典中已有的术语(如 es 的 clave API、ru 的 ключ API)
- 移除 EMBEDDING_API_TYPES 里已无人读取的 label/labelEn 双语字段,来源取值与默认
向量维度抽到 src/constants/embeddingApiTypes.ts(对齐 aiCapabilities 的分层做法),
字典键由 embeddingApiTypeLabelKey() 统一生成,面板内的维度兜底也不再写死 1536
- 新增 src/i18n/vectorSearchApiTypeLabels.test.ts:模板键不在 check-i18n 的字面量
覆盖范围内,这里补齐每种语言的覆盖与 raw key 断言,新增来源漏配文案即失败
|
Understand this PR’s impact Explore downstream dependencies and potential security impact with Blast Radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (13)
Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughChanges本次变更将嵌入 API 类型和默认向量维度移至共享常量模块。向量搜索设置界面改用共享定义,并使用本地化文案。各语言文件新增 API 类型和 API Key 文案。测试验证文案覆盖和配置一致性。 嵌入 API 设置
Priority: ⬇️ Low Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Bug fix 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
设置页「向量语义搜索 → Embedding 模型配置 → 模型来源」的 6 个选项此前直接把字典键名显示给用户
(
vectorSearchSettings.api-type-openai、...-siliconflow…)。原因不是组件没走 i18n,而是组件调用拼接
vectorSearchSettings.api-type-${type}这样的键名之后,src/locales/*里从未添加过这组键,i18next 查不到就回退成 key 本体。
本 PR 做了这些事:
api-type-*键:品牌名(OpenAI / Gemini / Cohere / SiliconFlow / Ollama)保留英文原名,可翻译部分按各自语言本地化——
OpenAI 兼容端点/OpenAI 相容端點/OpenAI 互換/OpenAI 호환/OpenAI-kompatibel/Compatible avec OpenAI/Compatible con OpenAI/Compatível com OpenAI/Совместимо с OpenAI,以及
Ollama(本地)/Ollama(本機)/Ollama(ローカル)/Ollama (로컬)/Ollama (lokal)等。API Key输入框标签改为t('vectorSearchSettings.api-key'),译名沿用各语言字典里已有的术语(es
Clave API、ruКлюч API、deAPI-Schlüssel、jaAPI キー…)。EMBEDDING_API_TYPES中已无人读取的label/labelEn双语字段(同一份文案的第二事实源,正是
src/i18n/useT.ts注释里要淘汰的过渡形态);来源取值与默认向量维度抽到src/constants/embeddingApiTypes.ts(对齐src/constants/aiCapabilities.ts的分层做法),字典键由embeddingApiTypeLabelKey()统一生成;面板内维度兜底不再写死1536,改用常量。src/i18n/vectorSearchApiTypeLabels.test.ts。动态模板键不会被scripts/check-i18n.cjs的字面量 key 检查覆盖,这里断言每种语言都覆盖全部
EmbeddingApiType、值非空且不是 raw key,并校验来源列表与默认维度表一一对应——将来加来源却漏配文案会直接失败。
Verification
Run the following locally in this order before pushing:
本地全部通过:
check:boundaries→no frontend layering violations found.check:i18n --base origin/main→locale parity, translations, and key references look good.(含 PR diff 的「不得照抄英文/简体」规则:新增 70 条译名逐条校验无违规)
check:pr-release-files --base origin/main→no release-file version changes in this PR.lint/typecheck→ 无输出(干净)test:run→ 108 files / 1085 tests 全通过(含新增vectorSearchApiTypeLabels11 个断言)build→Bundle budget: index-legacy = 1042.19 KiB (limit 3000 KiB);并在产物 chunk 中确认api-type-siliconflow":"SiliconFlow"已随语言包下发(不再是 raw key)git diff --check→ cleanScope checklist
importof a business service directly intosrc/components/**importof React/JSX/the Store/any service intosrc/features/*/application/**eslint-disableto bypass the boundary rules(新增文件 0 处eslint-disable)versions/version-info.xmleditt()/ locale JSON, not hardcoded strings. 10 种语言均为真实翻译,非英文/中文复制;品牌 token 保留原样。
Runtime / persistence / UI changes (if any)
各语言显示对应译名;
API Key在 zh / zh-TW 下仍是API Key(与字典中既有的隐藏 API Key/顯示 API Key一致),其余语言按各自术语显示。布局不变(仍是flex-wrap按钮组)。SiliconFlow 1024 / Gemini 768 / Cohere 1024 / Ollama 768);初始维度兜底
1536改为读取同一常量,取值等价。
version、partialize/migrate/merge,写入的Embedding 配置结构未变,老用户数据无需迁移。
Notes for reviewers / CodeRabbit
硅基流動取品牌中文名(硅基流动)的繁体写法;zh-TW / zh 下Ollama(本機)与Ollama(本地)刻意不同,以通过仓库的「zh-TW 不得照抄简体」规则。src/components/settings/AIConfigPanel.tsx:480的「API 类型」下拉仍是硬编码英文(
OpenAI (Chat Completions)、OpenAI Compatible (Custom Endpoint)、Xiaomi MiMo等 7 项),属另一个面板的同类问题,需要新增 7×10 条字典键。为保持本 PR 聚焦在向量搜索面板,未一并改动,
需要的话我可以单独开一个 PR。
Summary by CodeRabbit
新功能
本地化