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:
@@ -2,6 +2,7 @@
|
||||
|
||||
import { useState } from "react";
|
||||
import Link from "next/link";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { toast } from "sonner";
|
||||
import { ChevronDown, ChevronUp, RotateCcw } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
@@ -65,6 +66,7 @@ function formatDateTime(iso: string) {
|
||||
}
|
||||
|
||||
export function WebhooksManager({ initialWebhooks }: { initialWebhooks: Webhook[] }) {
|
||||
const t = useTranslations("settingsForm");
|
||||
const [webhookList, setWebhookList] = useState<Webhook[]>(initialWebhooks);
|
||||
const [url, setUrl] = useState("");
|
||||
const [selectedEvents, setSelectedEvents] = useState<WebhookEventType[]>([]);
|
||||
@@ -94,7 +96,7 @@ export function WebhooksManager({ initialWebhooks }: { initialWebhooks: Webhook[
|
||||
});
|
||||
if (!res.ok) {
|
||||
const data = await res.json() as { error?: string };
|
||||
throw new Error(data.error ?? "Failed to create webhook");
|
||||
throw new Error(data.error ?? t("webhookCreateFailed"));
|
||||
}
|
||||
const data = await res.json() as CreateWebhookResponse;
|
||||
setNewSecret({ id: data.id, secret: data.secret });
|
||||
@@ -105,7 +107,7 @@ export function WebhooksManager({ initialWebhooks }: { initialWebhooks: Webhook[
|
||||
setUrl("");
|
||||
setSelectedEvents([]);
|
||||
} catch (err) {
|
||||
toast.error(err instanceof Error ? err.message : "Failed to create webhook");
|
||||
toast.error(err instanceof Error ? err.message : t("webhookCreateFailed"));
|
||||
} finally {
|
||||
setCreating(false);
|
||||
}
|
||||
@@ -116,12 +118,12 @@ export function WebhooksManager({ initialWebhooks }: { initialWebhooks: Webhook[
|
||||
const res = await fetch(`/api/v1/webhooks/${id}`, { method: "DELETE" });
|
||||
if (!res.ok && res.status !== 204) {
|
||||
const data = await res.json() as { error?: string };
|
||||
throw new Error(data.error ?? "Failed to delete webhook");
|
||||
throw new Error(data.error ?? t("webhookDeleteFailed"));
|
||||
}
|
||||
setWebhookList((prev) => prev.filter((w) => w.id !== id));
|
||||
if (newSecret?.id === id) setNewSecret(null);
|
||||
} catch (err) {
|
||||
toast.error(err instanceof Error ? err.message : "Failed to delete webhook");
|
||||
toast.error(err instanceof Error ? err.message : t("webhookDeleteFailed"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,13 +136,13 @@ export function WebhooksManager({ initialWebhooks }: { initialWebhooks: Webhook[
|
||||
});
|
||||
if (!res.ok) {
|
||||
const data = await res.json() as { error?: string };
|
||||
throw new Error(data.error ?? "Failed to update webhook");
|
||||
throw new Error(data.error ?? t("webhookUpdateFailed"));
|
||||
}
|
||||
setWebhookList((prev) =>
|
||||
prev.map((w) => (w.id === id ? { ...w, active: !currentActive } : w))
|
||||
);
|
||||
} catch (err) {
|
||||
toast.error(err instanceof Error ? err.message : "Failed to update webhook");
|
||||
toast.error(err instanceof Error ? err.message : t("webhookUpdateFailed"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,7 +153,7 @@ export function WebhooksManager({ initialWebhooks }: { initialWebhooks: Webhook[
|
||||
setCopied(true);
|
||||
setTimeout(() => setCopied(false), 2000);
|
||||
} catch {
|
||||
toast.error("Failed to copy to clipboard");
|
||||
toast.error(t("copyFailed"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,9 +188,9 @@ export function WebhooksManager({ initialWebhooks }: { initialWebhooks: Webhook[
|
||||
body: JSON.stringify({ deliveryId }),
|
||||
});
|
||||
if (res.ok) {
|
||||
toast.success("Redelivery queued");
|
||||
toast.success(t("redeliverySuccess"));
|
||||
} else {
|
||||
toast.error("Failed to redeliver");
|
||||
toast.error(t("redeliveryFailed"));
|
||||
}
|
||||
} finally {
|
||||
setRedelivering(null);
|
||||
@@ -210,7 +212,7 @@ export function WebhooksManager({ initialWebhooks }: { initialWebhooks: Webhook[
|
||||
<Input
|
||||
id="webhook-url"
|
||||
type="url"
|
||||
placeholder="https://example.com/webhook"
|
||||
placeholder={t("webhookUrlPlaceholder")}
|
||||
value={url}
|
||||
onChange={(e) => setUrl(e.target.value)}
|
||||
maxLength={2048}
|
||||
@@ -242,7 +244,7 @@ export function WebhooksManager({ initialWebhooks }: { initialWebhooks: Webhook[
|
||||
</div>
|
||||
|
||||
<Button type="submit" disabled={creating || !url.trim()}>
|
||||
{creating ? "Adding…" : "Add webhook"}
|
||||
{creating ? t("webhookAdding") : t("webhookAddButton")}
|
||||
</Button>
|
||||
</form>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user