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:
@@ -1,6 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { FakeProgressBar } from "@/components/ui/fake-progress-bar";
|
||||
import { UtensilsCrossed, Sparkles, Loader2, ChefHat, Salad, Wine, Cake, Sandwich, Soup, Check } from "lucide-react";
|
||||
@@ -54,6 +55,7 @@ const DIFFICULTY_VARIANT = {
|
||||
} as const;
|
||||
|
||||
export function MealPairingButton({ recipeId }: { recipeId: string }) {
|
||||
const t = useTranslations("recipe");
|
||||
const router = useRouter();
|
||||
const [open, setOpen] = useState(false);
|
||||
const [loading, setLoading] = useState(false);
|
||||
@@ -71,7 +73,7 @@ export function MealPairingButton({ recipeId }: { recipeId: string }) {
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ count: 4 }),
|
||||
});
|
||||
if (!res.ok) { toast.error("Failed to suggest pairings"); return; }
|
||||
if (!res.ok) { toast.error(t("pairingMealFailed")); return; }
|
||||
const data = await res.json() as { pairings: Pairing[] };
|
||||
setPairings(data.pairings);
|
||||
} finally {
|
||||
@@ -101,7 +103,7 @@ export function MealPairingButton({ recipeId }: { recipeId: string }) {
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ prompt: pairing.name }),
|
||||
});
|
||||
if (!genRes.ok) { toast.error(`Failed to generate "${pairing.name}"`); continue; }
|
||||
if (!genRes.ok) { toast.error(t("pairingGenerateFailed", { name: pairing.name })); continue; }
|
||||
const generated = await genRes.json() as {
|
||||
title: string; description?: string; baseServings?: number; prepMins?: number;
|
||||
cookMins?: number; difficulty?: string; dietaryTags?: Record<string, boolean>;
|
||||
@@ -113,11 +115,11 @@ export function MealPairingButton({ recipeId }: { recipeId: string }) {
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ ...generated, visibility: "private", aiGenerated: true }),
|
||||
});
|
||||
if (!saveRes.ok) { toast.error(`Failed to save "${pairing.name}"`); continue; }
|
||||
if (!saveRes.ok) { toast.error(t("pairingSaveFailed", { name: pairing.name })); continue; }
|
||||
const saved = await saveRes.json() as { id: string };
|
||||
savedIds.push(saved.id);
|
||||
} catch {
|
||||
toast.error(`Error generating "${pairing.name}"`);
|
||||
toast.error(t("pairingGenerateFailed", { name: pairing.name }));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,10 +128,10 @@ export function MealPairingButton({ recipeId }: { recipeId: string }) {
|
||||
setOpen(false);
|
||||
|
||||
if (savedIds.length === 1) {
|
||||
toast.success("Recipe generated — review before publishing");
|
||||
toast.success(t("pairingSuccess"));
|
||||
router.push(`/recipes/${savedIds[0]}/edit`);
|
||||
} else if (savedIds.length > 1) {
|
||||
toast.success(`${savedIds.length} recipes generated — find them in your library`);
|
||||
toast.success(t("pairingBulkSuccess", { count: savedIds.length }));
|
||||
router.push("/recipes");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user