Skip to content

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

fix(i18n): select the plural form by category, and unbreak the tests typecheck

Etienne Lescot2852816a5611
diff --git a/src/components/ai-edition/RightPanes.tsx b/src/components/ai-edition/RightPanes.tsx
index 832f5959b..5f76e355d 100644
--- a/src/components/ai-edition/RightPanes.tsx
+++ b/src/components/ai-edition/RightPanes.tsx
@@ -1484,17 +1484,24 @@ export function fitClipPatch(nativeToken: AspectRatio): EditorSettingsPatch {
}
/**
- * "1 clip" / "2 clips", picked through Intl.PluralRules rather than `count === 1`.
+ * The catalog key for a count, by CLDR plural category.
*
- * The catalog has no plural machinery — `translate` interpolates and nothing else — so the two
- * forms are two keys. Choosing between them by CLDR category instead of by equality is what
- * makes French say "0 clip" and not "0 clips", and it degrades honestly for the locales whose
- * rules need more than two forms rather than pretending English's rules are universal.
+ * `translate` interpolates and nothing else, so each form is its own key. Selecting by
+ * category rather than by `count === 1` is what makes French say "0 clip" — and, more to the
+ * point, what lets a locale carry more than two forms at all: Russian needs "клипа" for 2–4
+ * and "клипов" for 5+, so mapping everything that is not `one` onto a single plural produced
+ * "2 клипов", which is simply wrong rather than merely coarse.
+ *
+ * Falls back to `fitClipMany` for any category a locale has not authored, so adding a form is
+ * a catalog change and never a code change. Arabic still needs its `two`, `few` and `many`
+ * forms — it has six categories and I could not verify the grammar, so it is deliberately
+ * left on the fallback rather than filled in with a guess.
*/
-function pluralKey(locale: string, count: number): "effects.fitClipOne" | "effects.fitClipMany" {
- return new Intl.PluralRules(locale).select(count) === "one"
+function pluralKey(locale: string, count: number): string {
+ const category = new Intl.PluralRules(locale).select(count);
+ return category === "one"
? "effects.fitClipOne"
- : "effects.fitClipMany";
+ : `effects.fitClip${category === "few" ? "Few" : "Many"}`;
}
// ─── Video Effects ─────────────────────────────────────────────────
diff --git a/src/components/ai-edition/fitClip.test.ts b/src/components/ai-edition/fitClip.test.ts
index c18c7b7e2..af2adb6d7 100644
--- a/src/components/ai-edition/fitClip.test.ts
+++ b/src/components/ai-edition/fitClip.test.ts
@@ -4,7 +4,6 @@
// unfixable to someone who already found the padding slider — so it gets pinned here.
import { describe, expect, it } from "vitest";
-import type { AspectRatio } from "@/utils/aspectRatioUtils";
import { fitClipPatch } from "./RightPanes";
describe("fitClipPatch", () => {
diff --git a/src/components/ai-edition/fitClipShapes.test.tsx b/src/components/ai-edition/fitClipShapes.test.tsx
index a372724d2..f1317b023 100644
--- a/src/components/ai-edition/fitClipShapes.test.tsx
+++ b/src/components/ai-edition/fitClipShapes.test.tsx
@@ -8,6 +8,7 @@ import "@testing-library/jest-dom";
import { cleanup, fireEvent, render, screen, waitFor, within } from "@testing-library/react";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { I18nProvider } from "@/contexts/I18nContext";
+import { LOCALE_STORAGE_KEY } from "@/i18n/config";
import type { AxcutDocument } from "@/lib/ai-edition/schema";
import { createEmptyDocument } from "@/lib/ai-edition/schema";
import { useProjectStore } from "@/lib/ai-edition/store/projectStore";
@@ -56,7 +57,8 @@ function documentWithShapes(shapes: Array<[number, number]>): AxcutDocument {
} as unknown as AxcutDocument;
}
-function mount(doc: AxcutDocument) {
+function mount(doc: AxcutDocument, locale?: string) {
+ if (locale) localStorage.setItem(LOCALE_STORAGE_KEY, locale);
useProjectStore.setState({ document: doc });
return render(
<I18nProvider>
@@ -79,9 +81,13 @@ function frameSettings() {
}
beforeEach(() => {
+ localStorage.clear();
useProjectStore.setState({ document: null });
});
-afterEach(cleanup);
+afterEach(() => {
+ cleanup();
+ localStorage.clear();
+});
describe("fitting a clip is an action, and a choice only when there is one", () => {
it("acts without asking when the timeline holds one shape", async () => {
@@ -174,6 +180,29 @@ describe("fitting a clip is an action, and a choice only when there is one", ()
).toBeInTheDocument();
});
+ it("counts in Russian with the form the count actually needs", () => {
+ // Russian has four plural categories, and 2-4 takes "клипа". Mapping everything that
+ // is not `one` onto a single plural rendered "2 клипов", which is wrong rather than
+ // merely coarse — the reason the count goes through Intl.PluralRules and not
+ // `count === 1`.
+ mount(
+ documentWithShapes([
+ [1920, 1080],
+ [1920, 1080],
+ [1080, 1920],
+ ]),
+ "ru",
+ );
+ fireEvent.click(screen.getByRole("button", { name: "Подогнать" }));
+ const menu = screen.getByRole("menu");
+ expect(
+ within(menu).getByRole("menuitem", { name: /1920 × 1080.*2 клипа/ }),
+ ).toBeInTheDocument();
+ expect(
+ within(menu).getByRole("menuitem", { name: /1080 × 1920.*1 клип$/ }),
+ ).toBeInTheDocument();
+ });
+
it("collapses same-shape clips to one entry, labelled with the biggest", () => {
mount(
documentWithShapes([
diff --git a/src/i18n/locales/ar/settings.json b/src/i18n/locales/ar/settings.json
index 48a250537..b0beb268d 100644
--- a/src/i18n/locales/ar/settings.json
+++ b/src/i18n/locales/ar/settings.json
@@ -79,6 +79,7 @@
"formatOriginal": "الأصلي",
"fitClip": "ملاءمة",
"fitClipOne": "مقطع واحد",
+ "fitClipFew": "{{count}} مقاطع",
"fitClipMany": "{{count}} مقاطع",
"motion": "الحركة",
"help": "تنسيق إطار التسجيل: ضبابية الخلفية، والظل، وضبابية الحركة، واستدارة الزوايا، والحشو حول الفيديو."
diff --git a/src/i18n/locales/en/settings.json b/src/i18n/locales/en/settings.json
index 3ec30e559..071fd4850 100644
--- a/src/i18n/locales/en/settings.json
+++ b/src/i18n/locales/en/settings.json
@@ -85,6 +85,7 @@
"formatOriginal": "Original",
"fitClip": "Fit",
"fitClipOne": "{{count}} clip",
+ "fitClipFew": "{{count}} clips",
"fitClipMany": "{{count}} clips",
"motion": "Motion",
"help": "Frame styling for the recording: background blur, drop shadow, motion blur, corner radius, and padding around the video."
diff --git a/src/i18n/locales/es/settings.json b/src/i18n/locales/es/settings.json
index 36a2a32b1..099928b5d 100644
--- a/src/i18n/locales/es/settings.json
+++ b/src/i18n/locales/es/settings.json
@@ -78,6 +78,7 @@
"formatOriginal": "Original",
"fitClip": "Ajustar",
"fitClipOne": "{{count}} clip",
+ "fitClipFew": "{{count}} clips",
"fitClipMany": "{{count}} clips",
"motion": "Movimiento",
"on": "activado",
diff --git a/src/i18n/locales/fr/settings.json b/src/i18n/locales/fr/settings.json
index 8bf5fdce6..1b7f5fa23 100644
--- a/src/i18n/locales/fr/settings.json
+++ b/src/i18n/locales/fr/settings.json
@@ -78,6 +78,7 @@
"formatOriginal": "Original",
"fitClip": "Ajuster",
"fitClipOne": "{{count}} clip",
+ "fitClipFew": "{{count}} clips",
"fitClipMany": "{{count}} clips",
"motion": "Mouvement",
"on": "activé",
diff --git a/src/i18n/locales/it/settings.json b/src/i18n/locales/it/settings.json
index 8dfd0d607..587aae961 100644
--- a/src/i18n/locales/it/settings.json
+++ b/src/i18n/locales/it/settings.json
@@ -79,6 +79,7 @@
"formatOriginal": "Originale",
"fitClip": "Adatta",
"fitClipOne": "{{count}} clip",
+ "fitClipFew": "{{count}} clip",
"fitClipMany": "{{count}} clip",
"motion": "Movimento",
"help": "Stile della cornice della registrazione: sfocatura dello sfondo, ombra, sfocatura di movimento, raggio degli angoli e margine attorno al video."
diff --git a/src/i18n/locales/ja-JP/settings.json b/src/i18n/locales/ja-JP/settings.json
index 183971ce9..f856cde46 100644
--- a/src/i18n/locales/ja-JP/settings.json
+++ b/src/i18n/locales/ja-JP/settings.json
@@ -78,6 +78,7 @@
"formatOriginal": "元のサイズ",
"fitClip": "合わせる",
"fitClipOne": "{{count}} クリップ",
+ "fitClipFew": "{{count}} クリップ",
"fitClipMany": "{{count}} クリップ",
"motion": "モーション",
"on": "オン",
diff --git a/src/i18n/locales/ko-KR/settings.json b/src/i18n/locales/ko-KR/settings.json
index 8ef9695c3..ee083c9b4 100644
--- a/src/i18n/locales/ko-KR/settings.json
+++ b/src/i18n/locales/ko-KR/settings.json
@@ -79,6 +79,7 @@
"formatOriginal": "원본",
"fitClip": "맞추기",
"fitClipOne": "{{count}}개 클립",
+ "fitClipFew": "{{count}}개 클립",
"fitClipMany": "{{count}}개 클립",
"motion": "모션",
"help": "녹화 프레임 스타일: 배경 흐림, 그림자, 모션 블러, 모서리 둥글기, 영상 주변 여백."
diff --git a/src/i18n/locales/pt-BR/settings.json b/src/i18n/locales/pt-BR/settings.json
index 853eddaa1..6512686ba 100644
--- a/src/i18n/locales/pt-BR/settings.json
+++ b/src/i18n/locales/pt-BR/settings.json
@@ -79,6 +79,7 @@
"formatOriginal": "Original",
"fitClip": "Ajustar",
"fitClipOne": "{{count}} clipe",
+ "fitClipFew": "{{count}} clipes",
"fitClipMany": "{{count}} clipes",
"motion": "Movimento",
"help": "Estilo do quadro da gravação: desfoque de fundo, sombra, desfoque de movimento, raio dos cantos e margem em volta do vídeo."
diff --git a/src/i18n/locales/ru/settings.json b/src/i18n/locales/ru/settings.json
index be705fe73..dcd82de34 100644
--- a/src/i18n/locales/ru/settings.json
+++ b/src/i18n/locales/ru/settings.json
@@ -79,6 +79,7 @@
"formatOriginal": "Исходный",
"fitClip": "Подогнать",
"fitClipOne": "{{count}} клип",
+ "fitClipFew": "{{count}} клипа",
"fitClipMany": "{{count}} клипов",
"motion": "Движение",
"help": "Оформление кадра записи: размытие фона, тень, размытие движения, скругление углов и отступ вокруг видео."
diff --git a/src/i18n/locales/tr/settings.json b/src/i18n/locales/tr/settings.json
index 9d282f58e..b3ccf10db 100644
--- a/src/i18n/locales/tr/settings.json
+++ b/src/i18n/locales/tr/settings.json
@@ -78,6 +78,7 @@
"formatOriginal": "Orijinal",
"fitClip": "Sığdır",
"fitClipOne": "{{count}} klip",
+ "fitClipFew": "{{count}} klip",
"fitClipMany": "{{count}} klip",
"motion": "Hareket",
"on": "açık",
diff --git a/src/i18n/locales/vi/settings.json b/src/i18n/locales/vi/settings.json
index 6a8f757d4..2274559b5 100644
--- a/src/i18n/locales/vi/settings.json
+++ b/src/i18n/locales/vi/settings.json
@@ -78,6 +78,7 @@
"formatOriginal": "Gốc",
"fitClip": "Vừa khít",
"fitClipOne": "{{count}} clip",
+ "fitClipFew": "{{count}} clip",
"fitClipMany": "{{count}} clip",
"motion": "Chuyển động",
"on": "bật",
diff --git a/src/i18n/locales/zh-CN/settings.json b/src/i18n/locales/zh-CN/settings.json
index caef554a0..cd2856f78 100644
--- a/src/i18n/locales/zh-CN/settings.json
+++ b/src/i18n/locales/zh-CN/settings.json
@@ -78,6 +78,7 @@
"formatOriginal": "原始",
"fitClip": "适配",
"fitClipOne": "{{count}} 个片段",
+ "fitClipFew": "{{count}} 个片段",
"fitClipMany": "{{count}} 个片段",
"motion": "运动",
"on": "开",
diff --git a/src/i18n/locales/zh-TW/settings.json b/src/i18n/locales/zh-TW/settings.json
index 5e795355d..b8606a2e7 100644
--- a/src/i18n/locales/zh-TW/settings.json
+++ b/src/i18n/locales/zh-TW/settings.json
@@ -79,6 +79,7 @@
"formatOriginal": "原始",
"fitClip": "符合",
"fitClipOne": "{{count}} 個片段",
+ "fitClipFew": "{{count}} 個片段",
"fitClipMany": "{{count}} 個片段",
"motion": "動態",
"on": "開",