'use client'; import { useLocale } from 'next-intl'; import { useRouter } from 'next/navigation'; import { useTransition } from 'react'; import { LOCALE_COOKIE, locales, type Locale } from '@/i18n/config'; // Floating ES/EN toggle. Writes a cookie and refreshes server components so the // whole interface switches instantly. export default function LanguageSwitch({ className = '' }: { className?: string }) { const locale = useLocale() as Locale; const router = useRouter(); const [pending, startTransition] = useTransition(); function setLocale(next: Locale) { if (next === locale) return; document.cookie = `${LOCALE_COOKIE}=${next}; path=/; max-age=31536000; samesite=lax`; startTransition(() => router.refresh()); } return (
{locales.map((l) => ( ))}
); }