diff options
| author | Adam <[email protected]> | 2026-02-09 12:16:26 -0600 |
|---|---|---|
| committer | Adam <[email protected]> | 2026-02-09 12:20:09 -0600 |
| commit | 83708c295c0cdff32ec155d81813ad346b232e35 (patch) | |
| tree | 4059ed4030fa073bf4d058a2ae487920b9db5e48 /packages/console/app/src/lib/language.ts | |
| parent | a84bdd7cd7d638e207f4932aa614650c4d0e275f (diff) | |
| download | opencode-83708c295c0cdff32ec155d81813ad346b232e35.tar.gz opencode-83708c295c0cdff32ec155d81813ad346b232e35.zip | |
chore: cleanup
Diffstat (limited to 'packages/console/app/src/lib/language.ts')
| -rw-r--r-- | packages/console/app/src/lib/language.ts | 76 |
1 files changed, 75 insertions, 1 deletions
diff --git a/packages/console/app/src/lib/language.ts b/packages/console/app/src/lib/language.ts index b7165ed6c..a13692476 100644 --- a/packages/console/app/src/lib/language.ts +++ b/packages/console/app/src/lib/language.ts @@ -68,6 +68,80 @@ const TAG = { tr: "tr", } satisfies Record<Locale, string> +const DOCS = { + en: "root", + zh: "zh-cn", + zht: "zh-tw", + ko: "ko", + de: "de", + es: "es", + fr: "fr", + it: "it", + da: "da", + ja: "ja", + pl: "pl", + ru: "ru", + ar: "ar", + no: "nb", + br: "pt-br", + th: "th", + tr: "tr", +} satisfies Record<Locale, string> + +const DOCS_SEGMENT = new Set([ + "ar", + "bs", + "da", + "de", + "es", + "fr", + "it", + "ja", + "ko", + "nb", + "pl", + "pt-br", + "ru", + "th", + "tr", + "zh-cn", + "zh-tw", +]) + +function suffix(pathname: string) { + const index = pathname.search(/[?#]/) + if (index === -1) { + return { + path: fix(pathname), + suffix: "", + } + } + + return { + path: fix(pathname.slice(0, index)), + suffix: pathname.slice(index), + } +} + +export function docs(locale: Locale, pathname: string) { + const value = DOCS[locale] + const next = suffix(pathname) + if (next.path !== "/docs" && next.path !== "/docs/" && !next.path.startsWith("/docs/")) { + return `${next.path}${next.suffix}` + } + + if (value === "root") return `${next.path}${next.suffix}` + + const hit = /^\/docs\/([^/]+)(\/.*)?$/.exec(next.path) + if (hit && DOCS_SEGMENT.has(hit[1] ?? "")) { + return `${next.path}${next.suffix}` + } + + if (next.path === "/docs") return `/docs/${value}${next.suffix}` + if (next.path === "/docs/") return `/docs/${value}/${next.suffix}` + return `/docs/${value}${next.path.slice("/docs".length)}${next.suffix}` +} + export function parseLocale(value: unknown): Locale | null { if (typeof value !== "string") return null if ((LOCALES as readonly string[]).includes(value)) return value as Locale @@ -90,7 +164,7 @@ export function strip(pathname: string) { export function route(locale: Locale, pathname: string) { const next = strip(pathname) - if (next.startsWith("/docs")) return next + if (next.startsWith("/docs")) return docs(locale, next) if (next.startsWith("/auth")) return next if (next.startsWith("/workspace")) return next if (locale === "en") return next |
