Add an English/Czech interface language switch

English stays the default; Czech is a full translation. Only the app chrome
is translated - notes and generated decks keep their own language, which is a
core feature, not a setting.

i18n
- lib/i18n-dict.ts: flat en/cs dictionaries (441 keys each), translate() and
  translatePlural() with real Czech plural rules (1 sada / 2-4 sady / 5+ sad).
  English is the default and the fallback for a missing key.
- lib/i18n.ts: browser store (freezmo.locale.v1), useI18n() hook, and the
  x-freezmo-locale header. The hook's t/plural are bound to the locale React
  is rendering with, so the first client render matches the server HTML and
  then re-renders in the stored language; module-level t is only for event
  handlers and non-React helpers.
- <html lang> follows the choice (inline script + setLocale).

UI
- Settings -> Language segmented control (English / Cestina), plus an EN/CS
  button on the key gate for first run.
- Every screen translated: sidebar, header, tab bar, library, deck cards,
  folder bar, create flow, all seven activities, study chrome, results,
  settings + health panel, API-key gate and help, install sheet, offline and
  the deck-not-found page.
- Plural-aware counts everywhere (decks, folders, activities, runs, photos,
  documents, pages, words, wrong attempts).

Server
- API routes and guards (generate, grade, health, http-guard, rate-limit,
  ollama error mapping) answer in the request's language, so error cards and
  the health panel never fall back to English mid-sentence.

Fixes
- A hydration mismatch when a non-default locale was stored silently dropped
  the .dark class after hydration; render-time t() is now bound to the
  hook's locale (UploadScreen.describeExtraction, ResultsScreen.answerFor,
  DeckCard's folder fallback).
- Bumped the service worker cache to freezmo-v4 for this deploy.

Tests: i18n 27/27 (gate toggle, persistence, html lang, Czech plurals,
settings switch) and a rebuilt regression suite 72/72 (English default,
library, create, all 7 activity types, results, settings, install sheet,
offline, PWA, security, Czech smoke).
This commit is contained in:
Martin Dvořák 2026-10-08 13:56:32 +00:00
commit 618ad5fb9c
42 changed files with 1892 additions and 509 deletions

View file

