diff --git a/web/src/i18n/en.ts b/web/src/i18n/en.ts index e15356e49..cdf957e0a 100644 --- a/web/src/i18n/en.ts +++ b/web/src/i18n/en.ts @@ -283,6 +283,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 d23e4b9ce..ddada5041 100644 --- a/web/src/i18n/zh.ts +++ b/web/src/i18n/zh.ts @@ -255,6 +255,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 里):命中行 → 文档 + 以命中词为中心的摘录 */