ZCode needs localization for human-facing CLI and TUI copy without changing the agent protocol, model-visible control text, tool schemas, or event contracts. The first slice keeps localization small, typed, and deterministic so the NL to code loop remains stable while UI copy can move to Chinese.
P0 supports:
en-USzh-CNThe default fallback is en-US. The config value may also be auto, which
resolves from adapter-provided locale hints when available and otherwise falls
back to en-US.
Config shape:
{
"ui": {
"locale": "zh-CN"
}
}
ui.locale accepts en-US, zh-CN, or auto.
Effective priority follows normal config precedence:
No ZCODE_* environment variable is added. If a future environment override is
needed, it must be specified here first with precedence, validation, error
behavior, and test coverage.
auto is resolved only at adapter or entry boundaries. Business modules, core,
and TUI never read environment variables or platform locale APIs directly.
Detection uses the first supported natural-language locale from these hints:
LC_ALLLC_MESSAGESLANGLANGUAGE entries, in colon-separated orderIntl.DateTimeFormat().resolvedOptions().localeLocale parsing strips encoding and modifiers such as .UTF-8 and
@calendar=gregorian, maps _ to -, and accepts common language tags such as
zh, zh_CN, zh-Hans-CN, en, and en_GB. C and POSIX locale values are
ignored because they do not describe a user-facing language preference.
Unsupported detected values are skipped; if no supported value is found, the
effective locale is en-US.
Localized:
/login Coding Plan setup.Not localized:
Slash command names remain stable English protocol tokens such as /help,
/model, and /mcp; summaries and help body text may be localized.
The command center owns /locale; TUI only forwards the prompt and applies the
returned locale projection. Supported forms:
/locale: show the effective locale, the supported configured values, and
whether switching is available in the current client./locale auto/locale en-US/locale zh-CN/language is an input alias for /locale; help and suggestions should present
/locale as the canonical command.
Switching locale is an app/server contract, not a TUI state mutation. The
command calls ZCodeApp.setLocale(), and the app persists the requested config
value before changing the effective in-memory locale exposed by
ZCodeApp.getLocale(). For auto, the requested value stored on disk remains
auto, while the command result returns the resolved effective locale for the
current process.
Persistence target:
ui.locale, update that nearest loaded
project config file so project-specific policy stays round-trippable.--locale remains a process override, but /locale may supersede it for
the active TUI process and for future sessions created in that process.Config writes patch only ui.locale; unrelated model, provider, mcp,
skills, permission, and other user content must be preserved. Write failure
returns a command error and must not update the active effective locale.
@zcode/i18n exports a pure typed catalog plus pure locale-resolution helpers.
It has no filesystem, network, environment, or async initialization path.
Callers select a locale once at their presentation boundary and pass the
resulting copy object to formatters or components.
The CLI must resolve the effective startup locale before rendering the TUI, even
when login is required and ZCodeApp is intentionally not created yet. This
pre-login path still reads the same config precedence as app startup, applies
CLI --locale overrides, resolves auto from adapter-provided detection, and
passes the supported effective locale into local panels such as the Coding Plan
setup picker. This prevents persisted ui.locale: "zh-CN" from being ignored on
the first unauthenticated screen.
Dynamic copy is represented as typed functions, not ad-hoc string interpolation at call sites. Values passed into those functions must already be bounded or redacted by the formatter that understands terminal width and sensitivity.
Missing, unsupported, or malformed locale values resolve to en-US. Invalid
config file values are rejected by the config schema rather than silently
accepted.
contracts defines UiLocale and config keys.adapters/config parses and merges ui.locale.bootstrap exposes the effective locale on ZCodeApp.cli passes CLI/session locale to TUI and uses localized CLI copy for
human-readable output. It provides adapter-level locale hints from standard OS
locale signals.tui renders from the typed copy object and does not read config or
environment directly.core remains locale-agnostic.auto, OS locale hints, and common language tags to
supported locales with deterministic fallback.--locale auto uses detected locale hints for help and TUI startup.ui.locale: "auto" before exposing
ZCodeApp.getLocale()./locale can query or switch the effective locale from the command center,
including TUI slash command flow, and persists the requested value to config.ui.locale is
honored before ZCodeApp exists.