@ -16,6 +16,7 @@ import {
} from "@/components/icons";
import { useTheme } from "@/components/ThemeToggle";
import { createFolder, folderStore } from "@/lib/folders";
import { useI18n } from "@/lib/i18n";
import { ALL_FOLDERS, folderSelection, sidebarOpen, useSelectedFolder, useSidebarOpen } from "@/lib/nav";
import { UNORGANIZED_ID } from "@/lib/schemas";
import { deckStore } from "@/lib/storage";
@ -42,6 +43,7 @@ function NavContent({
);
const selected = useSelectedFolder();
const { theme, toggle } = useTheme();
const { t } = useI18n();
const [creating, setCreating] = useState(false);
const [draft, setDraft] = useState("");
@ -106,7 +108,7 @@ function NavContent({
href="/"
onClick={onNavigate}
className={cn("nav-row gap-2.5", collapsed ? "w-auto px-2" : "flex-1")}
aria-label="Freezmo home"
aria-label={t("header.home")}
title="Freezmo"
>
{/* eslint-disable-next-line @next/next/no-img-element -- static app icon, no optimisation needed */}
@ -124,8 +126,8 @@ function NavContent({
<button
type="button"
onClick={() => sidebarCollapse.set(true)}
aria-label="Collapse sidebar"
title="Collapse sidebar"
aria-label={t("sidebar.collapse")}
title={t("sidebar.collapse")}
className="grid size-8 place-items-center rounded-lg text-[var(--text-subtle)] transition hover:bg-[var(--hover)] hover:text-[var(--text)]"
>
<ChevronLeftIcon className="size-4" />
@ -138,10 +140,10 @@ function NavContent({
href="/create"
onClick={onNavigate}
className={cn("nav-row mb-3", collapsed && "justify-center px-2")}
title="New deck"
title={t("common.newDeck")}
>
<PlusIcon className="size-4 shrink-0" />
{!collapsed ? <span className="flex-1 truncate text-left">New deck</span> : null}
{!collapsed ? <span className="flex-1 truncate text-left">{t("common.newDeck")}</span> : null}
</Link>
{/* folders --------------------------------------------------------- */}
@ -149,13 +151,13 @@ function NavContent({
{!desktop && !collapsed ? (
<div className="flex items-center justify-between px-2 pb-1">
<span className="text-[11px] font-semibold uppercase tracking-wider text-[var(--text-subtle)]">
Folders
{t("common.folders")}
</span>
<button
type="button"
onClick={() => setCreating(true)}
aria-label="New folder"
title="New folder"
aria-label={t("common.newFolder")}
title={t("common.newFolder")}
className="grid size-6 place-items-center rounded-md text-[var(--text-subtle)] transition hover:bg-[var(--hover)] hover:text-[var(--text)]"
>
<PlusIcon className="size-3.5" />
@ -164,15 +166,15 @@ function NavContent({
) : null}
<nav
aria-label={desktop ? "Library" : "Folders"}
aria-label={desktop ? t("sidebar.library") : t("common.folders")}
className="thin-scroll min-h-0 flex-1 space-y-0.5 overflow-y-auto"
>
{collapsed ? (
<button
type="button"
onClick={() => sidebarCollapse.set(false)}
aria-label="Expand sidebar"
title="Expand sidebar"
aria-label={t("sidebar.expand")}
title={t("sidebar.expand")}
className="nav-row justify-center px-2"
>
<ChevronRightIcon className="size-4" />
@ -185,13 +187,13 @@ function NavContent({
<div className={cn("space-y-0.5", !collapsed && "mb-1")}>
{viewRow(
ALL_FOLDERS,
"All decks",
t("common.allDecks"),
<LayersIcon className="size-4 shrink-0 opacity-70" />,
count(decks.length),
)}
{viewRow(
UNORGANIZED_ID,
"Unorganized",
t("common.unorganized"),
<FolderIcon className="size-4 shrink-0 opacity-70" />,
null,
)}
@ -200,13 +202,13 @@ function NavContent({
<>
{viewRow(
ALL_FOLDERS,
"All decks",
t("common.allDecks"),
<LayersIcon className="size-4 shrink-0 opacity-70" />,
count(decks.length),
)}
{viewRow(
UNORGANIZED_ID,
"Unorganized",
t("common.unorganized"),
<FolderIcon className="size-4 shrink-0 opacity-70" />,
count(counts[UNORGANIZED_ID] ?? 0),
)}
@ -217,13 +219,13 @@ function NavContent({
{desktop && !collapsed ? (
<div className="flex items-center justify-between px-2 pb-1 pt-1">
<span className="text-[11px] font-semibold uppercase tracking-wider text-[var(--text-subtle)]">
Folders
{t("common.folders")}
</span>
<button
type="button"
onClick={() => setCreating(true)}
aria-label="New folder"
title="New folder"
aria-label={t("common.newFolder")}
title={t("common.newFolder")}
className="grid size-6 place-items-center rounded-md text-[var(--text-subtle)] transition hover:bg-[var(--hover)] hover:text-[var(--text)]"
>
<PlusIcon className="size-3.5" />
@ -261,13 +263,13 @@ function NavContent({
setError(null);
}
}}
placeholder="Folder name"
aria-label="New folder name"
placeholder={t("common.folderName")}
aria-label={t("common.newFolderName")}
maxLength={60}
className="min-w-0 flex-1 rounded-lg border border-[var(--hairline)] bg-[var(--surface)] px-2.5 py-1.5 text-[13px] text-[var(--text)] outline-none focus:border-[var(--text-subtle)]"
/>
<button type="button" onClick={submit} className="btn-primary h-8 px-3 text-[12px]">
Add
{t("common.add")}
</button>
</div>
) : null}
@ -280,16 +282,16 @@ function NavContent({
<button
type="button"
onClick={openSettings}
title="Settings"
title={t("common.settings")}
className={cn("nav-row", collapsed && "justify-center px-2")}
>
<GearIcon className="size-4 shrink-0 opacity-70" />
{!collapsed ? <span className="flex-1 truncate text-left">Settings</span> : null}
{!collapsed ? <span className="flex-1 truncate text-left">{t("common.settings")}</span> : null}
</button>
<button
type="button"
onClick={toggle}
title={theme === "dark" ? "Light mode" : "Dark mode"}
title={theme === "dark" ? t("common.lightMode") : t("common.darkMode")}
className={cn("nav-row", collapsed && "justify-center px-2")}
>
{theme === "dark" ? (
@ -298,7 +300,9 @@ function NavContent({
<MoonIcon className="size-4 shrink-0 opacity-70" />
)}
{!collapsed ? (
<span className="flex-1 truncate text-left">{theme === "dark" ? "Light mode" : "Dark mode"}</span>
<span className="flex-1 truncate text-left">
{theme === "dark" ? t("common.lightMode") : t("common.darkMode")}
</span>
) : null}
</button>
</div>
@ -357,10 +361,11 @@ function useCollapsed(): boolean {
export function Sidebar() {
const isCollapsed = useCollapsed();
const { t } = useI18n();
return (
<aside
aria-label="Sidebar"
aria-label={t("sidebar.label")}
className={cn(
"fixed inset-y-0 left-0 z-40 hidden p-3 transition-[width] duration-200 lg:flex",
isCollapsed ? "w-[84px]" : "w-[268px]",
@ -376,6 +381,7 @@ export function Sidebar() {
export function MobileSidebar() {
const open = useSidebarOpen();
const { t } = useI18n();
return (
<AnimatePresence>
@ -388,12 +394,12 @@ export function MobileSidebar() {
>
<button
type="button"
aria-label="Close menu"
aria-label={t("sidebar.closeMenu")}
onClick={() => sidebarOpen.set(false)}
className="absolute inset-0 bg-black/40 backdrop-blur-sm"
/>
<motion.aside
aria-label="Menu"
aria-label={t("common.menu")}
initial={{ x: -280 }}
animate={{ x: 0 }}
exit={{ x: -280 }}