GeezerVison is showing github.com — feat(app): add global locale coverage (#40992) · anotheroni/opencode@741244b
File treeExpand file treeCollapse file tree Open diff view settings Some content is hiddenLarge Commits have some content hidden by default. Use the searchbox below for content that may be hidden. Dismiss bannerExpand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/app/AGENTS.md +4Lines changed: 4 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
| 28 | 28 | - Prefer complete translated phrases. Do not concatenate grammatical fragments or make call sites assemble sentences. Keep placeholders to irreducible dynamic values such as names, paths, and counts. | 29 | 29 | - If a translation cannot be expressed by the current API, deepen the shared language/UI i18n module so one typed call owns locale selection, plural resolution, fallback, and interpolation. Do not leak that machinery into product code. | 30 | 30 | - Do not translate from model knowledge alone. Verify terminology and grammar with Unicode CLDR locale/plural data, Microsoft Localization Style Guides and terminology, Apple localization/style guidance and localized platform UI, Mozilla localization style guides, Mozilla Pontoon, and the Firefox localization corpus at `github.com/mozilla-l10n/firefox-l10n`. | | 31 | +- For developer-facing terminology, prefer the words already used by the target language's developer community over literal dictionary translations. Cross-check maintained localized developer products such as Firefox, KDE, and VS Code; use at least two independent corpora when they are available. If established practice keeps an English loanword or acronym, keep it rather than inventing a translation. | | 32 | +- Translate complete UI phrases in context. A glossary hit is evidence, not permission to translate word-by-word. Check terse labels such as session, prompt, agent, model, fork, shell, terminal, workspace, and worktree in the same grammatical role before choosing a term. | | 33 | +- Before a locale is ready, audit recurring concepts for one consistent translation and review every value that still equals English. Classify retained English as a product name, provider/tool name, URL, code token, keyboard legend, acronym, asset name, or established borrowing; translate unexplained leftovers. | | 34 | +- In translation review notes, name the corpora used and call out uncertain or region-specific terminology so native speakers can focus review where it matters. | 31 | 35 | - Also use the relevant language authority or official dictionary for the locale (for example RAE/Fundéu, FranceTerme, Duden, TDK, Kotus/Kielitoimiston sanakirja, Språkrådet/Bokmålsordboka, Rada Języka Polskiego/PWN, the Russian and Arabic language academies, the Ukrainian Orthography, Taiwan MOE dictionaries, or the Royal Society of Thailand). Treat the English dictionary as the semantic source of truth and preserve placeholders, code identifiers, product names, and keyboard labels. | 32 | 36 |
| 33 | 37 | ## Tool Calling | |
Collapse file Copy file name to clipboardExpand all lines: packages/app/src/context/language.tsx +51-88Lines changed: 51 additions & 88 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -8,17 +8,19 @@ import { dict as en } from "@/i18n/en" | 8 | 8 | import { dict as uiEn } from "@opencode-ai/ui/i18n/en" | 9 | 9 | import { | 10 | 10 | createDesktopNativeBundle, | | 11 | + detectDesktopNativeLocale, | 11 | 12 | DESKTOP_NATIVE_ENGLISH, | 12 | 13 | DESKTOP_NATIVE_LABELS, | 13 | 14 | DESKTOP_NATIVE_LOCALES, | | 15 | + DESKTOP_NATIVE_LOCALE_TAGS, | 14 | 16 | type DesktopNativeBundle, | 15 | 17 | type DesktopNativeLocale, | 16 | 18 | } from "@/i18n/desktop-native" | 17 | 19 |
| 18 | 20 | export type Locale = DesktopNativeLocale | 19 | 21 | export type Direction = "ltr" | "rtl" | 20 | 22 |
| 21 | | -const RTL_LOCALES: ReadonlySet<Locale> = new Set(["ar", "ur", "pa"]) | | 23 | +const RTL_LOCALES: ReadonlySet<Locale> = new Set(["ar", "ur", "pa", "fa", "dv"]) | 22 | 24 |
| 23 | 25 | function localeDirection(locale: Locale): Direction { | 24 | 26 | return RTL_LOCALES.has(locale) ? "rtl" : "ltr" | @@ -39,36 +41,7 @@ function cookie(locale: Locale) { | 39 | 41 |
| 40 | 42 | const LOCALES: readonly Locale[] = DESKTOP_NATIVE_LOCALES | 41 | 43 |
| 42 | | -const INTL: Record<Locale, string> = { | 43 | | - en: "en", | 44 | | - zh: "zh-Hans", | 45 | | - zht: "zh-Hant", | 46 | | - ko: "ko", | 47 | | - de: "de", | 48 | | - es: "es", | 49 | | - fr: "fr", | 50 | | - da: "da", | 51 | | - ja: "ja", | 52 | | - pl: "pl", | 53 | | - ru: "ru", | 54 | | - uk: "uk", | 55 | | - ar: "ar", | 56 | | - no: "nb-NO", | 57 | | - br: "pt-BR", | 58 | | - th: "th", | 59 | | - bs: "bs", | 60 | | - tr: "tr", | 61 | | - hi: "hi-IN", | 62 | | - nl: "nl-NL", | 63 | | - id: "id-ID", | 64 | | - vi: "vi-VN", | 65 | | - it: "it-IT", | 66 | | - ur: "ur-PK", | 67 | | - pa: "pa-Arab-PK", | 68 | | - az: "az-Latn-AZ", | 69 | | - fi: "fi-FI", | 70 | | - sv: "sv-SE", | 71 | | -} | | 44 | +const INTL = DESKTOP_NATIVE_LOCALE_TAGS | 72 | 45 |
| 73 | 46 | const base = i18n.flatten({ ...en, ...uiEn }) | 74 | 47 | const dicts = new Map<Locale, Dictionary>([["en", base]]) | @@ -104,6 +77,40 @@ const loaders: Record<Exclude<Locale, "en">, () => Promise<Dictionary>> = { | 104 | 77 | az: () => merge(import("@/i18n/az"), import("@opencode-ai/ui/i18n/az")), | 105 | 78 | fi: () => merge(import("@/i18n/fi"), import("@opencode-ai/ui/i18n/fi")), | 106 | 79 | sv: () => merge(import("@/i18n/sv"), import("@opencode-ai/ui/i18n/sv")), | | 80 | + am: () => merge(import("@/i18n/am"), import("@opencode-ai/ui/i18n/am")), | | 81 | + bg: () => merge(import("@/i18n/bg"), import("@opencode-ai/ui/i18n/bg")), | | 82 | + bn: () => merge(import("@/i18n/bn"), import("@opencode-ai/ui/i18n/bn")), | | 83 | + ca: () => merge(import("@/i18n/ca"), import("@opencode-ai/ui/i18n/ca")), | | 84 | + cs: () => merge(import("@/i18n/cs"), import("@opencode-ai/ui/i18n/cs")), | | 85 | + dv: () => merge(import("@/i18n/dv"), import("@opencode-ai/ui/i18n/dv")), | | 86 | + dz: () => merge(import("@/i18n/dz"), import("@opencode-ai/ui/i18n/dz")), | | 87 | + el: () => merge(import("@/i18n/el"), import("@opencode-ai/ui/i18n/el")), | | 88 | + et: () => merge(import("@/i18n/et"), import("@opencode-ai/ui/i18n/et")), | | 89 | + fa: () => merge(import("@/i18n/fa"), import("@opencode-ai/ui/i18n/fa")), | | 90 | + fo: () => merge(import("@/i18n/fo"), import("@opencode-ai/ui/i18n/fo")), | | 91 | + hr: () => merge(import("@/i18n/hr"), import("@opencode-ai/ui/i18n/hr")), | | 92 | + hu: () => merge(import("@/i18n/hu"), import("@opencode-ai/ui/i18n/hu")), | | 93 | + hy: () => merge(import("@/i18n/hy"), import("@opencode-ai/ui/i18n/hy")), | | 94 | + is: () => merge(import("@/i18n/is"), import("@opencode-ai/ui/i18n/is")), | | 95 | + ka: () => merge(import("@/i18n/ka"), import("@opencode-ai/ui/i18n/ka")), | | 96 | + km: () => merge(import("@/i18n/km"), import("@opencode-ai/ui/i18n/km")), | | 97 | + lo: () => merge(import("@/i18n/lo"), import("@opencode-ai/ui/i18n/lo")), | | 98 | + lt: () => merge(import("@/i18n/lt"), import("@opencode-ai/ui/i18n/lt")), | | 99 | + lv: () => merge(import("@/i18n/lv"), import("@opencode-ai/ui/i18n/lv")), | | 100 | + mk: () => merge(import("@/i18n/mk"), import("@opencode-ai/ui/i18n/mk")), | | 101 | + mn: () => merge(import("@/i18n/mn"), import("@opencode-ai/ui/i18n/mn")), | | 102 | + ms: () => merge(import("@/i18n/ms"), import("@opencode-ai/ui/i18n/ms")), | | 103 | + my: () => merge(import("@/i18n/my"), import("@opencode-ai/ui/i18n/my")), | | 104 | + ne: () => merge(import("@/i18n/ne"), import("@opencode-ai/ui/i18n/ne")), | | 105 | + ro: () => merge(import("@/i18n/ro"), import("@opencode-ai/ui/i18n/ro")), | | 106 | + si: () => merge(import("@/i18n/si"), import("@opencode-ai/ui/i18n/si")), | | 107 | + sk: () => merge(import("@/i18n/sk"), import("@opencode-ai/ui/i18n/sk")), | | 108 | + sl: () => merge(import("@/i18n/sl"), import("@opencode-ai/ui/i18n/sl")), | | 109 | + sq: () => merge(import("@/i18n/sq"), import("@opencode-ai/ui/i18n/sq")), | | 110 | + sr: () => merge(import("@/i18n/sr"), import("@opencode-ai/ui/i18n/sr")), | | 111 | + tg: () => merge(import("@/i18n/tg"), import("@opencode-ai/ui/i18n/tg")), | | 112 | + tk: () => merge(import("@/i18n/tk"), import("@opencode-ai/ui/i18n/tk")), | | 113 | + uz: () => merge(import("@/i18n/uz"), import("@opencode-ai/ui/i18n/uz")), | 107 | 114 | } | 108 | 115 |
| 109 | 116 | function loadDict(locale: Locale) { | @@ -121,63 +128,9 @@ export function loadLocaleDict(locale: Locale) { | 121 | 128 | return loadDict(locale).then(() => undefined) | 122 | 129 | } | 123 | 130 |
| 124 | | -const localeMatchers: Array<{ locale: Locale; match: (language: string) => boolean }> = [ | 125 | | - { locale: "en", match: (language) => language.startsWith("en") }, | 126 | | - { | 127 | | - locale: "zht", | 128 | | - match: (language) => | 129 | | - language.startsWith("zh") && | 130 | | - (language.includes("hant") || language.includes("-tw") || language.includes("-hk") || language.includes("-mo")), | 131 | | - }, | 132 | | - { locale: "zh", match: (language) => language.startsWith("zh") }, | 133 | | - { locale: "ko", match: (language) => language.startsWith("ko") }, | 134 | | - { locale: "de", match: (language) => language.startsWith("de") }, | 135 | | - { locale: "es", match: (language) => language.startsWith("es") }, | 136 | | - { locale: "fr", match: (language) => language.startsWith("fr") }, | 137 | | - { locale: "da", match: (language) => language.startsWith("da") }, | 138 | | - { locale: "ja", match: (language) => language.startsWith("ja") }, | 139 | | - { locale: "pl", match: (language) => language.startsWith("pl") }, | 140 | | - { locale: "ru", match: (language) => language.startsWith("ru") }, | 141 | | - { locale: "uk", match: (language) => language.startsWith("uk") }, | 142 | | - { locale: "ar", match: (language) => language.startsWith("ar") }, | 143 | | - { | 144 | | - locale: "no", | 145 | | - match: (language) => language.startsWith("no") || language.startsWith("nb") || language.startsWith("nn"), | 146 | | - }, | 147 | | - { locale: "br", match: (language) => language.startsWith("pt") }, | 148 | | - { locale: "th", match: (language) => language.startsWith("th") }, | 149 | | - { locale: "bs", match: (language) => language.startsWith("bs") }, | 150 | | - { locale: "tr", match: (language) => language.startsWith("tr") }, | 151 | | - { locale: "hi", match: (language) => language.startsWith("hi") }, | 152 | | - { locale: "nl", match: (language) => language.startsWith("nl") }, | 153 | | - { locale: "id", match: (language) => language.startsWith("id") }, | 154 | | - { locale: "vi", match: (language) => language.startsWith("vi") }, | 155 | | - { locale: "it", match: (language) => language.startsWith("it") }, | 156 | | - { locale: "ur", match: (language) => language.startsWith("ur") }, | 157 | | - { | 158 | | - locale: "pa", | 159 | | - match: (language) => language.startsWith("pa") && (language.includes("arab") || language.includes("-pk")), | 160 | | - }, | 161 | | - { | 162 | | - locale: "az", | 163 | | - match: (language) => language.startsWith("az") && !language.includes("arab") && !language.includes("cyrl"), | 164 | | - }, | 165 | | - { locale: "fi", match: (language) => language.startsWith("fi") }, | 166 | | - { locale: "sv", match: (language) => language.startsWith("sv") }, | 167 | | -] | 168 | | - | 169 | 131 | function detectLocale(): Locale { | 170 | 132 | if (typeof navigator !== "object") return "en" | 171 | | - | 172 | | - const languages = navigator.languages?.length ? navigator.languages : [navigator.language] | 173 | | - for (const language of languages) { | 174 | | - if (!language) continue | 175 | | - const normalized = language.toLowerCase() | 176 | | - const match = localeMatchers.find((entry) => entry.match(normalized)) | 177 | | - if (match) return match.locale | 178 | | - } | 179 | | - | 180 | | - return "en" | | 133 | + return detectDesktopNativeLocale(navigator.languages?.length ? navigator.languages : [navigator.language]) | 181 | 134 | } | 182 | 135 |
| 183 | 136 | export function normalizeLocale(value: string): Locale { | @@ -198,7 +151,17 @@ function readStoredLocale() { | 198 | 151 | } | 199 | 152 |
| 200 | 153 | const warm = readStoredLocale() ?? detectLocale() | 201 | | -if (warm !== "en") void loadDict(warm) | | 154 | +const initialLocale = | | 155 | + warm === "en" | | 156 | + ? Promise.resolve(warm) | | 157 | + : loadDict(warm).then( | | 158 | + () => warm, | | 159 | + () => "en" as const, | | 160 | + ) | | 161 | + | | 162 | +export function loadInitialLocale() { | | 163 | + return initialLocale | | 164 | +} | 202 | 165 |
| 203 | 166 | export const { use: useLanguage, provider: LanguageProvider } = createSimpleContext({ | 204 | 167 | name: "Language", | @@ -244,7 +207,7 @@ export const { use: useLanguage, provider: LanguageProvider } = createSimpleCont | 244 | 207 | createEffect(() => { | 245 | 208 | if (typeof document !== "object") return | 246 | 209 | const value = locale() | 247 | | - document.documentElement.lang = value | | 210 | + document.documentElement.lang = intl() | 248 | 211 | document.documentElement.dir = direction() | 249 | 212 | document.cookie = cookie(value) | 250 | 213 | }) | |
Collapse file Copy file name to clipboardExpand all lines: packages/app/src/entry.tsx +28-25Lines changed: 28 additions & 25 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 3 | 3 | import * as Sentry from "@sentry/solid" | 4 | 4 | import { render } from "solid-js/web" | 5 | 5 | import { AppBaseProviders, AppInterface } from "@/app" | | 6 | +import { loadInitialLocale } from "@/context/language" | 6 | 7 | import { type Platform, PlatformProvider } from "@/context/platform" | 7 | 8 | import { createBrowserDraftStore } from "@/utils/draft-store" | 8 | 9 | import { dict as en } from "@/i18n/en" | @@ -149,29 +150,31 @@ if (import.meta.env.VITE_SENTRY_DSN) { | 149 | 150 | } | 150 | 151 |
| 151 | 152 | if (root instanceof HTMLElement) { | 152 | | - const auth = authFromToken(new URLSearchParams(location.search).get("auth_token")) | 153 | | - clearAuthToken() | 154 | | - const server: ServerConnection.Http = { | 155 | | - type: "http", | 156 | | - authToken: !!auth, | 157 | | - http: { | 158 | | - url: getCurrentUrl(), | 159 | | - ...auth, | 160 | | - }, | 161 | | - } | 162 | | - render( | 163 | | - () => ( | 164 | | - <PlatformProvider value={platform}> | 165 | | - <AppBaseProviders> | 166 | | - <AppInterface | 167 | | - defaultServer={ServerConnection.Key.make(getDefaultUrl())} | 168 | | - canonicalLocalServer={ServerConnection.key(server)} | 169 | | - servers={[server]} | 170 | | - disableHealthCheck | 171 | | - /> | 172 | | - </AppBaseProviders> | 173 | | - </PlatformProvider> | 174 | | - ), | 175 | | - root, | 176 | | - ) | | 153 | + void loadInitialLocale().then((locale) => { | | 154 | + const auth = authFromToken(new URLSearchParams(location.search).get("auth_token")) | | 155 | + clearAuthToken() | | 156 | + const server: ServerConnection.Http = { | | 157 | + type: "http", | | 158 | + authToken: !!auth, | | 159 | + http: { | | 160 | + url: getCurrentUrl(), | | 161 | + ...auth, | | 162 | + }, | | 163 | + } | | 164 | + render( | | 165 | + () => ( | | 166 | + <PlatformProvider value={platform}> | | 167 | + <AppBaseProviders locale={locale}> | | 168 | + <AppInterface | | 169 | + defaultServer={ServerConnection.Key.make(getDefaultUrl())} | | 170 | + canonicalLocalServer={ServerConnection.key(server)} | | 171 | + servers={[server]} | | 172 | + disableHealthCheck | | 173 | + /> | | 174 | + </AppBaseProviders> | | 175 | + </PlatformProvider> | | 176 | + ), | | 177 | + root, | | 178 | + ) | | 179 | + }) | 177 | 180 | } |
|