fix(app): keep locale names native (#40985)

Co-authored-by: Luke Parker <10430890+Hona@users.noreply.github.com>
This commit is contained in:
opencode-agent[bot] 2026-08-07 03:32:43 +00:00 committed by GitHub
parent 8d65dbdd04
commit 31c5c4e924
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 68 additions and 39 deletions

View file

@ -9,6 +9,7 @@ import { dict as uiEn } from "@opencode-ai/ui/i18n/en"
import {
createDesktopNativeBundle,
DESKTOP_NATIVE_ENGLISH,
DESKTOP_NATIVE_LABELS,
DESKTOP_NATIVE_LOCALES,
type DesktopNativeBundle,
type DesktopNativeLocale,
@ -69,40 +70,6 @@ const INTL: Record<Locale, string> = {
sv: "sv-SE",
}
const LABEL_KEY: Partial<Record<Locale, keyof Dictionary>> = {
en: "language.en",
zh: "language.zh",
zht: "language.zht",
ko: "language.ko",
de: "language.de",
es: "language.es",
fr: "language.fr",
da: "language.da",
ja: "language.ja",
pl: "language.pl",
ru: "language.ru",
uk: "language.uk",
ar: "language.ar",
no: "language.no",
br: "language.br",
th: "language.th",
bs: "language.bs",
tr: "language.tr",
}
const LABEL: Partial<Record<Locale, string>> = {
hi: "हिन्दी",
nl: "Nederlands",
id: "Bahasa Indonesia",
vi: "Tiếng Việt",
it: "Italiano",
ur: "اردو",
pa: "پنجابی",
az: "Azərbaycanca",
fi: "Suomi",
sv: "Svenska",
}
const base = i18n.flatten({ ...en, ...uiEn })
const dicts = new Map<Locale, Dictionary>([["en", base]])
@ -272,11 +239,7 @@ export const { use: useLanguage, provider: LanguageProvider } = createSimpleCont
return i18n.resolveTemplate(current[candidate] ?? current[fallback] ?? fallback, { ...params, count })
}
const label = (value: Locale) => {
const key = LABEL_KEY[value]
if (key) return t(key)
return LABEL[value] ?? value
}
const label = (value: Locale) => DESKTOP_NATIVE_LABELS[value]
createEffect(() => {
if (typeof document !== "object") return

View file

@ -3,12 +3,47 @@ import {
createDesktopNativeBundle,
DESKTOP_NATIVE_ENGLISH,
DESKTOP_NATIVE_KEYS,
DESKTOP_NATIVE_LABELS,
DESKTOP_NATIVE_LOCALES,
DESKTOP_NATIVE_MAX_PAYLOAD_BYTES,
formatDesktopNativeMessage,
parseDesktopNativeBundle,
} from "./desktop-native"
describe("desktop native translations", () => {
test("uses native language names independent of the active locale", () => {
expect(DESKTOP_NATIVE_LOCALES.map((locale) => DESKTOP_NATIVE_LABELS[locale])).toEqual([
"English",
"简体中文",
"繁體中文",
"한국어",
"Deutsch",
"Español",
"Français",
"Dansk",
"日本語",
"Polski",
"Русский",
"Українська",
"Bosanski",
"العربية",
"Norsk",
"Português (Brasil)",
"ไทย",
"Türkçe",
"हिन्दी",
"Nederlands",
"Bahasa Indonesia",
"Tiếng Việt",
"Italiano",
"اردو",
"پنجابی",
"Azərbaycanca",
"Suomi",
"Svenska",
])
})
test("accepts the exact typed bundle", () => {
const bundle = createDesktopNativeBundle("en", (key) => DESKTOP_NATIVE_ENGLISH[key])
expect(parseDesktopNativeBundle(bundle)).toEqual(bundle)

View file

@ -31,6 +31,37 @@ export const DESKTOP_NATIVE_LOCALES = [
export type DesktopNativeLocale = (typeof DESKTOP_NATIVE_LOCALES)[number]
export const DESKTOP_NATIVE_LABELS: Record<DesktopNativeLocale, string> = {
en: "English",
zh: "简体中文",
zht: "繁體中文",
ko: "한국어",
de: "Deutsch",
es: "Español",
fr: "Français",
da: "Dansk",
ja: "日本語",
pl: "Polski",
ru: "Русский",
uk: "Українська",
bs: "Bosanski",
ar: "العربية",
no: "Norsk",
br: "Português (Brasil)",
th: "ไทย",
tr: "Türkçe",
hi: "हिन्दी",
nl: "Nederlands",
id: "Bahasa Indonesia",
vi: "Tiếng Việt",
it: "Italiano",
ur: "اردو",
pa: "پنجابی",
az: "Azərbaycanca",
fi: "Suomi",
sv: "Svenska",
}
export const DESKTOP_NATIVE_ENGLISH = {
"desktop.menu.app": "OpenCode",
"desktop.menu.file": "File",