'use server'; import { revalidatePath } from 'next/cache'; import { cookies } from 'next/headers'; import { isLocale, type Locale } from '@sport/types'; import { LOCALE_COOKIE } from './request'; /** * Persists the operator's language choice. * * A Server Action rather than a client-side cookie write, so the very next * render already has the new locale — no flash of the previous language, and no * need to duplicate the cookie name in client code. */ export async function setLocale(locale: Locale): Promise { if (!isLocale(locale)) return; const store = await cookies(); store.set(LOCALE_COOKIE, locale, { path: '/', maxAge: 60 * 60 * 24 * 365, sameSite: 'lax', // Not httpOnly: this is a display preference, not a credential, and reading // it client-side is occasionally useful. httpOnly: false, }); // Every admin screen renders translated text, so the whole tree is stale. revalidatePath('/', 'layout'); }