peppa/apps/web/app/locale-actions.ts
2026-11-15 14:25:03 +05:00

20 lines
713 B
TypeScript

"use server";
import { forgetChatLocales, setUserLocale } from "@peppa/core";
import { LOCALE_COOKIE, normalizeLocale } from "@peppa/shared/i18n";
import { cookies } from "next/headers";
import { currentUser } from "@/lib/auth";
import { db } from "@/lib/db";
import { localeCookieOptions } from "@/lib/i18n";
/** PEP-98: language switcher — cookie for everyone, plus the user's setting when logged in. */
export async function setLanguage(value: string): Promise<void> {
const locale = normalizeLocale(value);
(await cookies()).set(LOCALE_COOKIE, locale, localeCookieOptions);
const user = await currentUser();
if (user) {
await setUserLocale(db, user.id, locale);
forgetChatLocales();
}
}