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 { Shuffle, Loader2 } from "lucide-react";
import {
Popover,
@@ -29,6 +30,7 @@ export function SubstituteIngredientPopover({
ingredient: string;
recipeTitle: string;
}) {
const t = useTranslations("substitute");
const [open, setOpen] = useState(false);
const [loading, setLoading] = useState(false);
const [substitutions, setSubstitutions] = useState<Substitution[]>([]);
@@ -47,14 +49,14 @@ export function SubstituteIngredientPopover({
});
if (!res.ok) {
const body = await res.json().catch(() => null) as { error?: string } | null;
setError(body?.error ?? "Couldn't fetch substitutes.");
setError(body?.error ?? t("fetchError"));
return;
}
const data = await res.json() as { substitutions: Substitution[] };
setSubstitutions(data.substitutions);
setFetched(true);
} catch {
setError("Couldn't fetch substitutes.");
setError(t("fetchError"));
} finally {
setLoading(false);
}
@@ -69,18 +71,18 @@ export function SubstituteIngredientPopover({
<Popover open={open} onOpenChange={handleOpen}>
<PopoverTrigger
className="h-5 w-5 opacity-0 group-hover:opacity-60 hover:opacity-100 transition-opacity shrink-0 inline-flex items-center justify-center rounded hover:bg-accent"
title={`Substitute for ${ingredient}`}
title={t("titleFor", { ingredient })}
>
<Shuffle className="h-3 w-3" />
</PopoverTrigger>
<PopoverContent className="w-80 p-3 space-y-3" align="start">
<p className="text-xs font-semibold text-muted-foreground uppercase tracking-wide">
Substitutes for <span className="text-foreground normal-case">{ingredient}</span>
{t("substitutesFor")} <span className="text-foreground normal-case">{ingredient}</span>
</p>
{loading && (
<div className="flex items-center gap-2 py-2 text-sm text-muted-foreground">
<Loader2 className="h-3.5 w-3.5 animate-spin" />
Finding substitutes
{t("finding")}
</div>
)}
{!loading && substitutions.length > 0 && (
@@ -103,7 +105,7 @@ export function SubstituteIngredientPopover({
<p className="text-sm text-destructive py-1">{error}</p>
)}
{!loading && fetched && substitutions.length === 0 && (
<p className="text-sm text-muted-foreground py-1">No substitutions found.</p>
<p className="text-sm text-muted-foreground py-1">{t("noneFound")}</p>
)}
</PopoverContent>
</Popover>