diff options
| author | Jun <[email protected]> | 2026-03-06 05:31:38 +0900 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-03-05 14:31:38 -0600 |
| commit | 76cdc668e88415ced30d2f57caeb56d21c080f19 (patch) | |
| tree | 52cac9b005641605e5d8afbb69523f3be1addba0 /packages/console/app/src/lib | |
| parent | 2ba1ecabc925d2a4a83c81d7ceab2f88abb90701 (diff) | |
| download | opencode-76cdc668e88415ced30d2f57caeb56d21c080f19.tar.gz opencode-76cdc668e88415ced30d2f57caeb56d21c080f19.zip | |
fix(console): follow-up for #13108 docs/en routing and locale cookie sync (#13608)
Diffstat (limited to 'packages/console/app/src/lib')
| -rw-r--r-- | packages/console/app/src/lib/language.ts | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/packages/console/app/src/lib/language.ts b/packages/console/app/src/lib/language.ts index 54321d234..5e80179e4 100644 --- a/packages/console/app/src/lib/language.ts +++ b/packages/console/app/src/lib/language.ts @@ -108,6 +108,26 @@ const DOCS_SEGMENT = new Set([ "zh-tw", ]) +const DOCS_LOCALE = { + ar: "ar", + da: "da", + de: "de", + en: "en", + es: "es", + fr: "fr", + it: "it", + ja: "ja", + ko: "ko", + nb: "no", + "pt-br": "br", + root: "en", + ru: "ru", + th: "th", + tr: "tr", + "zh-cn": "zh", + "zh-tw": "zht", +} as const satisfies Record<string, Locale> + function suffix(pathname: string) { const index = pathname.search(/[?#]/) if (index === -1) { @@ -130,7 +150,12 @@ export function docs(locale: Locale, pathname: string) { return `${next.path}${next.suffix}` } - if (value === "root") return `${next.path}${next.suffix}` + if (value === "root") { + if (next.path === "/docs/en") return `/docs${next.suffix}` + if (next.path === "/docs/en/") return `/docs/${next.suffix}` + if (next.path.startsWith("/docs/en/")) return `/docs/${next.path.slice("/docs/en/".length)}${next.suffix}` + return `${next.path}${next.suffix}` + } if (next.path === "/docs") return `/docs/${value}${next.suffix}` if (next.path === "/docs/") return `/docs/${value}/${next.suffix}` @@ -154,6 +179,15 @@ export function fromPathname(pathname: string) { return parseLocale(fix(pathname).split("/")[1]) } +export function fromDocsPathname(pathname: string) { + const next = fix(pathname) + const value = next.split("/")[2]?.toLowerCase() + if (!value) return null + if (!next.startsWith("/docs/")) return null + if (!(value in DOCS_LOCALE)) return null + return DOCS_LOCALE[value as keyof typeof DOCS_LOCALE] +} + export function strip(pathname: string) { const locale = fromPathname(pathname) if (!locale) return fix(pathname) @@ -272,6 +306,9 @@ export function localeFromRequest(request: Request) { const fromPath = fromPathname(new URL(request.url).pathname) if (fromPath) return fromPath + const fromDocsPath = fromDocsPathname(new URL(request.url).pathname) + if (fromDocsPath) return fromDocsPath + return ( localeFromCookieHeader(request.headers.get("cookie")) ?? detectFromAcceptLanguage(request.headers.get("accept-language")) |
