Skip to content

fix(i18n): 向量搜索模型来源选项与 API Key 标签接入字典,不再露出 raw key - #384

Merged
AmintaCCCP merged 1 commit into
mainfrom
fix/i18n-vector-embedding-labels
Sep 21, 2026
Merged

AmintaCCCP merged 1 commit into
mainfrom
fix/i18n-vector-embedding-labels

Conversation

@AmintaCCCP

@AmintaCCCP AmintaCCCP commented Sep 21, 2026 •

Copy link
Copy Markdown
Owner

Summary

设置页「向量语义搜索 → Embedding 模型配置 → 模型来源」的 6 个选项此前直接把字典键名显示给用户
(vectorSearchSettings.api-type-openai、...-siliconflow …)。原因不是组件没走 i18n,而是组件调用
拼接 vectorSearchSettings.api-type-${type} 这样的键名之后,src/locales/* 里从未添加过这组键,
i18next 查不到就回退成 key 本体。

本 PR 做了这些事:

  • 补齐 10 份语言包的 6 个 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、de API-Schlüssel、ja API キー…)。
  • 清理与去重:删掉 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:

npm run check:boundaries   # frontend layering guard (offline, fast)
npm run check:i18n -- --base origin/main
npm run check:pr-release-files -- --base origin/main
npm run lint               # eslint incl. no-restricted-imports boundary rules
npm run typecheck          # tsc -b --noEmit
npm run test:run           # vitest run (contract + unit tests)
npm run build              # vite build + bundle budget (<= 3000 KiB legacy entry)
git diff --check           # whitespace / merge-marker hygiene

本地全部通过:

  • 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 全通过(含新增 vectorSearchApiTypeLabels 11 个断言)
  • build → Bundle budget: index-legacy = 1042.19 KiB (limit 3000 KiB);并在产物 chunk 中确认
    api-type-siliconflow":"SiliconFlow" 已随语言包下发(不再是 raw key)
  • git diff --check → clean

Scope checklist

  • Runtime/persistence/UI changes described. 见下方「Runtime / persistence / UI changes」。
  • No new import of a business service directly into src/components/**
  • No new import of React/JSX/the Store/any service into src/features/*/application/**
  • No inline eslint-disable to bypass the boundary rules(新增文件 0 处 eslint-disable)
  • No app version bump and no versions/version-info.xml edit
  • New user-facing copy uses t() / locale JSON, not hardcoded strings. 10 种语言均为真实翻译,
    非英文/中文复制;品牌 token 保留原样。

Runtime / persistence / UI changes (if any)

  • UI:设置页「向量语义搜索」面板的文案来源变化——模型来源 6 个按钮、API Key 标签由字典提供,
    各语言显示对应译名;API Key 在 zh / zh-TW 下仍是 API Key(与字典中既有的 隐藏 API Key /
    顯示 API Key 一致),其余语言按各自术语显示。布局不变(仍是 flex-wrap 按钮组)。
  • 行为:模型来源切换时预填的默认向量维度表从组件内移到 constants,值未变(OpenAI 1536 /
    SiliconFlow 1024 / Gemini 768 / Cohere 1024 / Ollama 768);初始维度兜底 1536 改为读取同一常量,
    取值等价。
  • 持久化:无影响。未改动 Store key、version、partialize / migrate / merge,写入的
    Embedding 配置结构未变,老用户数据无需迁移。

Notes for reviewers / CodeRabbit

  • zh-TW 的 硅基流動 取品牌中文名(硅基流动)的繁体写法;zh-TW / zh 下 Ollama(本機) 与
    Ollama(本地) 刻意不同,以通过仓库的「zh-TW 不得照抄简体」规则。
  • 品牌名保留英文是有意为之:仓库 PR 模板明确允许 brand token 保持字面量。
  • 范围外发现(本 PR 未处理):src/components/settings/AIConfigPanel.tsx:480 的「API 类型」下拉
    仍是硬编码英文(OpenAI (Chat Completions)、OpenAI Compatible (Custom Endpoint)、Xiaomi MiMo 等 7 项),
    属另一个面板的同类问题,需要新增 7×10 条字典键。为保持本 PR 聚焦在向量搜索面板,未一并改动,
    需要的话我可以单独开一个 PR。

Summary by CodeRabbit

  • 新功能

    • 向量搜索设置新增并本地化支持 OpenAI、OpenAI 兼容、SiliconFlow、Gemini、Cohere 和 Ollama 等模型来源选项。
    • 不同模型来源会自动使用对应的默认向量维度,并支持自动识别与调整。
  • 本地化

    • 补充多种语言的模型来源名称及“API Key”字段标签,提升设置页面的多语言显示一致性。

设置页「向量语义搜索」的模型来源按钮调用 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 断言,新增来源漏配文案即失败
@coderabbitai

coderabbitai Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

Understand this PR’s impact

Explore downstream dependencies and potential security impact with Blast Radius.

View blast radius →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 74dcb3c1-d2e5-4529-8ee9-9352af115f7d

📥 Commits

Reviewing files that changed from the base of the PR and between a8d4b7c and a9b8d81.

📒 Files selected for processing (13)
  • src/components/settings/VectorSearchSettings.tsx
  • src/constants/embeddingApiTypes.ts
  • src/i18n/vectorSearchApiTypeLabels.test.ts
  • src/locales/de/app.json
  • src/locales/en/app.json
  • src/locales/es/app.json
  • src/locales/fr/app.json
  • src/locales/ja/app.json
  • src/locales/ko/app.json
  • src/locales/pt-BR/app.json
  • src/locales/ru/app.json
  • src/locales/zh-TW/app.json
  • src/locales/zh/app.json

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

Changes

本次变更将嵌入 API 类型和默认向量维度移至共享常量模块。向量搜索设置界面改用共享定义,并使用本地化文案。各语言文件新增 API 类型和 API Key 文案。测试验证文案覆盖和配置一致性。

嵌入 API 设置

Layer / File(s) Summary
共享嵌入 API 常量
src/constants/embeddingApiTypes.ts
新增六种嵌入 API 类型、默认向量维度映射和本地化键生成函数。
设置界面接入共享定义
src/components/settings/VectorSearchSettings.tsx
设置界面改用共享常量,使用默认维度初始化和回退,并通过本地化键显示 API 类型与 API Key 标签。
本地化文案与覆盖测试
src/locales/*/app.json, src/i18n/vectorSearchApiTypeLabels.test.ts
各语言新增六种 API 类型和 API Key 文案。测试验证文案非空、类型无重复,并验证类型列表与默认维度映射一致。

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 3…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确概括了主要变更:将向量搜索模型来源选项和 API Key 标签接入 i18n 字典,并修复 raw key 显示问题。
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Repository owner deleted a comment from trycase-bot Bot Sep 21, 2026
@AmintaCCCP
AmintaCCCP merged commit 6902db4 into main Sep 21, 2026
10 of 11 checks passed
@AmintaCCCP
AmintaCCCP deleted the fix/i18n-vector-embedding-labels branch September 21, 2026 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant