JeffJiang c1366cf559
Add documents site (#1767)
* feat: add docs site

- Implemented dynamic routing for MDX documentation pages with language support.
- Created layout components for documentation with a header and footer.
- Added metadata for various documentation sections in English and Chinese.
- Developed initial content for the DeerFlow App and Harness documentation.
- Introduced i18n hooks and translations for English and Chinese languages.
- Enhanced header component to include navigation links for documentation and blog.
- Established a structure for tutorials and reference materials.
- Created a new translations file to manage locale-specific strings.

* feat: enhance documentation structure and content for application and harness sections

* feat: update .gitignore to include .playwright-mcp and remove obsolete Playwright YAML file

* fix(docs): correct punctuation and formatting in documentation files

* feat(docs): remove outdated index.mdx file from documentation

* fix(docs): update documentation links and improve Chinese description in index.mdx

* fix(docs): update title in Chinese for meta information in _meta.ts
2026-04-03 07:25:40 +08:00

42 lines
1.1 KiB
TypeScript

import { cookies } from "next/headers";
import { DEFAULT_LOCALE, normalizeLocale, type Locale } from "./locale";
import { translations } from "./translations";
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);
}
export async function setLocale(locale: string | Locale): Promise<Locale> {
const normalizedLocale = normalizeLocale(locale);
const cookieStore = await cookies();
cookieStore.set("locale", encodeURIComponent(normalizedLocale), {
maxAge: 365 * 24 * 60 * 60,
path: "/",
sameSite: "lax",
});
return normalizedLocale;
}
export async function getI18n(localeOverride?: string | Locale) {
const locale = localeOverride
? normalizeLocale(localeOverride)
: await detectLocaleServer();
const t = translations[locale] ?? translations[DEFAULT_LOCALE];
return {
locale,
t,
};
}