DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.
Python ai-agentsai-tutorclawbotcli-tooldeepresearchinteractive-learninglearningmulti-agent-systemsrag
fix(whisper): make the page's copy translatable
Bingxi Zhao (Frank)1f4de01e707a
diff --git a/web/app/(workspace)/whisper/page.tsx b/web/app/(workspace)/whisper/page.tsxindex 7e4e0e965..da5b136a8 100644--- a/web/app/(workspace)/whisper/page.tsx+++ b/web/app/(workspace)/whisper/page.tsx@@ -1,6 +1,7 @@"use client";import { useCallback, useEffect, useMemo, useRef, useState } from "react";+import { useTranslation } from "react-i18next";import { Ear, Loader2 } from "lucide-react";import WhisperComposer from "@/components/whisper/WhisperComposer";import WhisperMessageList from "@/components/whisper/WhisperMessageList";@@ -36,6 +37,7 @@ function looksLikeRoomEnded(text: string): boolean {}export default function WhisperPage() {+ const { t } = useTranslation();const [seat, setSeat] = useState<WhisperSeat>("visitor");const [roomId, setRoomId] = useState<string | null>(null);const [messages, setMessages] = useState<WhisperMessage[]>([]);@@ -285,13 +287,13 @@ export default function WhisperPage() {<div className="min-w-0"><div className="flex items-center gap-2 text-sm font-medium text-[var(--foreground)]"><Ear className="h-4 w-4 text-[var(--primary)]" aria-hidden />- Whisper+ {t("Whisper")}</div><p className="mt-0.5 text-[11px] text-[var(--muted-foreground)]">- Dual-seat supervision · seat switch (not split-screen)+ {t("Dual-seat supervision · seat switch (not split-screen)")}{dtSessionId ? (<span className="ml-2 font-mono opacity-70">- session {dtSessionId.slice(0, 8)}…+ {t("Session {{id}}", { id: `${dtSessionId.slice(0, 8)}…` })}</span>) : null}</p>@@ -305,11 +307,11 @@ export default function WhisperPage() {disabled={!canNewRoom}className="rounded-lg border border-[var(--border)] px-2.5 py-1.5 text-[11px] font-medium text-[var(--muted-foreground)] transition-colors hover:border-[var(--ring)] hover:text-[var(--foreground)] disabled:cursor-not-allowed disabled:opacity-40">- New room+ {t("New room")}</button><divrole="tablist"- aria-label="Seat"+ aria-label={t("Seat")}className="inline-flex rounded-xl border border-[var(--border)] bg-[var(--background)] p-0.5">{(["visitor", "trainee"] as const).map((value) => {@@ -327,7 +329,7 @@ export default function WhisperPage() {: "text-[var(--muted-foreground)] hover:text-[var(--foreground)]"}`}>- {value}+ {value === "visitor" ? t("visitor") : t("trainee")}</button>);})}@@ -335,7 +337,7 @@ export default function WhisperPage() {{!connected && (<span className="inline-flex items-center gap-1 text-[11px] text-[var(--muted-foreground)]"><Loader2 className="h-3 w-3 animate-spin" />- {everConnected ? "Reconnecting…" : "Connecting…"}+ {everConnected ? t("Reconnecting…") : t("Connecting…")}</span>)}</div>@@ -347,9 +349,9 @@ export default function WhisperPage() {className="border-b border-amber-500/30 bg-amber-500/10 px-4 py-2 text-xs text-amber-800 dark:text-amber-200">{crisisHit- ? "Crisis redirect detected. Sending is disabled for this room."- : "This whisper room has ended. Sending is disabled."}{" "}- You can still copy the room id.+ ? t("Crisis redirect detected. Sending is disabled for this room.")+ : t("This whisper room has ended. Sending is disabled.")}{" "}+ {t("You can still copy the room id.")}</div>)}@@ -358,7 +360,7 @@ export default function WhisperPage() {role="status"className="border-b border-[var(--border)] bg-[var(--background)] px-4 py-2 text-xs text-[var(--muted-foreground)]">- Open the room as Visitor first.+ {t("Open the room as Visitor first.")}</div>)}diff --git a/web/components/whisper/WhisperComposer.tsx b/web/components/whisper/WhisperComposer.tsxindex 999efd5a2..611417cda 100644--- a/web/components/whisper/WhisperComposer.tsx+++ b/web/components/whisper/WhisperComposer.tsx@@ -2,6 +2,7 @@import type { KeyboardEvent } from "react";import { Loader2, Send } from "lucide-react";+import { useTranslation } from "react-i18next";import { shouldSubmitOnEnter } from "@/lib/composer-keyboard";import { useImeComposing } from "@/lib/use-ime-composing";import type { WhisperSeat } from "@/lib/whisper-transcript";@@ -33,6 +34,7 @@ export default function WhisperComposer({onSend,onEnd,}: WhisperComposerProps) {+ const { t } = useTranslation();const { isComposingRef, onCompositionStart, onCompositionEnd } =useImeComposing();@@ -56,29 +58,33 @@ export default function WhisperComposer({rows={2}placeholder={seat === "visitor"- ? "Message as visitor…"- : "Counselor line as trainee…"+ ? t("Message as visitor…")+ : t("Counselor line as trainee…")}className="min-h-[2.75rem] flex-1 resize-none rounded-xl border border-[var(--border)] bg-[var(--background)] px-3.5 py-2.5 text-sm outline-none transition-colors focus:border-[var(--ring)] disabled:cursor-not-allowed disabled:opacity-60"- aria-label={seat === "visitor" ? "Visitor message" : "Trainee message"}+ aria-label={+ seat === "visitor" ? t("Visitor message") : t("Trainee message")+ }/><buttontype="button"onClick={onSend}disabled={sendDisabled || !draft.trim()}className="inline-flex h-10 items-center gap-1.5 rounded-xl bg-[var(--primary)] px-3.5 text-sm font-medium text-[var(--primary-foreground)] transition-opacity disabled:cursor-not-allowed disabled:opacity-50"- aria-label="Send"+ aria-label={t("Send")}>{busy ? (<Loader2 className="h-4 w-4 animate-spin" />) : (<Send className="h-4 w-4" />)}- Send+ {t("Send")}</button></div>{busy && (- <p className="text-[11px] text-[var(--muted-foreground)]">Waiting…</p>+ <p className="text-[11px] text-[var(--muted-foreground)]">+ {t("Waiting…")}+ </p>)}{showEndButton && (<div className="flex justify-end">@@ -88,7 +94,7 @@ export default function WhisperComposer({disabled={endDisabled}className="rounded-lg border border-[var(--border)] px-3 py-1.5 text-xs font-medium text-[var(--muted-foreground)] transition-colors hover:border-[var(--ring)] hover:text-[var(--foreground)] disabled:cursor-not-allowed disabled:opacity-50">- 结束+ {t("End session")}</button></div>)}diff --git a/web/components/whisper/WhisperMessageList.tsx b/web/components/whisper/WhisperMessageList.tsxindex 7e74bf294..f2407650b 100644--- a/web/components/whisper/WhisperMessageList.tsx+++ b/web/components/whisper/WhisperMessageList.tsx@@ -1,6 +1,7 @@"use client";import { Lock } from "lucide-react";+import { useTranslation } from "react-i18next";import MarkdownRenderer from "@/components/common/MarkdownRenderer";import type { WhisperMessage, WhisperSeat } from "@/lib/whisper-transcript";@@ -40,31 +41,42 @@ export default function WhisperMessageList({messages,seat,}: WhisperMessageListProps) {+ const { t } = useTranslation();+if (messages.length === 0) {return (<div className="rounded-2xl border border-dashed border-[var(--border)] bg-[var(--background)]/50 p-4 text-xs leading-6 text-[var(--muted-foreground)]"><p className="mb-2 font-medium text-[var(--foreground)]">- Dual-seat whisper — 3 steps+ {t("Dual-seat whisper — 3 steps")}</p><ol className="list-decimal space-y-1.5 pl-4"><li>- <span className="font-medium text-[var(--foreground)]">Visitor:</span>{" "}- send the first message → you get a{" "}- <code className="rounded bg-[var(--muted)] px-1">room_id</code>.+ <span className="font-medium text-[var(--foreground)]">+ {t("Visitor")}:+ </span>{" "}+ {t("send the first message to get a room id.")}</li><li>- <span className="font-medium text-[var(--foreground)]">Trainee:</span>{" "}- switch seats and send counselor lines. Private notes show with a lock.+ <span className="font-medium text-[var(--foreground)]">+ {t("Trainee")}:+ </span>{" "}+ {t(+ "switch seats and send counselor lines. Private notes show with a lock.",+ )}</li><li>- <span className="font-medium text-[var(--foreground)]">结束:</span>{" "}- on Trainee, end the room for a debrief.+ <span className="font-medium text-[var(--foreground)]">+ {t("End session")}:+ </span>{" "}+ {t("on Trainee, end the room for a debrief.")}</li></ol><p className="mt-3 opacity-80">{seat === "visitor"- ? "You are on Visitor — start with step 1."- : "You are on Trainee — complete step 1 as Visitor first if there is no room yet."}+ ? t("You are on Visitor — start with step 1.")+ : t(+ "You are on Trainee — complete step 1 as Visitor first if there is no room yet.",+ )}</p></div>);@@ -95,12 +107,14 @@ export default function WhisperMessageList({{isWhisper && (<span className="inline-flex items-center gap-1 font-semibold text-amber-600 dark:text-amber-400"><Lock className="h-3 w-3" aria-hidden />- whisper+ {t("whisper")}</span>)}{metaStage && <span>{metaStage}</span>}{metaSource && <span>· {metaSource}</span>}- {msg.localSeat && <span>· you ({msg.localSeat})</span>}+ {msg.localSeat && (+ <span>· {t("you")} ({msg.localSeat})</span>+ )}</div>)}{rendersMarkdown(msg) ? (diff --git a/web/components/whisper/WhisperRoomChip.tsx b/web/components/whisper/WhisperRoomChip.tsxindex 681803e50..6a8459b35 100644--- a/web/components/whisper/WhisperRoomChip.tsx+++ b/web/components/whisper/WhisperRoomChip.tsx@@ -2,12 +2,14 @@import { useState } from "react";import { Check, Copy } from "lucide-react";+import { useTranslation } from "react-i18next";type WhisperRoomChipProps = {roomId: string;};export default function WhisperRoomChip({ roomId }: WhisperRoomChipProps) {+ const { t } = useTranslation();const [copied, setCopied] = useState(false);async function copyRoomId() {@@ -22,7 +24,7 @@ export default function WhisperRoomChip({ roomId }: WhisperRoomChipProps) {return (<div className="flex items-center gap-2 rounded-full border border-[var(--border)] bg-[var(--background)] px-3 py-1 text-xs text-[var(--muted-foreground)]">- <span className="font-medium text-[var(--foreground)]">room</span>+ <span className="font-medium text-[var(--foreground)]">{t("room")}</span><code className="max-w-[12rem] truncate font-mono text-[11px] text-[var(--foreground)]">{roomId}</code>@@ -30,14 +32,14 @@ export default function WhisperRoomChip({ roomId }: WhisperRoomChipProps) {type="button"onClick={() => void copyRoomId()}className="inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[var(--muted-foreground)] transition-colors hover:bg-[var(--card)] hover:text-[var(--foreground)]"- aria-label="Copy room id"+ aria-label={t("Copy room id")}>{copied ? (<Check className="h-3.5 w-3.5 text-emerald-500" />) : (<Copy className="h-3.5 w-3.5" />)}- <span>{copied ? "Copied" : "Copy"}</span>+ <span>{copied ? t("Copied") : t("Copy")}</span></button></div>);diff --git a/web/locales/en/app.json b/web/locales/en/app.jsonindex 3931e3718..778c9532a 100644--- a/web/locales/en/app.json+++ b/web/locales/en/app.json@@ -3208,5 +3208,34 @@"Concurrent LLM calls": "Concurrent LLM calls","Lower this if your provider rate-limits you": "Lower this if your provider rate-limits you","Extra extraction passes": "Extra extraction passes",- "Recovers missed entities; each pass costs another call": "Recovers missed entities; each pass costs another call"+ "Recovers missed entities; each pass costs another call": "Recovers missed entities; each pass costs another call",+ "Copy room id": "Copy room id",+ "Counselor line as trainee…": "Counselor line as trainee…",+ "Crisis redirect detected. Sending is disabled for this room.": "Crisis redirect detected. Sending is disabled for this room.",+ "Dual-seat supervision · seat switch (not split-screen)": "Dual-seat supervision · seat switch (not split-screen)",+ "Dual-seat whisper — 3 steps": "Dual-seat whisper — 3 steps",+ "End session": "End session",+ "Message as visitor…": "Message as visitor…",+ "New room": "New room",+ "Open the room as Visitor first.": "Open the room as Visitor first.",+ "Reconnecting…": "Reconnecting…",+ "Seat": "Seat",+ "This whisper room has ended. Sending is disabled.": "This whisper room has ended. Sending is disabled.",+ "Trainee": "Trainee",+ "Trainee message": "Trainee message",+ "Visitor": "Visitor",+ "Visitor message": "Visitor message",+ "Waiting…": "Waiting…",+ "You are on Trainee — complete step 1 as Visitor first if there is no room yet.": "You are on Trainee — complete step 1 as Visitor first if there is no room yet.",+ "You are on Visitor — start with step 1.": "You are on Visitor — start with step 1.",+ "You can still copy the room id.": "You can still copy the room id.",+ "on Trainee, end the room for a debrief.": "on Trainee, end the room for a debrief.",+ "room": "room",+ "send the first message to get a room id.": "send the first message to get a room id.",+ "switch seats and send counselor lines. Private notes show with a lock.": "switch seats and send counselor lines. Private notes show with a lock.",+ "trainee": "trainee",+ "visitor": "visitor",+ "whisper": "whisper",+ "you": "you",+ "Session {{id}}": "Session {{id}}"}diff --git a/web/locales/zh/app.json b/web/locales/zh/app.jsonindex c02408c03..a00a81de4 100644--- a/web/locales/zh/app.json+++ b/web/locales/zh/app.json@@ -3208,5 +3208,34 @@"Concurrent LLM calls": "并发 LLM 调用数","Lower this if your provider rate-limits you": "如果提供商限流,请调低","Extra extraction passes": "额外抽取轮数",- "Recovers missed entities; each pass costs another call": "补捞漏掉的实体;每轮多消耗一次调用"+ "Recovers missed entities; each pass costs another call": "补捞漏掉的实体;每轮多消耗一次调用",+ "Copy room id": "复制房间 ID",+ "Counselor line as trainee…": "以受训者身份写咨询话术…",+ "Crisis redirect detected. Sending is disabled for this room.": "检测到危机转介,本房间已停止发送。",+ "Dual-seat supervision · seat switch (not split-screen)": "双席位督导 · 切换席位(非分屏)",+ "Dual-seat whisper — 3 steps": "双席位密语 —— 三步",+ "End session": "结束",+ "Message as visitor…": "以来访者身份发言…",+ "New room": "新建房间",+ "Open the room as Visitor first.": "请先以来访者身份开启房间。",+ "Reconnecting…": "重新连接中…",+ "Seat": "席位",+ "This whisper room has ended. Sending is disabled.": "该密语房间已结束,无法继续发送。",+ "Trainee": "受训者",+ "Trainee message": "受训者消息",+ "Visitor": "来访者",+ "Visitor message": "来访者消息",+ "Waiting…": "等待中…",+ "You are on Trainee — complete step 1 as Visitor first if there is no room yet.": "你在受训者席位 —— 若尚无房间,请先以来访者身份完成第 1 步。",+ "You are on Visitor — start with step 1.": "你在来访者席位 —— 请从第 1 步开始。",+ "You can still copy the room id.": "你仍然可以复制房间 ID。",+ "on Trainee, end the room for a debrief.": "在受训者席位结束房间,进入复盘。",+ "room": "房间",+ "send the first message to get a room id.": "发送第一条消息,即可获得房间 ID。",+ "switch seats and send counselor lines. Private notes show with a lock.": "切换席位并发送咨询话术;私密笔记会带锁标显示。",+ "trainee": "受训者",+ "visitor": "来访者",+ "whisper": "密语",+ "you": "你",+ "Session {{id}}": "会话 {{id}}"}diff --git a/web/tests/whisper-i18n.test.ts b/web/tests/whisper-i18n.test.tsnew file mode 100644index 000000000..6e301c93d--- /dev/null+++ b/web/tests/whisper-i18n.test.ts@@ -0,0 +1,97 @@+import test from "node:test";+import assert from "node:assert/strict";+import fs from "node:fs";+import path from "node:path";++// The /whisper surface shipped with 23 hardcoded strings — mostly English plus+// one stray Chinese button — so it rendered the same copy whatever language the+// user had picked. Now that every one goes through `t()`, pin the other half of+// that contract: each key must exist in both locales, and the Chinese side must+// actually be translated rather than echoing the English back.++function findWebRoot(): string {+ let dir = __dirname;+ for (let i = 0; i < 8; i++) {+ if (fs.existsSync(path.join(dir, "locales", "en", "app.json"))) return dir;+ dir = path.dirname(dir);+ }+ throw new Error("could not locate the web root from " + __dirname);+}++const WEB = findWebRoot();++const SOURCES = [+ "app/(workspace)/whisper/page.tsx",+ "components/whisper/WhisperComposer.tsx",+ "components/whisper/WhisperMessageList.tsx",+ "components/whisper/WhisperRoomChip.tsx",+];++// `t("…")` but not `setDraft("")` — the negative lookbehind keeps identifiers+// that merely end in `t` from matching.+const T_CALL = /(?<![\w$])t\(\s*"((?:[^"\\]|\\.)+)"/g;++function keysUsed(): string[] {+ const keys = new Set<string>();+ for (const rel of SOURCES) {+ const src = fs.readFileSync(path.join(WEB, rel), "utf8");+ for (const m of src.matchAll(T_CALL)) keys.add(m[1]);+ }+ return [...keys].sort();+}++function locale(name: string): Record<string, string> {+ return JSON.parse(+ fs.readFileSync(path.join(WEB, "locales", name, "app.json"), "utf8"),+ ) as Record<string, string>;+}++test("the whisper surface actually calls t() for its copy", () => {+ // Guards the regex itself: if these files stop using t(), the assertions+ // below would pass vacuously.+ assert.ok(+ keysUsed().length >= 25,+ `expected the whisper files to translate their copy, found ${keysUsed().length} keys`,+ );+});++test("every whisper translation key exists in both locales", () => {+ const en = locale("en");+ const zh = locale("zh");+ const missing = keysUsed().filter((k) => !(k in en) || !(k in zh));+ assert.deepEqual(+ missing,+ [],+ `keys missing from a locale (they would render as raw English): ${missing.join(", ")}`,+ );+});++test("whisper copy is really translated into Chinese", () => {+ const zh = locale("zh");+ // Interpolated placeholders and bare ids are legitimately identical across+ // locales; prose is not.+ const echoed = keysUsed().filter(+ (k) => k.length > 3 && !k.includes("{{") && zh[k] === k,+ );+ assert.deepEqual(+ echoed,+ [],+ `zh still echoes the English copy for: ${echoed.join(", ")}`,+ );+});++test("no hardcoded Chinese copy is left in the whisper components", () => {+ // The End-session button used to be a literal 结束 in the JSX, which showed+ // Chinese to English users. Copy belongs in the locale files.+ //+ // Only the components are checked. page.tsx legitimately holds Chinese+ // *protocol* strings — it sends `结束` as psych-academy's is_end_command and+ // matches the room-ended text the capability streams back. Those are wire+ // values, not copy, and translating them would break the exchange.+ const offenders: string[] = [];+ for (const rel of SOURCES.filter((f) => f.startsWith("components/"))) {+ const src = fs.readFileSync(path.join(WEB, rel), "utf8");+ if (/[一-鿿]/.test(src)) offenders.push(rel);+ }+ assert.deepEqual(offenders, [], `CJK copy left in source: ${offenders.join(", ")}`);+});