Skip to content

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

feat(annotations): start a new text annotation with localised text

Etienne Lescotc9f4f96d4fe2
diff --git a/crates/compositor/src/text_linux.rs b/crates/compositor/src/text_linux.rs
index c2602d4b1..64c590c74 100644
--- a/crates/compositor/src/text_linux.rs
+++ b/crates/compositor/src/text_linux.rs
@@ -395,6 +395,40 @@ mod tests {
);
}
+ /// Chaque texte par defaut d'annotation produit-il de l'encre sur CETTE
+ /// machine ?
+ ///
+ /// L'app propose un texte localise a la creation ("Hello", "你好",
+ /// "مرحبا"...). Si la police systeme ne couvre pas le script, cosmic-text
+ /// rend du tofu ou rien du tout, et l'utilisateur voit une annotation vide
+ /// qu'il n'a pas ecrite. Le test ne PEUT pas garantir la couverture d'une
+ /// machine inconnue — il documente ce qui manque sur celle qui l'execute,
+ /// ce qui est exactement l'information utile quand quelqu'un rapporte
+ /// « mon annotation est invisible ».
+ #[test]
+ fn the_localised_default_texts_render_on_this_machine() {
+ let raster = TextRasterizer::new().expect("rasterizer");
+ let samples = [
+ ("en", "Hello"), ("fr", "Bonjour"), ("es", "Hola"), ("it", "Ciao"),
+ ("pt-BR", "Olá"), ("ru", "Привет"), ("tr", "Merhaba"), ("vi", "Xin chào"),
+ ("ar", "مرحبا"), ("ja-JP", "こんにちは"), ("ko-KR", "안녕하세요"),
+ ("zh-CN", "你好"), ("zh-TW", "你好"),
+ ];
+ let mut blank = Vec::new();
+ for (locale, text) in samples {
+ let atlas = raster.build_atlas(&spec(text, "center")).expect("atlas");
+ let ink = atlas.iter().filter(|byte| **byte > 16).count();
+ println!(" {locale:6} {text:12} -> {ink} px d'encre");
+ if ink == 0 {
+ blank.push(locale);
+ }
+ }
+ assert!(
+ blank.is_empty(),
+ "aucune police installee ne couvre: {blank:?} — l'annotation par defaut y serait invisible"
+ );
+ }
+
#[test]
fn one_short_line_is_centred_vertically_in_its_box() {
// L'overlay web pose `alignItems: center` et Windows fait pareil
diff --git a/src/i18n/locales/ar/settings.json b/src/i18n/locales/ar/settings.json
index 39e893a6c..d2ab9c645 100644
--- a/src/i18n/locales/ar/settings.json
+++ b/src/i18n/locales/ar/settings.json
@@ -149,6 +149,7 @@
"typeBlur": "تمويه",
"textContent": "محتوى النص",
"textPlaceholder": "أدخل النص هنا...",
+ "defaultText": "مرحبا",
"fontStyle": "نمط الخط",
"selectStyle": "حدد النمط",
"size": "الحجم",
diff --git a/src/i18n/locales/en/settings.json b/src/i18n/locales/en/settings.json
index 8ebfb79ed..4b8358ea1 100644
--- a/src/i18n/locales/en/settings.json
+++ b/src/i18n/locales/en/settings.json
@@ -149,6 +149,7 @@
"typeBlur": "Blur",
"textContent": "Text Content",
"textPlaceholder": "Enter your text...",
+ "defaultText": "Hello",
"fontStyle": "Font Style",
"selectStyle": "Select style",
"size": "Size",
diff --git a/src/i18n/locales/es/settings.json b/src/i18n/locales/es/settings.json
index 68bd83ec0..d7cb0cb9a 100644
--- a/src/i18n/locales/es/settings.json
+++ b/src/i18n/locales/es/settings.json
@@ -149,6 +149,7 @@
"typeBlur": "Desenfoque",
"textContent": "Contenido de texto",
"textPlaceholder": "Escribe tu texto...",
+ "defaultText": "Hola",
"fontStyle": "Estilo de fuente",
"selectStyle": "Seleccionar estilo",
"size": "Tamaño",
diff --git a/src/i18n/locales/fr/settings.json b/src/i18n/locales/fr/settings.json
index 13f650f5f..afba3a562 100644
--- a/src/i18n/locales/fr/settings.json
+++ b/src/i18n/locales/fr/settings.json
@@ -149,6 +149,7 @@
"typeBlur": "Flou",
"textContent": "Contenu du texte",
"textPlaceholder": "Saisissez votre texte...",
+ "defaultText": "Bonjour",
"fontStyle": "Style de police",
"selectStyle": "Choisir un style",
"size": "Taille",
diff --git a/src/i18n/locales/it/settings.json b/src/i18n/locales/it/settings.json
index 9f6f82393..eeaa72d60 100644
--- a/src/i18n/locales/it/settings.json
+++ b/src/i18n/locales/it/settings.json
@@ -149,6 +149,7 @@
"typeBlur": "Sfocatura",
"textContent": "Contenuto testo",
"textPlaceholder": "Inserisci il tuo testo...",
+ "defaultText": "Ciao",
"fontStyle": "Stile carattere",
"selectStyle": "Seleziona stile",
"size": "Dimensione",
diff --git a/src/i18n/locales/ja-JP/settings.json b/src/i18n/locales/ja-JP/settings.json
index e7e4bb5dc..0dbc20e65 100644
--- a/src/i18n/locales/ja-JP/settings.json
+++ b/src/i18n/locales/ja-JP/settings.json
@@ -149,6 +149,7 @@
"typeBlur": "ぼかし",
"textContent": "テキスト内容",
"textPlaceholder": "テキストを入力してください...",
+ "defaultText": "こんにちは",
"fontStyle": "フォントスタイル",
"selectStyle": "スタイルを選択",
"size": "サイズ",
diff --git a/src/i18n/locales/ko-KR/settings.json b/src/i18n/locales/ko-KR/settings.json
index 4e1d23ca9..4f3de7c7a 100644
--- a/src/i18n/locales/ko-KR/settings.json
+++ b/src/i18n/locales/ko-KR/settings.json
@@ -149,6 +149,7 @@
"typeBlur": "블러",
"textContent": "텍스트 내용",
"textPlaceholder": "텍스트를 입력하세요...",
+ "defaultText": "안녕하세요",
"fontStyle": "폰트 스타일",
"selectStyle": "스타일 선택",
"size": "크기",
diff --git a/src/i18n/locales/pt-BR/settings.json b/src/i18n/locales/pt-BR/settings.json
index 95f63653e..b0f492a2e 100644
--- a/src/i18n/locales/pt-BR/settings.json
+++ b/src/i18n/locales/pt-BR/settings.json
@@ -149,6 +149,7 @@
"typeBlur": "Desfoque",
"textContent": "Conteúdo do Texto",
"textPlaceholder": "Digite seu texto...",
+ "defaultText": "Olá",
"fontStyle": "Estilo da Fonte",
"selectStyle": "Selecionar estilo",
"size": "Tamanho",
diff --git a/src/i18n/locales/ru/settings.json b/src/i18n/locales/ru/settings.json
index ccec01ca2..8ff6591e7 100644
--- a/src/i18n/locales/ru/settings.json
+++ b/src/i18n/locales/ru/settings.json
@@ -149,6 +149,7 @@
"typeBlur": "Размытие",
"textContent": "Содержание текста",
"textPlaceholder": "Введите ваш текст...",
+ "defaultText": "Привет",
"fontStyle": "Стиль шрифта",
"selectStyle": "Выбрать стиль",
"size": "Размер",
diff --git a/src/i18n/locales/tr/settings.json b/src/i18n/locales/tr/settings.json
index d81852dd4..8193da831 100644
--- a/src/i18n/locales/tr/settings.json
+++ b/src/i18n/locales/tr/settings.json
@@ -149,6 +149,7 @@
"typeBlur": "Bulanık",
"textContent": "Metin İçeriği",
"textPlaceholder": "Metninizi girin...",
+ "defaultText": "Merhaba",
"fontStyle": "Yazı Tipi Stili",
"selectStyle": "Stil seçin",
"size": "Boyut",
diff --git a/src/i18n/locales/vi/settings.json b/src/i18n/locales/vi/settings.json
index c2fc75d7b..2d1d201a8 100644
--- a/src/i18n/locales/vi/settings.json
+++ b/src/i18n/locales/vi/settings.json
@@ -149,6 +149,7 @@
"typeBlur": "Làm mờ",
"textContent": "Nội dung văn bản",
"textPlaceholder": "Nhập văn bản của bạn...",
+ "defaultText": "Xin chào",
"fontStyle": "Kiểu phông chữ",
"selectStyle": "Chọn kiểu",
"size": "Kích thước",
diff --git a/src/i18n/locales/zh-CN/settings.json b/src/i18n/locales/zh-CN/settings.json
index 1fd9f2a83..ca6c78910 100644
--- a/src/i18n/locales/zh-CN/settings.json
+++ b/src/i18n/locales/zh-CN/settings.json
@@ -149,6 +149,7 @@
"typeBlur": "模糊",
"textContent": "文本内容",
"textPlaceholder": "输入您的文本...",
+ "defaultText": "你好",
"fontStyle": "字体样式",
"selectStyle": "选择样式",
"size": "大小",
diff --git a/src/i18n/locales/zh-TW/settings.json b/src/i18n/locales/zh-TW/settings.json
index 1210a1db0..8fe3c9ffa 100644
--- a/src/i18n/locales/zh-TW/settings.json
+++ b/src/i18n/locales/zh-TW/settings.json
@@ -150,6 +150,7 @@
"typeBlur": "模糊",
"textContent": "文字內容",
"textPlaceholder": "輸入您的文字...",
+ "defaultText": "你好",
"fontStyle": "字體樣式",
"selectStyle": "選擇樣式",
"size": "大小",
diff --git a/src/lib/ai-edition/store/useTimeline.test.ts b/src/lib/ai-edition/store/useTimeline.test.ts
index ae57345ec..e6fb3632c 100644
--- a/src/lib/ai-edition/store/useTimeline.test.ts
+++ b/src/lib/ai-edition/store/useTimeline.test.ts
@@ -1,9 +1,17 @@
import { act, renderHook, waitFor } from "@testing-library/react";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+import { I18nProvider } from "@/contexts/I18nContext";
import type { AxcutDocument } from "../schema";
import { useProjectStore } from "./projectStore";
import { useTimeline } from "./useTimeline";
+/**
+ * `useTimeline` reads the locale — `addAnnotation` seeds a new region with the
+ * translated default text — so it needs the provider. One helper rather than a
+ * wrapper argument on every call site.
+ */
+const renderTimeline = () => renderHook(() => useTimeline(), { wrapper: I18nProvider });
+
const probeVideoDurationMock = vi.hoisted(() => vi.fn());
const probeVideoDimensionsMock = vi.hoisted(() =>
vi.fn().mockResolvedValue({ width: 1920, height: 1080 }),
@@ -135,7 +143,7 @@ describe("useTimeline.insertClipAt background duration probe", () => {
// between the real and placeholder duration, corrupting their
// positions and producing visual overlap.
probeVideoDurationMock.mockResolvedValue(5);
- const { result } = renderHook(() => useTimeline());
+ const { result } = renderTimeline();
await act(async () => {
await result.current.insertClipAt("asset_2", 1);
@@ -197,7 +205,7 @@ describe("useTimeline.moveClip / duplicateClip (delegates to document/timeline.t
});
it("moveClip reorders clips and persists the resequenced timeline", async () => {
- const { result } = renderHook(() => useTimeline());
+ const { result } = renderTimeline();
await act(async () => {
await result.current.moveClip("clip_a", 1);
});
@@ -208,7 +216,7 @@ describe("useTimeline.moveClip / duplicateClip (delegates to document/timeline.t
});
it("moveClip no-ops for an unknown clip id", async () => {
- const { result } = renderHook(() => useTimeline());
+ const { result } = renderTimeline();
await act(async () => {
await result.current.moveClip("clip_missing", 0);
});
@@ -216,7 +224,7 @@ describe("useTimeline.moveClip / duplicateClip (delegates to document/timeline.t
});
it("duplicateClip inserts a copy right after the original and selects it", async () => {
- const { result } = renderHook(() => useTimeline());
+ const { result } = renderTimeline();
await act(async () => {
await result.current.duplicateClip("clip_a");
});
@@ -231,7 +239,7 @@ describe("useTimeline.moveClip / duplicateClip (delegates to document/timeline.t
});
it("duplicateClip no-ops for an unknown clip id", async () => {
- const { result } = renderHook(() => useTimeline());
+ const { result } = renderTimeline();
await act(async () => {
await result.current.duplicateClip("clip_missing");
});
@@ -269,7 +277,7 @@ describe("useTimeline backfills missing source dimensions on load", () => {
status: "ready",
error: null,
});
- renderHook(() => useTimeline());
+ renderTimeline();
await waitFor(() => expect(bridgeMocks.save).toHaveBeenCalledTimes(1));
expect(probeVideoDimensionsMock).toHaveBeenCalledTimes(1);
const saved = useProjectStore.getState().document?.assets.find((a) => a.id === "asset_1");
@@ -284,7 +292,7 @@ describe("useTimeline backfills missing source dimensions on load", () => {
status: "ready",
error: null,
});
- renderHook(() => useTimeline());
+ renderTimeline();
// Give any stray effect a chance to fire before asserting it didn't.
await act(async () => {
await new Promise((r) => setTimeout(r, 0));
@@ -305,7 +313,7 @@ describe("useTimeline backfills missing source dimensions on load", () => {
status: "ready",
error: null,
});
- const { rerender } = renderHook(() => useTimeline());
+ const { rerender } = renderTimeline();
await act(async () => {
await new Promise((r) => setTimeout(r, 0));
});
@@ -356,7 +364,7 @@ describe("useTimeline.updateClipSourceRange (Edit-clip modal)", () => {
});
it("shrinks the clip's timeline width to match the narrowed source window", async () => {
- const { result } = renderHook(() => useTimeline());
+ const { result } = renderTimeline();
// Trim the 10s clip down to its first 4s of source.
await act(async () => {
await result.current.updateClipSourceRange("clip_a", 0, 4);
@@ -369,7 +377,7 @@ describe("useTimeline.updateClipSourceRange (Edit-clip modal)", () => {
});
it("drops a pill sitting over the truncated tail and keeps the one that survives", async () => {
- const { result } = renderHook(() => useTimeline());
+ const { result } = renderTimeline();
await act(async () => {
await result.current.updateClipSourceRange("clip_a", 0, 4);
});
@@ -392,7 +400,7 @@ describe("useTimeline.updateClipSourceRange (Edit-clip modal)", () => {
zoomRanges: [anchoredZoom("z_edge", 3, 7)],
} as unknown as typeof sampleDoc,
});
- const { result } = renderHook(() => useTimeline());
+ const { result } = renderTimeline();
await act(async () => {
await result.current.updateClipSourceRange("clip_a", 0, 5);
});
@@ -430,19 +438,19 @@ describe("useTimeline.addAnnotation", () => {
vi.clearAllMocks();
});
- it("creates an empty text annotation and selects it so the placeholder shows", async () => {
- const { result } = renderHook(() => useTimeline());
+ it("creates a text annotation carrying the localised default text", async () => {
+ const { result } = renderTimeline();
await act(async () => {
await result.current.addAnnotation();
});
const annotations = useProjectStore.getState().document?.annotations ?? [];
expect(annotations).toHaveLength(1);
- // Empty content is what lets the inspector's placeholder show, instead of a
- // baked-in default the user has to select and clear before typing.
- expect(annotations[0]).toMatchObject({ type: "text", content: "" });
- // The new (empty) annotation is auto-selected so its inspector opens and it
- // draws a selection box on the canvas — an empty text annotation renders
- // nothing, so without selection it would be invisible and unclickable.
+ // Real text, not an empty field. An empty annotation renders nothing at
+ // all, so adding one used to change nothing on the canvas; the
+ // inspector's placeholder is CSS ghost text that never reaches `content`
+ // and therefore never reached the compositor. DEFAULT_LOCALE is `en`.
+ expect(annotations[0]).toMatchObject({ type: "text", content: "Hello" });
+ // Still auto-selected, so its inspector opens ready to be typed over.
expect(result.current.selection).toEqual({
kind: "annotation",
id: (annotations[0] as { id: string }).id,
@@ -488,7 +496,7 @@ describe("useTimeline zoom modifiers (rotation + focus mode)", () => {
});
it("sets a 3D rotation preset on the region", async () => {
- const { result } = renderHook(() => useTimeline());
+ const { result } = renderTimeline();
await act(async () => {
await result.current.updateZoomRotation("zoom_a", "iso");
});
@@ -501,7 +509,7 @@ describe("useTimeline zoom modifiers (rotation + focus mode)", () => {
it("clears the preset back to a flat frame", async () => {
// "None" in the UI is the ABSENCE of a preset, not a fourth one: the schema field is
// optional and the native side treats anything unrecognised as zero rotation.
- const { result } = renderHook(() => useTimeline());
+ const { result } = renderTimeline();
await act(async () => {
await result.current.updateZoomRotation("zoom_a", "iso");
});
@@ -512,7 +520,7 @@ describe("useTimeline zoom modifiers (rotation + focus mode)", () => {
});
it("switches focus mode without disturbing the rotation preset", async () => {
- const { result } = renderHook(() => useTimeline());
+ const { result } = renderTimeline();
await act(async () => {
await result.current.updateZoomRotation("zoom_a", "left");
});
@@ -559,10 +567,13 @@ describe("useTimeline is not re-rendered by playhead ticks", () => {
it("does not re-render across a second of 60 Hz playhead writes", () => {
let renders = 0;
- renderHook(() => {
- renders++;
- return useTimeline();
- });
+ renderHook(
+ () => {
+ renders++;
+ return useTimeline();
+ },
+ { wrapper: I18nProvider },
+ );
const baseline = renders;
// One act() per write: a single batched act() would collapse all 60 into one
@@ -578,7 +589,7 @@ describe("useTimeline is not re-rendered by playhead ticks", () => {
});
it("still anchors a new region at the live playhead", async () => {
- const { result } = renderHook(() => useTimeline());
+ const { result } = renderTimeline();
act(() => {
useProjectStore.getState().setCurrentTime(4.2);
});
diff --git a/src/lib/ai-edition/store/useTimeline.ts b/src/lib/ai-edition/store/useTimeline.ts
index 4d430c886..c2d702f80 100644
--- a/src/lib/ai-edition/store/useTimeline.ts
+++ b/src/lib/ai-edition/store/useTimeline.ts
@@ -6,6 +6,7 @@
import { useCallback, useEffect, useRef, useState } from "react";
import { toFileUrl } from "@/components/video-editor/projectPersistence";
import type { AnnotationRegion, AnnotationType } from "@/components/video-editor/types";
+import { useScopedT } from "@/contexts/I18nContext";
import { createId } from "../document/ids";
import {
duplicateClip as duplicateClipInDocument,
@@ -85,6 +86,7 @@ function playheadSec(): number {
}
export function useTimeline() {
+ const ts = useScopedT("settings");
const document = useProjectStore((s) => s.document);
const projectId = useProjectStore((s) => s.projectId);
const saveDocument = useProjectStore((s) => s.saveDocument);
@@ -250,9 +252,13 @@ export function useTimeline() {
startMs: timeMs,
endMs: timeMs + 2000,
type: "text" as AnnotationType,
- // Start empty so the inspector's placeholder shows and typing goes into an
- // empty field, instead of a baked-in default the user must select and clear.
- content: "",
+ // Real, localised text rather than an empty field. An empty annotation
+ // renders nothing at all, so the user added a region and saw no change
+ // on the canvas; the inspector's placeholder is CSS ghost text that
+ // never reaches `content`, so it never reached the compositor either.
+ // `textContent` stays empty because the render path reads
+ // `content || textContent` and seeding both would just duplicate it.
+ content: ts("annotation.defaultText"),
textContent: "",
position: { x: 50, y: 50 },
size: { width: 30, height: 20 },
@@ -277,13 +283,14 @@ export function useTimeline() {
annotations: [...document.annotations, ...created] as unknown as AxcutDocument["annotations"],
};
await saveDocument(next);
- // Select the freshly added (empty) annotation so its inspector opens and it
- // shows a selection box on the canvas — an empty text annotation renders
- // nothing, so without this it would be invisible and impossible to click.
+ // Select the freshly added annotation so its inspector opens and it shows a
+ // selection box on the canvas, ready to be retyped over.
const newId = created[0]?.id ?? ann.id;
setMultiSelection([{ kind: "annotation", id: newId }]);
setSelection({ kind: "annotation", id: newId });
- }, [document, saveDocument]);
+ // `ts` is memoised on [locale, namespace] by useScopedT, so this does not
+ // churn the callback identity between renders.
+ }, [document, saveDocument, ts]);
const addSpeed = useCallback(async () => {
if (!document) return;