"use client"; import { useTransition } from "react"; import { useRouter } from "next/navigation"; import { useLocale, useT } from "@/lib/i18n/client"; import { LOCALE_COOKIE, type Locale } from "@/lib/i18n/types"; /** * Switcher de langue (FR / EN). Pose le cookie karbe-locale et refresh la page * pour que le server re-render avec la nouvelle locale. */ export function LocaleSwitcher() { const router = useRouter(); const current = useLocale(); const t = useT(); const [pending, startTransition] = useTransition(); function setLocale(next: Locale) { if (next === current) return; // 1 an, scope au site entier document.cookie = `${LOCALE_COOKIE}=${next}; path=/; max-age=${60 * 60 * 24 * 365}; SameSite=Lax`; startTransition(() => { router.refresh(); }); } return (
{t("language.switch")}
); }