Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 2 additions & 39 deletions packages/app/src/context/language.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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]])

Expand Down Expand Up @@ -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
Expand Down
35 changes: 35 additions & 0 deletions packages/app/src/i18n/desktop-native.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
31 changes: 31 additions & 0 deletions packages/app/src/i18n/desktop-native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading