Skip to content

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

CodeLanguageCodeLanguage
enEnglishzhSimplified Chinese
zhtTraditional ChinesejaJapanese
koKoreandeGerman
esSpanishfrFrench
ruRussianptPortuguese
arArabicdaDanish
plPolishnoNorwegian
thThaitrTurkish

Selection

Environment Variable

bash
export SWUST_CODE_LOCALE=zh
swust-code

Automatic Detection

The default preference is auto. The detection code checks:

  1. Time zone
  2. LC_ALL, LC_MESSAGES, and LANG
  3. Intl.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

text
/language

Selecting 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

  1. Add a dictionary file under packages/tui/src/i18n/
  2. Import the canonical Keys type from en.ts
  3. Use satisfies Partial<Record<Keys, string>>
  4. Register the locale type and label in locales.ts
  5. Merge the new dictionary in the dictionary-selection logic in context/language.tsx
  6. If the implementation later moves to dynamic loading, make sure first-frame command UI does not flash back to English

Dictionary Shape

typescript
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": "搜索",
}