fix(app): keep locale names native (#40985)
Co-authored-by: Luke Parker <10430890+Hona@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
bbd3c3f874
commit
4c3eb4a9a2
@@ -9,6 +9,7 @@ import { dict as uiEn } from "@opencode-ai/ui/i18n/en"
|
|||||||
import {
|
import {
|
||||||
createDesktopNativeBundle,
|
createDesktopNativeBundle,
|
||||||
DESKTOP_NATIVE_ENGLISH,
|
DESKTOP_NATIVE_ENGLISH,
|
||||||
|
DESKTOP_NATIVE_LABELS,
|
||||||
DESKTOP_NATIVE_LOCALES,
|
DESKTOP_NATIVE_LOCALES,
|
||||||
type DesktopNativeBundle,
|
type DesktopNativeBundle,
|
||||||
type DesktopNativeLocale,
|
type DesktopNativeLocale,
|
||||||
@@ -69,40 +70,6 @@ const INTL: Record<Locale, string> = {
|
|||||||
sv: "sv-SE",
|
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 base = i18n.flatten({ ...en, ...uiEn })
|
||||||
const dicts = new Map<Locale, Dictionary>([["en", base]])
|
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 })
|
return i18n.resolveTemplate(current[candidate] ?? current[fallback] ?? fallback, { ...params, count })
|
||||||
}
|
}
|
||||||
|
|
||||||
const label = (value: Locale) => {
|
const label = (value: Locale) => DESKTOP_NATIVE_LABELS[value]
|
||||||
const key = LABEL_KEY[value]
|
|
||||||
if (key) return t(key)
|
|
||||||
return LABEL[value] ?? value
|
|
||||||
}
|
|
||||||
|
|
||||||
createEffect(() => {
|
createEffect(() => {
|
||||||
if (typeof document !== "object") return
|
if (typeof document !== "object") return
|
||||||
|
|||||||
@@ -3,12 +3,47 @@ import {
|
|||||||
createDesktopNativeBundle,
|
createDesktopNativeBundle,
|
||||||
DESKTOP_NATIVE_ENGLISH,
|
DESKTOP_NATIVE_ENGLISH,
|
||||||
DESKTOP_NATIVE_KEYS,
|
DESKTOP_NATIVE_KEYS,
|
||||||
|
DESKTOP_NATIVE_LABELS,
|
||||||
|
DESKTOP_NATIVE_LOCALES,
|
||||||
DESKTOP_NATIVE_MAX_PAYLOAD_BYTES,
|
DESKTOP_NATIVE_MAX_PAYLOAD_BYTES,
|
||||||
formatDesktopNativeMessage,
|
formatDesktopNativeMessage,
|
||||||
parseDesktopNativeBundle,
|
parseDesktopNativeBundle,
|
||||||
} from "./desktop-native"
|
} from "./desktop-native"
|
||||||
|
|
||||||
describe("desktop native translations", () => {
|
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", () => {
|
test("accepts the exact typed bundle", () => {
|
||||||
const bundle = createDesktopNativeBundle("en", (key) => DESKTOP_NATIVE_ENGLISH[key])
|
const bundle = createDesktopNativeBundle("en", (key) => DESKTOP_NATIVE_ENGLISH[key])
|
||||||
expect(parseDesktopNativeBundle(bundle)).toEqual(bundle)
|
expect(parseDesktopNativeBundle(bundle)).toEqual(bundle)
|
||||||
|
|||||||
@@ -31,6 +31,37 @@ export const DESKTOP_NATIVE_LOCALES = [
|
|||||||
|
|
||||||
export type DesktopNativeLocale = (typeof DESKTOP_NATIVE_LOCALES)[number]
|
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 = {
|
export const DESKTOP_NATIVE_ENGLISH = {
|
||||||
"desktop.menu.app": "OpenCode",
|
"desktop.menu.app": "OpenCode",
|
||||||
"desktop.menu.file": "File",
|
"desktop.menu.file": "File",
|
||||||
|
|||||||
Reference in New Issue
Block a user