mirror of
https://gitee.com/wanwujie/deer-flow
synced 2026-04-27 15:54:48 +08:00
* fix(i18n): guard locale input and add safe translation fallback * refactor(i18n): isolate locale utils and normalize server cookie decode --------- Co-authored-by: Willem Jiang <willem.jiang@gmail.com>
18 lines
445 B
TypeScript
18 lines
445 B
TypeScript
import { cookies } from "next/headers";
|
|
|
|
import { normalizeLocale, type Locale } from "./locale";
|
|
|
|
export async function detectLocaleServer(): Promise<Locale> {
|
|
const cookieStore = await cookies();
|
|
let locale = cookieStore.get("locale")?.value;
|
|
if (locale !== undefined) {
|
|
try {
|
|
locale = decodeURIComponent(locale);
|
|
} catch {
|
|
// Keep raw cookie value when decoding fails.
|
|
}
|
|
}
|
|
|
|
return normalizeLocale(locale);
|
|
}
|