From 77a37e9b24161de337d57dc3d32c36799e65b0d0 Mon Sep 17 00:00:00 2001 From: Virtue039 <77153652+virtue039@users.noreply.github.com> Date: Tue, 24 Nov 2026 20:29:12 +0800 Subject: [PATCH] Use the interface language for built-in documentation titles. Signed-off-by: Virtue039 <77153652+virtue039@users.noreply.github.com> --- web/src/i18n/en.ts | 2 ++ web/src/i18n/zh.ts | 2 ++ web/src/pages/Docs.test.ts | 35 +++++++++++++++++++++++++++++++++++ web/src/pages/Docs.tsx | 4 ++-- 4 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 web/src/pages/Docs.test.ts diff --git a/web/src/i18n/en.ts b/web/src/i18n/en.ts index 78f0fe381..f88531665 100644 --- a/web/src/i18n/en.ts +++ b/web/src/i18n/en.ts @@ -282,6 +282,8 @@ export const en = { docs: { /* 文档区字标:Charter——理想之城的立城宪章,与主字标同字体同字号 */ brand: "Utopia Charter", + ingestTopic: "Ingest interfaces", + mcpTopic: "Agents over MCP", backTitle: "Back to Utopia", searchPlaceholder: "Search the docs…", noResults: "No matches.", diff --git a/web/src/i18n/zh.ts b/web/src/i18n/zh.ts index b17beaaa4..00611b328 100644 --- a/web/src/i18n/zh.ts +++ b/web/src/i18n/zh.ts @@ -254,6 +254,8 @@ export const zh: Strings = { }, docs: { brand: "Utopia Charter", + ingestTopic: "摄入接口", + mcpTopic: "通过 MCP 使用智能体", backTitle: "返回 Utopia", searchPlaceholder: "搜索文档…", noResults: "没有匹配。", diff --git a/web/src/pages/Docs.test.ts b/web/src/pages/Docs.test.ts new file mode 100644 index 000000000..aaaed0b83 --- /dev/null +++ b/web/src/pages/Docs.test.ts @@ -0,0 +1,35 @@ +import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; +import { createElement, type ReactNode } from "react"; +import { renderToStaticMarkup } from "react-dom/server"; +import { afterEach, expect, it, vi } from "vitest"; + +const usePageTitle = vi.hoisted(() => vi.fn()); + +vi.mock("@tanstack/react-router", () => ({ + Link: ({ children }: { children: ReactNode }) => children, + useNavigate: () => () => {}, + useParams: () => ({ slug: "ingest" }), +})); +vi.mock("./HeaderActions", () => ({ HeaderActions: () => null })); +vi.mock("../useTitle", () => ({ usePageTitle })); + +afterEach(() => { + vi.unstubAllGlobals(); + vi.resetModules(); +}); + +it("uses the selected locale for documentation navigation and the page title", async () => { + vi.stubGlobal("localStorage", { + getItem: (key: string) => key === "utopia.lang" ? "zh" : null, + }); + vi.stubGlobal("navigator", { platform: "MacIntel" }); + const { DocsPage } = await import("./Docs"); + const client = new QueryClient(); + const markup = renderToStaticMarkup( + createElement(QueryClientProvider, { client, children: createElement(DocsPage) }), + ); + + expect(markup).toContain("摄入接口"); + expect(markup).toContain("通过 MCP 使用智能体"); + expect(usePageTitle).toHaveBeenCalledWith("Utopia", "摄入接口"); +}); diff --git a/web/src/pages/Docs.tsx b/web/src/pages/Docs.tsx index 9efb40afa..3a4417ad5 100644 --- a/web/src/pages/Docs.tsx +++ b/web/src/pages/Docs.tsx @@ -24,8 +24,8 @@ import { fetchMe } from "../authSession"; /** 文档清单:slug → 标题 + 内容(构建期打进 bundle) */ const DOCS: { slug: string; title: string; body: string }[] = [ - { slug: "ingest", title: "Ingest interfaces", body: ingestMd }, - { slug: "mcp", title: "Agents over MCP", body: mcpMd }, + { slug: "ingest", title: S.docs.ingestTopic, body: ingestMd }, + { slug: "mcp", title: S.docs.mcpTopic, body: mcpMd }, ]; /** 全文检索(客户端,文档已在 bundle 里):命中行 → 文档 + 以命中词为中心的摘录 */