This commit is contained in:
Nông Đức Huy
2026-08-13 23:20:22 +07:00
parent 3e5d38ec18
commit 3d6b0e0d4e
145 changed files with 7817 additions and 801 deletions
+32
View File
@@ -0,0 +1,32 @@
'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<void> {
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');
}