mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
Add complete i18n infrastructure with 21 supported languages: English, Simplified Chinese, Traditional Chinese, Japanese, Korean, Spanish, French, Italian, Brazilian Portuguese, German, Dutch, Swedish, Russian, Polish, Ukrainian, Arabic (RTL), Turkish, Hindi, Vietnamese, Indonesian, and Thai. - I18nProvider context with three-tier locale detection (user preference > navigator.languages > instance default > English) - ~1500 translation keys per locale with TypeScript-enforced completeness - Dynamic code-splitting: only the active locale is loaded at runtime - Language selectors in footer, login page, settings, and mobile sidebar - Arabic RTL support with CSS logical properties across all components - Tool names, descriptions, and categories translated via i18n helpers - Public API endpoint GET /api/v1/config/locale for instance default - Multi-script font stack (CJK, Arabic, Devanagari, Thai, Cyrillic) - format() and plural() helpers for interpolation and pluralization - API error translation mapping (translateApiError) - 36 Playwright e2e tests verifying all 21 locales load correctly - 25 unit tests for format, plural, locale detection, and completeness - Updated translations.md docs and CLAUDE.md conventions
69 lines
1.8 KiB
TypeScript
69 lines
1.8 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { format, formatFileSize, plural } from "@/lib/format";
|
|
|
|
describe("format", () => {
|
|
it("replaces single placeholder", () => {
|
|
expect(format("Hello {name}", { name: "World" })).toBe("Hello World");
|
|
});
|
|
|
|
it("replaces multiple placeholders", () => {
|
|
expect(format("{a} and {b}", { a: "X", b: "Y" })).toBe("X and Y");
|
|
});
|
|
|
|
it("replaces numeric values", () => {
|
|
expect(format("{count} files", { count: 5 })).toBe("5 files");
|
|
});
|
|
|
|
it("preserves unmatched placeholders", () => {
|
|
expect(format("Hello {name}", {})).toBe("Hello {name}");
|
|
});
|
|
|
|
it("handles empty template", () => {
|
|
expect(format("", { name: "test" })).toBe("");
|
|
});
|
|
|
|
it("handles template with no placeholders", () => {
|
|
expect(format("No placeholders here", { name: "test" })).toBe("No placeholders here");
|
|
});
|
|
});
|
|
|
|
describe("plural", () => {
|
|
it("returns one form for count 1", () => {
|
|
expect(plural(1, "1 file", "files")).toBe("1 file");
|
|
});
|
|
|
|
it("returns other form for count 0", () => {
|
|
expect(plural(0, "1 file", "0 files")).toBe("0 files");
|
|
});
|
|
|
|
it("returns other form for count > 1", () => {
|
|
expect(plural(5, "1 file", "5 files")).toBe("5 files");
|
|
});
|
|
|
|
it("returns other form for negative count", () => {
|
|
expect(plural(-1, "1 file", "files")).toBe("files");
|
|
});
|
|
});
|
|
|
|
describe("formatFileSize", () => {
|
|
it("formats bytes", () => {
|
|
expect(formatFileSize(500)).toBe("500 B");
|
|
});
|
|
|
|
it("formats kilobytes", () => {
|
|
expect(formatFileSize(2048)).toBe("2.0 KB");
|
|
});
|
|
|
|
it("formats megabytes", () => {
|
|
expect(formatFileSize(1536 * 1024)).toBe("1.5 MB");
|
|
});
|
|
|
|
it("formats gigabytes", () => {
|
|
expect(formatFileSize(2.5 * 1024 * 1024 * 1024)).toBe("2.5 GB");
|
|
});
|
|
|
|
it("handles zero", () => {
|
|
expect(formatFileSize(0)).toBe("0 B");
|
|
});
|
|
});
|