mirror of
https://github.com/bytedance/deer-flow.git
synced 2026-05-23 08:25:57 +00:00
e9adaab7a6
* 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);
|
|
}
|