diff options
| author | Adam <[email protected]> | 2026-02-09 11:34:35 -0600 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-02-09 11:34:35 -0600 |
| commit | dc53086c1e73d43d3a28fc4cdf161e83d09b1877 (patch) | |
| tree | 45a1d0e38de958d0886a5120b2806b21db74145b /packages/web/src/i18n | |
| parent | f74c0339cc6315f7e7743e26b7eab47ce026c239 (diff) | |
| download | opencode-dc53086c1e73d43d3a28fc4cdf161e83d09b1877.tar.gz opencode-dc53086c1e73d43d3a28fc4cdf161e83d09b1877.zip | |
wip(docs): i18n (#12681)
Diffstat (limited to 'packages/web/src/i18n')
| -rw-r--r-- | packages/web/src/i18n/locales.ts | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/packages/web/src/i18n/locales.ts b/packages/web/src/i18n/locales.ts new file mode 100644 index 000000000..50cdaecb5 --- /dev/null +++ b/packages/web/src/i18n/locales.ts @@ -0,0 +1,98 @@ +export const docsLocale = [ + "ar", + "bs", + "da", + "de", + "es", + "fr", + "it", + "ja", + "ko", + "nb", + "pl", + "pt-br", + "ru", + "th", + "tr", + "zh-cn", + "zh-tw", +] as const + +export type DocsLocale = (typeof docsLocale)[number] + +export const locale = ["root", ...docsLocale] as const + +export type Locale = (typeof locale)[number] + +export const localeAlias = { + ar: "ar", + br: "pt-br", + bs: "bs", + da: "da", + de: "de", + en: "root", + es: "es", + fr: "fr", + it: "it", + ja: "ja", + ko: "ko", + nb: "nb", + nn: "nb", + no: "nb", + pl: "pl", + pt: "pt-br", + "pt-br": "pt-br", + root: "root", + ru: "ru", + th: "th", + tr: "tr", + zh: "zh-cn", + "zh-cn": "zh-cn", + zht: "zh-tw", + "zh-tw": "zh-tw", +} as const satisfies Record<string, Locale> + +const starts = [ + ["ko", "ko"], + ["bs", "bs"], + ["de", "de"], + ["es", "es"], + ["fr", "fr"], + ["it", "it"], + ["da", "da"], + ["ja", "ja"], + ["pl", "pl"], + ["ru", "ru"], + ["ar", "ar"], + ["th", "th"], + ["tr", "tr"], + ["en", "root"], +] as const + +export function matchLocale(input: string) { + let decoded = "" + try { + decoded = decodeURIComponent(input) + } catch { + return null + } + + const value = decoded.trim().toLowerCase() + if (!value) return null + + if (value.startsWith("zh")) { + if (value.includes("hant") || value.includes("-tw") || value.includes("-hk") || value.includes("-mo")) { + return "zh-tw" + } + return "zh-cn" + } + + if (value in localeAlias) { + return localeAlias[value as keyof typeof localeAlias] + } + + if (value.startsWith("pt")) return "pt-br" + if (value.startsWith("no") || value.startsWith("nb") || value.startsWith("nn")) return "nb" + + return starts.find((item) => value.startsWith(item[0]))?.[1] ?? null +} |
