Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

Localize teleprompter readouts

My-Denia7dba0f941f27
diff --git a/src/components/launch/NotesToolbar.browser.test.tsx b/src/components/launch/NotesToolbar.browser.test.tsx
index 47889c730..5861a0671 100644
--- a/src/components/launch/NotesToolbar.browser.test.tsx
+++ b/src/components/launch/NotesToolbar.browser.test.tsx
@@ -12,7 +12,8 @@ vi.mock("@/components/ui/tooltip", () => ({
}));
vi.mock("@/contexts/I18nContext", () => ({
- useScopedT: () => (key: string) => {
+ useI18n: () => ({ locale: "en" }),
+ useScopedT: () => (key: string, vars?: Record<string, string | number>) => {
const labels: Record<string, string> = {
"tooltips.notesToolbar.play": "Play",
"tooltips.notesToolbar.pause": "Pause",
@@ -23,8 +24,12 @@ vi.mock("@/contexts/I18nContext", () => ({
"tooltips.notesToolbar.decreaseFontSize": "Decrease font size",
"tooltips.notesToolbar.increaseFontSize": "Increase font size",
"tooltips.notesToolbar.mirror": "Mirror",
+ "units.pixelsPerSecond": "{{value}} px/s",
+ "units.pixels": "{{value}} px",
};
- return labels[key] ?? key;
+ return (labels[key] ?? key).replace(/\{\{(\w+)\}\}/g, (_, name: string) =>
+ String(vars?.[name] ?? `{{${name}}}`),
+ );
},
}));
diff --git a/src/components/launch/NotesToolbar.test.tsx b/src/components/launch/NotesToolbar.test.tsx
index e95e04c1a..6564b60d2 100644
--- a/src/components/launch/NotesToolbar.test.tsx
+++ b/src/components/launch/NotesToolbar.test.tsx
@@ -1,31 +1,16 @@
import "@testing-library/jest-dom";
-import { render, screen } from "@testing-library/react";
+import { render, screen, within } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import type { Editor } from "@tiptap/react";
+import { type ReactNode, useLayoutEffect } from "react";
import { describe, expect, it, vi } from "vitest";
+import { I18nProvider, useI18n } from "@/contexts/I18nContext";
import { NotesToolbar, type NotesToolbarProps } from "./NotesToolbar";
vi.mock("@/components/ui/tooltip", () => ({
Tooltip: ({ children }: { children: React.ReactNode }) => children,
}));
-vi.mock("@/contexts/I18nContext", () => ({
- useScopedT: () => (key: string) => {
- const labels: Record<string, string> = {
- "tooltips.notesToolbar.play": "Play",
- "tooltips.notesToolbar.pause": "Pause",
- "tooltips.notesToolbar.speed": "Scroll speed",
- "tooltips.notesToolbar.decreaseSpeed": "Decrease scroll speed",
- "tooltips.notesToolbar.increaseSpeed": "Increase scroll speed",
- "tooltips.notesToolbar.fontSize": "Font size",
- "tooltips.notesToolbar.decreaseFontSize": "Decrease font size",
- "tooltips.notesToolbar.increaseFontSize": "Increase font size",
- "tooltips.notesToolbar.mirror": "Mirror",
- };
- return labels[key] ?? key;
- },
-}));
-
function createEditor(): Editor {
const chain: Record<string, ReturnType<typeof vi.fn>> = {};
for (const command of [
@@ -68,15 +53,42 @@ function createProps(overrides: Partial<NotesToolbarProps> = {}): NotesToolbarPr
};
}
+function ActiveLocale({ children, locale }: { children: ReactNode; locale: string }) {
+ const { setLocale } = useI18n();
+
+ useLayoutEffect(() => {
+ setLocale(locale);
+ }, [locale, setLocale]);
+
+ return children;
+}
+
+function renderToolbar(props: NotesToolbarProps, locale = "en") {
+ return render(
+ <I18nProvider>
+ <ActiveLocale locale={locale}>
+ <NotesToolbar {...props} />
+ </ActiveLocale>
+ </I18nProvider>,
+ );
+}
+
describe("NotesToolbar teleprompter controls", () => {
it("exposes values and dispatches every manual control", async () => {
const user = userEvent.setup();
const props = createProps();
- render(<NotesToolbar {...props} />);
+ renderToolbar(props);
- expect(screen.getByRole("status", { name: "Scroll speed" })).toHaveTextContent("40 px/s");
- expect(screen.getByRole("status", { name: "Font size" })).toHaveTextContent("16 px");
- expect(screen.getByRole("button", { name: "Mirror" })).toHaveAttribute("aria-pressed", "false");
+ const speed = within(screen.getByRole("group", { name: "Scroll speed" })).getByRole("status");
+ const fontSize = within(screen.getByRole("group", { name: "Font size" })).getByRole("status");
+ expect(speed).not.toHaveAccessibleName();
+ expect(speed).toHaveTextContent("40 px/s");
+ expect(fontSize).not.toHaveAccessibleName();
+ expect(fontSize).toHaveTextContent("16 px");
+ expect(screen.getByRole("button", { name: "Mirror horizontally" })).toHaveAttribute(
+ "aria-pressed",
+ "false",
+ );
expect(screen.getByRole("button", { name: "Decrease scroll speed" })).not.toHaveAttribute(
"aria-pressed",
);
@@ -84,12 +96,12 @@ describe("NotesToolbar teleprompter controls", () => {
"aria-pressed",
);
- await user.click(screen.getByRole("button", { name: "Play" }));
+ await user.click(screen.getByRole("button", { name: "Start auto-scroll" }));
await user.click(screen.getByRole("button", { name: "Decrease scroll speed" }));
await user.click(screen.getByRole("button", { name: "Increase scroll speed" }));
await user.click(screen.getByRole("button", { name: "Decrease font size" }));
await user.click(screen.getByRole("button", { name: "Increase font size" }));
- await user.click(screen.getByRole("button", { name: "Mirror" }));
+ await user.click(screen.getByRole("button", { name: "Mirror horizontally" }));
expect(props.onTogglePlaying).toHaveBeenCalledOnce();
expect(props.onDecreaseSpeed).toHaveBeenCalledOnce();
@@ -100,18 +112,33 @@ describe("NotesToolbar teleprompter controls", () => {
});
it("disables controls at their bounds", () => {
- const { rerender } = render(<NotesToolbar {...createProps({ speed: 10, fontSize: 14 })} />);
+ const { rerender } = renderToolbar(createProps({ speed: 10, fontSize: 14 }));
expect(screen.getByRole("button", { name: "Decrease scroll speed" })).toBeDisabled();
expect(screen.getByRole("button", { name: "Decrease font size" })).toBeDisabled();
- rerender(<NotesToolbar {...createProps({ speed: 100, fontSize: 48 })} />);
+ rerender(
+ <I18nProvider>
+ <NotesToolbar {...createProps({ speed: 100, fontSize: 48 })} />
+ </I18nProvider>,
+ );
expect(screen.getByRole("button", { name: "Increase scroll speed" })).toBeDisabled();
expect(screen.getByRole("button", { name: "Increase font size" })).toBeDisabled();
});
it("keeps playback paused and disabled until the editor is ready", () => {
- render(<NotesToolbar {...createProps({ editor: null })} />);
- expect(screen.getByRole("button", { name: "Play" })).toBeDisabled();
- expect(screen.queryByRole("button", { name: "Pause" })).not.toBeInTheDocument();
+ renderToolbar(createProps({ editor: null }));
+ expect(screen.getByRole("button", { name: "Start auto-scroll" })).toBeDisabled();
+ expect(screen.queryByRole("button", { name: "Pause auto-scroll" })).not.toBeInTheDocument();
+ });
+
+ it("formats readout values for the active locale", () => {
+ renderToolbar(createProps(), "ar");
+ const speed = within(screen.getByRole("group", { name: "سرعة التمرير" })).getByRole("status");
+ const fontSize = within(screen.getByRole("group", { name: "حجم الخط" })).getByRole("status");
+
+ expect(speed).not.toHaveAccessibleName();
+ expect(speed).toHaveTextContent(`${new Intl.NumberFormat("ar").format(40)} بكسل/ثانية`);
+ expect(fontSize).not.toHaveAccessibleName();
+ expect(fontSize).toHaveTextContent(`${new Intl.NumberFormat("ar").format(16)} بكسل`);
});
});
diff --git a/src/components/launch/NotesToolbar.tsx b/src/components/launch/NotesToolbar.tsx
index 245347468..0fd14e3e0 100644
--- a/src/components/launch/NotesToolbar.tsx
+++ b/src/components/launch/NotesToolbar.tsx
@@ -13,9 +13,9 @@ import {
Quote,
Strikethrough,
} from "lucide-react";
-import { type ReactNode, useEffect, useReducer } from "react";
+import { type ReactNode, useEffect, useMemo, useReducer } from "react";
import { Tooltip } from "@/components/ui/tooltip";
-import { useScopedT } from "@/contexts/I18nContext";
+import { useI18n, useScopedT } from "@/contexts/I18nContext";
import { cn } from "@/lib/utils";
import {
MAX_NOTES_FONT_SIZE,
@@ -113,7 +113,9 @@ export function NotesToolbar({
onToggleMirror,
}: NotesToolbarProps) {
useEditorRevision(editor);
+ const { locale } = useI18n();
const t = useScopedT("launch");
+ const numberFormatter = useMemo(() => new Intl.NumberFormat(locale), [locale]);
return (
<div className="flex w-full min-w-0 max-w-full flex-col gap-1.5 rounded-[0.625rem] border border-gray-200 bg-gray-50 p-1.5">
@@ -232,12 +234,8 @@ export function NotesToolbar({
>
<Minus size={16} />
</ToolbarButton>
- <output
- aria-label={t("tooltips.notesToolbar.speed")}
- aria-live="polite"
- className="min-w-14 text-center text-xs tabular-nums text-gray-700"
- >
- {speed} px/s
+ <output className="min-w-14 text-center text-xs tabular-nums text-gray-700">
+ {t("units.pixelsPerSecond", { value: numberFormatter.format(speed) })}
</output>
<ToolbarButton
aria-label={t("tooltips.notesToolbar.increaseSpeed")}
@@ -264,12 +262,8 @@ export function NotesToolbar({
>
<Minus size={16} />
</ToolbarButton>
- <output
- aria-label={t("tooltips.notesToolbar.fontSize")}
- aria-live="polite"
- className="min-w-10 text-center text-xs tabular-nums text-gray-700"
- >
- {fontSize} px
+ <output className="min-w-10 text-center text-xs tabular-nums text-gray-700">
+ {t("units.pixels", { value: numberFormatter.format(fontSize) })}
</output>
<ToolbarButton
aria-label={t("tooltips.notesToolbar.increaseFontSize")}
diff --git a/src/components/launch/NotesWindow.test.tsx b/src/components/launch/NotesWindow.test.tsx
index c0ebb9fb0..4332bc126 100644
--- a/src/components/launch/NotesWindow.test.tsx
+++ b/src/components/launch/NotesWindow.test.tsx
@@ -32,7 +32,8 @@ vi.mock("@/components/ui/tooltip", () => ({
}));
vi.mock("@/contexts/I18nContext", () => ({
- useScopedT: () => (key: string) => {
+ useI18n: () => ({ locale: "en" }),
+ useScopedT: () => (key: string, vars?: Record<string, string | number>) => {
const labels: Record<string, string> = {
"tooltips.notesToolbar.play": "Play",
"tooltips.notesToolbar.pause": "Pause",
@@ -43,8 +44,12 @@ vi.mock("@/contexts/I18nContext", () => ({
"tooltips.notesToolbar.decreaseFontSize": "Decrease font size",
"tooltips.notesToolbar.increaseFontSize": "Increase font size",
"tooltips.notesToolbar.mirror": "Mirror",
+ "units.pixelsPerSecond": "{{value}} px/s",
+ "units.pixels": "{{value}} px",
};
- return labels[key] ?? key;
+ return (labels[key] ?? key).replace(/\{\{(\w+)\}\}/g, (_, name: string) =>
+ String(vars?.[name] ?? `{{${name}}}`),
+ );
},
}));
diff --git a/src/i18n/locales/ar/launch.json b/src/i18n/locales/ar/launch.json
index 08cb8a4e5..61d028e09 100644
--- a/src/i18n/locales/ar/launch.json
+++ b/src/i18n/locales/ar/launch.json
@@ -32,6 +32,10 @@
"mirror": "عكس أفقي"
}
},
+ "units": {
+ "pixelsPerSecond": "{{value}} بكسل/ثانية",
+ "pixels": "{{value}} بكسل"
+ },
"audio": {
"enableSystemAudio": "تفعيل صوت النظام",
"disableSystemAudio": "تعطيل صوت النظام",
diff --git a/src/i18n/locales/en/launch.json b/src/i18n/locales/en/launch.json
index 02b8ca626..dcdefb59e 100644
--- a/src/i18n/locales/en/launch.json
+++ b/src/i18n/locales/en/launch.json
@@ -32,6 +32,10 @@
"mirror": "Mirror horizontally"
}
},
+ "units": {
+ "pixelsPerSecond": "{{value}} px/s",
+ "pixels": "{{value}} px"
+ },
"audio": {
"enableSystemAudio": "Enable system audio",
"disableSystemAudio": "Disable system audio",
diff --git a/src/i18n/locales/es/launch.json b/src/i18n/locales/es/launch.json
index c5fb8d10e..09f5764dc 100644
--- a/src/i18n/locales/es/launch.json
+++ b/src/i18n/locales/es/launch.json
@@ -32,6 +32,10 @@
"mirror": "Reflejar horizontalmente"
}
},
+ "units": {
+ "pixelsPerSecond": "{{value}} píxeles/s",
+ "pixels": "{{value}} píxeles"
+ },
"audio": {
"enableSystemAudio": "Activar audio del sistema",
"disableSystemAudio": "Desactivar audio del sistema",
diff --git a/src/i18n/locales/fr/launch.json b/src/i18n/locales/fr/launch.json
index 5c49eafd1..4b2837f51 100644
--- a/src/i18n/locales/fr/launch.json
+++ b/src/i18n/locales/fr/launch.json
@@ -32,6 +32,10 @@
"mirror": "Miroir horizontal"
}
},
+ "units": {
+ "pixelsPerSecond": "{{value}} pixels/s",
+ "pixels": "{{value}} pixels"
+ },
"audio": {
"enableSystemAudio": "Activer l'audio système",
"disableSystemAudio": "Désactiver l'audio système",
diff --git a/src/i18n/locales/it/launch.json b/src/i18n/locales/it/launch.json
index 7136316a1..14993fe3a 100644
--- a/src/i18n/locales/it/launch.json
+++ b/src/i18n/locales/it/launch.json
@@ -32,6 +32,10 @@
"mirror": "Specchia orizzontalmente"
}
},
+ "units": {
+ "pixelsPerSecond": "{{value}} pixel/s",
+ "pixels": "{{value}} pixel"
+ },
"audio": {
"enableSystemAudio": "Abilita audio di sistema",
"disableSystemAudio": "Disabilita audio di sistema",
diff --git a/src/i18n/locales/ja-JP/launch.json b/src/i18n/locales/ja-JP/launch.json
index bb564e44b..edbc0d19b 100644
--- a/src/i18n/locales/ja-JP/launch.json
+++ b/src/i18n/locales/ja-JP/launch.json
@@ -32,6 +32,10 @@
"mirror": "左右反転"
}
},
+ "units": {
+ "pixelsPerSecond": "{{value}} px/秒",
+ "pixels": "{{value}} px"
+ },
"audio": {
"enableSystemAudio": "システム音声を有効にする",
"disableSystemAudio": "システム音声を無効にする",
diff --git a/src/i18n/locales/ko-KR/launch.json b/src/i18n/locales/ko-KR/launch.json
index bd297c0c7..6037709d5 100644
--- a/src/i18n/locales/ko-KR/launch.json
+++ b/src/i18n/locales/ko-KR/launch.json
@@ -32,6 +32,10 @@
"mirror": "좌우 반전"
}
},
+ "units": {
+ "pixelsPerSecond": "{{value}} px/초",
+ "pixels": "{{value}} px"
+ },
"audio": {
"enableSystemAudio": "시스템 오디오 활성화",
"disableSystemAudio": "시스템 오디오 비활성화",
diff --git a/src/i18n/locales/pt-BR/launch.json b/src/i18n/locales/pt-BR/launch.json
index 1470d4cce..e24dedb60 100644
--- a/src/i18n/locales/pt-BR/launch.json
+++ b/src/i18n/locales/pt-BR/launch.json
@@ -32,6 +32,10 @@
"mirror": "Espelhar horizontalmente"
}
},
+ "units": {
+ "pixelsPerSecond": "{{value}} pixels/s",
+ "pixels": "{{value}} pixels"
+ },
"audio": {
"enableSystemAudio": "Ativar áudio do sistema",
"disableSystemAudio": "Desativar áudio do sistema",
diff --git a/src/i18n/locales/ru/launch.json b/src/i18n/locales/ru/launch.json
index 7836e4b87..1a105fefc 100644
--- a/src/i18n/locales/ru/launch.json
+++ b/src/i18n/locales/ru/launch.json
@@ -32,6 +32,10 @@
"mirror": "Отразить по горизонтали"
}
},
+ "units": {
+ "pixelsPerSecond": "{{value}} пикс/с",
+ "pixels": "{{value}} пикс"
+ },
"audio": {
"enableSystemAudio": "Включить системное аудио",
"disableSystemAudio": "Отключить системное аудио",
diff --git a/src/i18n/locales/tr/launch.json b/src/i18n/locales/tr/launch.json
index 05e415afb..97a3f3401 100644
--- a/src/i18n/locales/tr/launch.json
+++ b/src/i18n/locales/tr/launch.json
@@ -32,6 +32,10 @@
"mirror": "Yatay aynala"
}
},
+ "units": {
+ "pixelsPerSecond": "{{value}} piks/sn",
+ "pixels": "{{value}} piks"
+ },
"audio": {
"enableSystemAudio": "Sistem sesini etkinleştir",
"disableSystemAudio": "Sistem sesini devre dışı bırak",
diff --git a/src/i18n/locales/vi/launch.json b/src/i18n/locales/vi/launch.json
index e1488e425..7b1b6141c 100644
--- a/src/i18n/locales/vi/launch.json
+++ b/src/i18n/locales/vi/launch.json
@@ -32,6 +32,10 @@
"mirror": "Lật ngang"
}
},
+ "units": {
+ "pixelsPerSecond": "{{value}} px/giây",
+ "pixels": "{{value}} px"
+ },
"audio": {
"enableSystemAudio": "Bật âm thanh hệ thống",
"disableSystemAudio": "Tắt âm thanh hệ thống",
diff --git a/src/i18n/locales/zh-CN/launch.json b/src/i18n/locales/zh-CN/launch.json
index f67815fce..3fe856e2d 100644
--- a/src/i18n/locales/zh-CN/launch.json
+++ b/src/i18n/locales/zh-CN/launch.json
@@ -32,6 +32,10 @@
"mirror": "水平镜像"
}
},
+ "units": {
+ "pixelsPerSecond": "{{value}} 像素/秒",
+ "pixels": "{{value}} 像素"
+ },
"audio": {
"enableSystemAudio": "启用系统音频",
"disableSystemAudio": "禁用系统音频",
diff --git a/src/i18n/locales/zh-TW/launch.json b/src/i18n/locales/zh-TW/launch.json
index 5e8fbf10d..d34acfebf 100644
--- a/src/i18n/locales/zh-TW/launch.json
+++ b/src/i18n/locales/zh-TW/launch.json
@@ -32,6 +32,10 @@
"mirror": "水平鏡像"
}
},
+ "units": {
+ "pixelsPerSecond": "{{value}} 像素/秒",
+ "pixels": "{{value}} 像素"
+ },
"audio": {
"enableSystemAudio": "啟用系統音訊",
"disableSystemAudio": "停用系統音訊",