Skip to content

Linger is An Open-Source Personal Agent That Runs Fully on Your PC. We aim to break Big Tech’s grip on AI by bringing powerful local AI to everyday computers through efficient model–harness co-design, so everyone can run their own.

feat(web): translate the voice key dialog

Kilynf39075f4ad40
diff --git a/apps/web/src/features/rooms/voice-control/voice-key-dialog.tsx b/apps/web/src/features/rooms/voice-control/voice-key-dialog.tsx
index 8497936b..6ef7474f 100644
--- a/apps/web/src/features/rooms/voice-control/voice-key-dialog.tsx
+++ b/apps/web/src/features/rooms/voice-control/voice-key-dialog.tsx
@@ -12,8 +12,17 @@ import type {
TeamHubVoiceProvider,
TeamHubVoiceProviderKeyStatus,
} from "@/features/teamhub/teamhub-types";
+import { commonMessages } from "@/i18n/common.messages";
+import type { Translate } from "@/i18n/language";
+import type { Message } from "@/i18n/messages";
+import { RichMessage, useT } from "@/i18n/use-translation";
import { publishVoiceMediaPolicy } from "./use-voice-media-policy";
+import { voiceKeyMessages as m } from "./voice-key.messages";
+
+// Where TeamHub keeps saved keys; a server without it can only read keys
+// from its environment.
+const STORAGE_VARIABLE = "TEAMHUB_SECRET_ENCRYPTION_KEY";
const providerDetails: Record<
TeamHubVoiceProvider,
@@ -21,32 +30,20 @@ const providerDetails: Record<
environmentVariable: string;
href: string;
name: string;
- purpose: string;
- steps: string[];
+ purpose: Message<string>;
}
> = {
soniox: {
environmentVariable: "SONIOX_API_KEY",
href: "https://console.soniox.com/",
name: "Soniox",
- purpose:
- "Transcribes meetings, Pocket Notes dictation and Voice Mode dictation.",
- steps: [
- "Open the Soniox Console and sign in or create an account.",
- "Create an API key.",
- "Copy the key, paste it below, and select Save key.",
- ],
+ purpose: m.sonioxPurpose,
},
xai: {
environmentVariable: "XAI_API_KEY",
href: "https://console.x.ai/",
name: "xAI",
- purpose: "Turns Voice Mode into a live conversation with Grok.",
- steps: [
- "Open the xAI Console and sign in or create an account.",
- "Create an API key.",
- "Copy the key, paste it below, and select Save key.",
- ],
+ purpose: m.xaiPurpose,
},
};
@@ -67,23 +64,30 @@ function voiceReady(
: policy.live_supported === true;
}
-function describeSaveError(error: Error, provider: TeamHubVoiceProvider) {
+function describeSaveError(
+ error: Error,
+ provider: TeamHubVoiceProvider,
+ t: Translate,
+) {
const { environmentVariable, name } = providerDetails[provider];
switch (error instanceof TeamHubError ? error.code : undefined) {
case "INVALID_REQUEST":
- return "Enter a valid API key.";
+ return t(m.invalidKey);
case "VOICE_KEY_REJECTED":
- return `${name} rejected this key. Check it and try again.`;
+ return t(m.keyRejected, { provider: name });
case "VOICE_KEY_FROM_ENVIRONMENT":
- return `This server sets the ${name} key with ${environmentVariable}, so it cannot be changed here.`;
+ return t(m.keyFromEnvironment, {
+ provider: name,
+ variable: environmentVariable,
+ });
case "VOICE_KEY_STORAGE_UNAVAILABLE":
- return "This server cannot store keys. Whoever runs it must set TEAMHUB_SECRET_ENCRYPTION_KEY.";
+ return t(m.storageUnavailable, { storageVariable: STORAGE_VARIABLE });
case "VOICE_PROVIDER_UNAVAILABLE":
- return `Could not reach ${name} to check the key. Try again in a moment.`;
+ return t(m.providerUnreachable, { provider: name });
case "VOICE_MEDIA_OFF":
- return "Voice is turned off on this server.";
+ return t(m.voiceOff);
default:
- return "Could not save the key. Try again.";
+ return t(m.saveFailed);
}
}
@@ -109,6 +113,7 @@ export function VoiceKeyDialog({
providers: readonly TeamHubVoiceProvider[];
tenantId: string;
}) {
+ const t = useT();
const { client } = useTeamHubRuntime();
const [provider, setProvider] = useState(providers[0] ?? "soniox");
// Set when the key is saved but the fresh policy did not turn voice on.
@@ -136,20 +141,20 @@ export function VoiceKeyDialog({
<ModalDialog
closeOnBackdrop
description={
- providers.length > 1
- ? "Voice needs a Soniox or xAI key. Keys are used by everyone on this server."
- : details.purpose
+ providers.length > 1 ? t(m.chooseProvider) : t(details.purpose)
}
onClose={onClose}
size="md"
- title={providers.length > 1 ? "Turn on voice" : `${details.name} key`}
+ title={
+ providers.length > 1
+ ? t(m.turnOnVoice)
+ : t(m.title, { provider: details.name })
+ }
>
<div className="space-y-4 px-5 py-5 text-sm text-app-body">
{turnOnFailed ? (
<>
- <p role="alert">
- The key is saved, but voice could not be turned on. Try again.
- </p>
+ <p role="alert">{t(m.savedButOff)}</p>
<Button
loading={retrying}
onClick={() => {
@@ -158,14 +163,14 @@ export function VoiceKeyDialog({
}}
tone="primary"
>
- Try again
+ {t(commonMessages.tryAgain)}
</Button>
</>
) : (
<>
{providers.length > 1 ? (
<div
- aria-label="Voice provider"
+ aria-label={t(m.voiceProvider)}
className="flex gap-2"
role="group"
>
@@ -182,16 +187,21 @@ export function VoiceKeyDialog({
</div>
) : null}
{providers.length > 1 ? (
- <p className="text-muted-foreground">{details.purpose}</p>
+ <p className="text-muted-foreground">{t(details.purpose)}</p>
) : null}
{status?.can_save === false ? (
<p>
- This server cannot save a {details.name} key here. Whoever runs
- it must set{" "}
- <code className="font-mono">{details.environmentVariable}</code>
- , or set{" "}
- <code className="font-mono">TEAMHUB_SECRET_ENCRYPTION_KEY</code>{" "}
- so keys can be saved here.
+ <RichMessage
+ message={m.cannotSaveHere}
+ tags={{
+ code: (text) => <code className="font-mono">{text}</code>,
+ }}
+ values={{
+ provider: details.name,
+ storageVariable: STORAGE_VARIABLE,
+ variable: details.environmentVariable,
+ }}
+ />
</p>
) : (
<>
@@ -199,19 +209,21 @@ export function VoiceKeyDialog({
href={details.href}
steps={
<ol className="list-decimal space-y-1.5 pl-5">
- {details.steps.map((step) => (
- <li key={step}>{step}</li>
- ))}
+ <li>{t(m.stepOpen, { provider: details.name })}</li>
+ <li>{t(m.stepCreate)}</li>
+ <li>{t(m.stepPaste)}</li>
</ol>
}
/>
<ProviderKeyForm
- describeError={(error) => describeSaveError(error, provider)}
- hint="Stored encrypted and never shown again."
+ describeError={(error) =>
+ describeSaveError(error, provider, t)
+ }
+ hint={t(m.keyHint)}
key={provider}
- label={`${details.name} API key`}
+ label={t(m.apiKey, { provider: details.name })}
// TeamHub answers the save once the voice workers are up.
- pendingLabel="Turning on voice…"
+ pendingLabel={t(m.turningOn)}
save={async (apiKey) => {
await teamHubData(
client.api.PUT("/v0/voice-provider-keys/{provider}", {
diff --git a/apps/web/src/features/rooms/voice-control/voice-key-language.test.tsx b/apps/web/src/features/rooms/voice-control/voice-key-language.test.tsx
new file mode 100644
index 00000000..1b3f30df
--- /dev/null
+++ b/apps/web/src/features/rooms/voice-control/voice-key-language.test.tsx
@@ -0,0 +1,89 @@
+// @vitest-environment jsdom
+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
+import { fireEvent, render, screen } from "@testing-library/react";
+import { afterEach, describe, expect, it, vi } from "vitest";
+
+import { TeamHubRuntimeProvider } from "@/features/teamhub/teamhub-runtime";
+import type { TeamHubVoiceMediaPolicy } from "@/features/teamhub/teamhub-types";
+import { resetLanguageForTest, setLanguage } from "@/i18n/language";
+import zhCN from "@/i18n/locales/zh-CN.json";
+import { createTestTeamHubRuntime } from "@/test/teamhub-test-runtime";
+import { teamHubErrorResponse } from "@/test/teamhub-test-server";
+
+import { VoiceKeyDialog } from "./voice-key-dialog";
+
+const words = zhCN.voiceKey;
+const missing = { source: "none" as const, can_save: true };
+const noKeys: TeamHubVoiceMediaPolicy = {
+ voice_available: true,
+ voice_media_supported: false,
+ live_supported: false,
+ soniox_key: missing,
+ xai_key: missing,
+};
+
+function renderDialog(
+ runtime: ReturnType<typeof createTestTeamHubRuntime>,
+ policy: TeamHubVoiceMediaPolicy,
+) {
+ render(
+ <QueryClientProvider client={new QueryClient()}>
+ <TeamHubRuntimeProvider runtime={runtime}>
+ <VoiceKeyDialog
+ onClose={vi.fn()}
+ onReady={vi.fn()}
+ policy={policy}
+ providers={["soniox"]}
+ tenantId="tenant-northstar"
+ />
+ </TeamHubRuntimeProvider>
+ </QueryClientProvider>,
+ );
+}
+
+describe("the voice key dialog in the language on screen", () => {
+ afterEach(() => {
+ resetLanguageForTest();
+ });
+
+ it("keeps the provider's name inside the translated sentences", async () => {
+ await setLanguage("zh-CN");
+ const runtime = createTestTeamHubRuntime();
+ runtime.server.on("PUT", "/v0/voice-provider-keys/{provider}", () =>
+ teamHubErrorResponse(400, "VOICE_KEY_REJECTED", "unrelated server prose"),
+ );
+ renderDialog(runtime, noKeys);
+ expect(
+ screen.getByRole("dialog", {
+ name: words.title.replace("{provider}", "Soniox"),
+ }),
+ ).toBeVisible();
+ expect(
+ screen.getByText(words.stepOpen.replace("{provider}", "Soniox")),
+ ).toBeVisible();
+ fireEvent.change(
+ screen.getByLabelText(words.apiKey.replace("{provider}", "Soniox")),
+ { target: { value: "bad-key" } },
+ );
+ fireEvent.click(
+ screen.getByRole("button", { name: zhCN.connectors.saveKey }),
+ );
+ expect(
+ await screen.findByText(
+ words.keyRejected.replace("{provider}", "Soniox"),
+ ),
+ ).toBeVisible();
+ });
+
+ it("leaves the two settings a server operator must type as they are", async () => {
+ await setLanguage("zh-CN");
+ renderDialog(createTestTeamHubRuntime(), {
+ ...noKeys,
+ soniox_key: { source: "none", can_save: false },
+ });
+ for (const name of ["SONIOX_API_KEY", "TEAMHUB_SECRET_ENCRYPTION_KEY"]) {
+ expect(screen.getByText(name).tagName).toBe("CODE");
+ }
+ expect(document.body.textContent).not.toContain("This server");
+ });
+});
diff --git a/apps/web/src/features/rooms/voice-control/voice-key.messages.ts b/apps/web/src/features/rooms/voice-control/voice-key.messages.ts
new file mode 100644
index 00000000..b51f4d10
--- /dev/null
+++ b/apps/web/src/features/rooms/voice-control/voice-key.messages.ts
@@ -0,0 +1,32 @@
+import { defineMessages } from "@/i18n/messages";
+
+/** The dialog that takes the Soniox or xAI key a voice action needs. */
+export const voiceKeyMessages = defineMessages("voiceKey", {
+ title: "{provider} key",
+ turnOnVoice: "Turn on voice",
+ chooseProvider:
+ "Voice needs a Soniox or xAI key. Keys are used by everyone on this server.",
+ voiceProvider: "Voice provider",
+ sonioxPurpose:
+ "Transcribes meetings, Pocket Notes dictation and Voice Mode dictation.",
+ xaiPurpose: "Turns Voice Mode into a live conversation with Grok.",
+ stepOpen: "Open the {provider} Console and sign in or create an account.",
+ stepCreate: "Create an API key.",
+ stepPaste: "Copy the key, paste it below, and select Save key.",
+ apiKey: "{provider} API key",
+ keyHint: "Stored encrypted and never shown again.",
+ turningOn: "Turning on voice…",
+ savedButOff: "The key is saved, but voice could not be turned on. Try again.",
+ cannotSaveHere:
+ "This server cannot save a {provider} key here. Whoever runs it must set <code>{variable}</code>, or set <code>{storageVariable}</code> so keys can be saved here.",
+ invalidKey: "Enter a valid API key.",
+ keyRejected: "{provider} rejected this key. Check it and try again.",
+ keyFromEnvironment:
+ "This server sets the {provider} key with {variable}, so it cannot be changed here.",
+ storageUnavailable:
+ "This server cannot store keys. Whoever runs it must set {storageVariable}.",
+ providerUnreachable:
+ "Could not reach {provider} to check the key. Try again in a moment.",
+ voiceOff: "Voice is turned off on this server.",
+ saveFailed: "Could not save the key. Try again.",
+});
diff --git a/apps/web/src/i18n/locales/zh-CN.glossary.md b/apps/web/src/i18n/locales/zh-CN.glossary.md
index 4b7daaba..2814dee2 100644
--- a/apps/web/src/i18n/locales/zh-CN.glossary.md
+++ b/apps/web/src/i18n/locales/zh-CN.glossary.md
@@ -75,6 +75,7 @@ elsewhere.
| Meeting summary | 会议摘要 | |
| Voice Mode | 语音模式 | |
| Dictation | 听写 | Speaking text into a note or the composer. |
+| Voice provider | 语音服务商 | Soniox or xAI; the names stay as they are. |
| Draft | 草稿 | |
| Local model | 本地模型 | |
| Subscription | 订阅 | A model source. |
diff --git a/apps/web/src/i18n/locales/zh-CN.json b/apps/web/src/i18n/locales/zh-CN.json
index e354b0b3..3342d5e2 100644
--- a/apps/web/src/i18n/locales/zh-CN.json
+++ b/apps/web/src/i18n/locales/zh-CN.json
@@ -2369,5 +2369,28 @@
"deletePageQuestion": "要删除“{page}”这一页吗?",
"deleteThisNote": "要删除这篇笔记吗?",
"couldNotDelete": "无法删除,请再试一次。"
+ },
+ "voiceKey": {
+ "title": "{provider} 密钥",
+ "turnOnVoice": "开启语音",
+ "chooseProvider": "语音需要 Soniox 或 xAI 的密钥。这台服务器上的所有人共用这些密钥。",
+ "voiceProvider": "语音服务商",
+ "sonioxPurpose": "用于会议转写,以及“随手记”和语音模式的听写。",
+ "xaiPurpose": "让语音模式变成与 Grok 的实时对话。",
+ "stepOpen": "打开 {provider} Console,登录或创建账号。",
+ "stepCreate": "创建一个 API 密钥。",
+ "stepPaste": "复制密钥,粘贴到下方,然后选择“保存密钥”。",
+ "apiKey": "{provider} API 密钥",
+ "keyHint": "加密保存,之后不会再显示。",
+ "turningOn": "正在开启语音…",
+ "savedButOff": "密钥已保存,但语音未能开启。请再试一次。",
+ "cannotSaveHere": "这台服务器无法在这里保存 {provider} 密钥。需要由运行它的人设置 <code>{variable}</code>,或者设置 <code>{storageVariable}</code>,这样才能在这里保存密钥。",
+ "invalidKey": "请输入有效的 API 密钥。",
+ "keyRejected": "{provider} 拒绝了这个密钥。请检查后再试一次。",
+ "keyFromEnvironment": "这台服务器通过 {variable} 设置 {provider} 密钥,因此无法在这里修改。",
+ "storageUnavailable": "这台服务器无法保存密钥。需要由运行它的人设置 {storageVariable}。",
+ "providerUnreachable": "无法连接 {provider} 来检查密钥。请稍后再试。",
+ "voiceOff": "这台服务器已关闭语音。",
+ "saveFailed": "无法保存密钥,请再试一次。"
}
}