Internationalization (i18n)
SWUST Code now has an i18n context for the TUI. v0.3 expands the English (en) and Simplified Chinese (zh) dictionaries and wires command palette, permission prompts, prompt input, sidebar text, and common dialogs through the translation function. Other locale codes are still present in types and labels, but need dictionaries.
Supported Locale Codes
| Code | Language | Code | Language |
|---|---|---|---|
| en | English | zh | Simplified Chinese |
| zht | Traditional Chinese | ja | Japanese |
| ko | Korean | de | German |
| es | Spanish | fr | French |
| ru | Russian | pt | Portuguese |
| ar | Arabic | da | Danish |
| pl | Polish | no | Norwegian |
| th | Thai | tr | Turkish |
Selection
Environment Variable
export SWUST_CODE_LOCALE=zh
swust-codeAutomatic Detection
The default preference is auto. The detection code checks:
- Time zone
LC_ALL,LC_MESSAGES, andLANGIntl.DateTimeFormat().resolvedOptions().locale
The current local implementation detects the effective locale synchronously and merges the English and Chinese dictionaries for Simplified or Traditional Chinese environments. setLocale() writes the TUI KV preference, and the language picker is available from the command palette or /language.
TUI Command
/languageSelecting auto returns to automatic detection. Selecting a concrete locale persists it in TUI KV. Command names and slash entries stay in English or slash form, while descriptions and categories are localized.
Adding a Language
- Add a dictionary file under
packages/tui/src/i18n/ - Import the canonical
Keystype fromen.ts - Use
satisfies Partial<Record<Keys, string>> - Register the locale type and label in
locales.ts - Merge the new dictionary in the dictionary-selection logic in
context/language.tsx - If the implementation later moves to dynamic loading, make sure first-frame command UI does not flash back to English
Dictionary Shape
const en = {
"tui.prompt.placeholder.normal": "Ask anything... \"{{example}}\"",
"tui.command.language.switch.title": "Switch language",
"tui.dialog.select.placeholder": "Search",
} as const
import type { Dictionary } from "./en"
const zh: Dictionary = {
"tui.prompt.placeholder.normal": "询问任何问题...\"{{example}}\"",
"tui.command.language.switch.title": "切换语言",
"tui.dialog.select.placeholder": "搜索",
}