feat(i18n): translate hardcoded strings across print, public recipe, and recipe management UI

Wires dozens of components and server pages to next-intl instead of hardcoded
English text, and adds a lightweight getMessages/formatMessage helper for
server components (print pages, public recipe page, cook metadata) since
next-intl/server isn't wired into this app's routing. Backfills missing
en/fr message keys that existing code already referenced but fr.json lacked.
This commit is contained in:
Arnaud
2026-07-02 07:58:18 +02:00
parent afff6cf9eb
commit 01fdbb880b
32 changed files with 515 additions and 187 deletions
@@ -1,6 +1,7 @@
"use client";
import { useState } from "react";
import { useTranslations } from "next-intl";
import { toast } from "sonner";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
@@ -30,6 +31,7 @@ function formatDate(iso: string) {
}
export function ApiKeysManager({ initialKeys }: { initialKeys: ApiKey[] }) {
const t = useTranslations("settingsForm");
const [keys, setKeys] = useState<ApiKey[]>(initialKeys);
const [name, setName] = useState("");
const [creating, setCreating] = useState(false);
@@ -48,7 +50,7 @@ export function ApiKeysManager({ initialKeys }: { initialKeys: ApiKey[] }) {
});
if (!res.ok) {
const data = await res.json() as { error?: string };
throw new Error(data.error ?? "Failed to create API key");
throw new Error(data.error ?? t("apiKeyCreateFailed"));
}
const data = await res.json() as CreateApiKeyResponse;
setNewKey(data.key);
@@ -58,7 +60,7 @@ export function ApiKeysManager({ initialKeys }: { initialKeys: ApiKey[] }) {
]);
setName("");
} catch (err) {
toast.error(err instanceof Error ? err.message : "Failed to create API key");
toast.error(err instanceof Error ? err.message : t("apiKeyCreateFailed"));
} finally {
setCreating(false);
}
@@ -69,11 +71,11 @@ export function ApiKeysManager({ initialKeys }: { initialKeys: ApiKey[] }) {
const res = await fetch(`/api/v1/api-keys/${id}`, { method: "DELETE" });
if (!res.ok) {
const data = await res.json() as { error?: string };
throw new Error(data.error ?? "Failed to revoke API key");
throw new Error(data.error ?? t("apiKeyRevokeFailed"));
}
setKeys((prev) => prev.filter((k) => k.id !== id));
} catch (err) {
toast.error(err instanceof Error ? err.message : "Failed to revoke API key");
toast.error(err instanceof Error ? err.message : t("apiKeyRevokeFailed"));
}
}
@@ -84,7 +86,7 @@ export function ApiKeysManager({ initialKeys }: { initialKeys: ApiKey[] }) {
setCopied(true);
setTimeout(() => setCopied(false), 2000);
} catch {
toast.error("Failed to copy to clipboard");
toast.error(t("copyFailed"));
}
}
@@ -97,7 +99,7 @@ export function ApiKeysManager({ initialKeys }: { initialKeys: ApiKey[] }) {
<div className="flex gap-2">
<Input
id="key-name"
placeholder="e.g. My app"
placeholder={t("apiKeyNamePlaceholder")}
value={name}
onChange={(e) => setName(e.target.value)}
maxLength={100}