mirror of
https://gitee.com/wanwujie/deer-flow
synced 2026-04-28 08:14:48 +08:00
fix(i18n): normalize locale and prevent undefined translations (#914)
* 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>
This commit is contained in:
@@ -1,9 +1,17 @@
|
||||
import { cookies } from "next/headers";
|
||||
|
||||
export type Locale = "en-US" | "zh-CN";
|
||||
import { normalizeLocale, type Locale } from "./locale";
|
||||
|
||||
export async function detectLocaleServer(): Promise<Locale> {
|
||||
const cookieStore = await cookies();
|
||||
const locale = cookieStore.get("locale")?.value ?? "en-US";
|
||||
return locale as Locale;
|
||||
let locale = cookieStore.get("locale")?.value;
|
||||
if (locale !== undefined) {
|
||||
try {
|
||||
locale = decodeURIComponent(locale);
|
||||
} catch {
|
||||
// Keep raw cookie value when decoding fails.
|
||||
}
|
||||
}
|
||||
|
||||
return normalizeLocale(locale);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user