From 7dd48f6431b36cba621fcf221b4212c172e19f9d Mon Sep 17 00:00:00 2001 From: Jiaxiaoyuan Date: Fri, 20 Nov 2026 09:44:33 +0800 Subject: [PATCH] fix(tui): allow explicit display locale overrides --- .aoci/baseline.json | 74 ++++++++++--------- aoci.code.txt | 17 +++-- docs/installation.md | 3 + .../tui/src/tui/features/changelog/content.ts | 11 +-- .../tui/src/tui/features/composer/copy.ts | 11 +-- .../src/tui/features/session-mutation/copy.ts | 15 ++-- .../tui/features/settings/status-line-copy.ts | 3 +- packages/tui/src/tui/foundation/locale.ts | 4 + packages/tui/src/tui/shell/chrome.ts | 3 +- .../test/unit/tui-status-line-items.test.ts | 6 ++ release/public-source.json | 1 + scripts/run-vitest-suite.mjs | 1 + test/source-sync.test.mjs | 13 +++- 13 files changed, 89 insertions(+), 73 deletions(-) create mode 100644 packages/tui/src/tui/foundation/locale.ts diff --git a/.aoci/baseline.json b/.aoci/baseline.json index 5e71736b3..84b6c5e21 100644 --- a/.aoci/baseline.json +++ b/.aoci/baseline.json @@ -1,7 +1,7 @@ { "version": 1, "created_at": "2026-11-19T05:53:26Z", - "updated_at": "2026-11-20T01:35:42Z", + "updated_at": "2026-11-20T01:44:19Z", "files": { ".agents/skills/changelog-card-publish/SKILL.md": { "role": "index", @@ -773,9 +773,9 @@ }, "aoci.code.txt": { "role": "index", - "sha256": "251d96fb088590d8761d51f2d6033c31857b5c6cc4d3c7265f303fd80292731c", - "size": 636382, - "normalized_sha256": "251d96fb088590d8761d51f2d6033c31857b5c6cc4d3c7265f303fd80292731c" + "sha256": "b7537017aa924a83b866decc563fed9e4faeeaa5922251d6af021f394d789c18", + "size": 637015, + "normalized_sha256": "b7537017aa924a83b866decc563fed9e4faeeaa5922251d6af021f394d789c18" }, "aoci.meta.txt": { "role": "index", @@ -1660,9 +1660,9 @@ }, "docs/installation.md": { "role": "index", - "sha256": "668b1ce5ee5c9b96cd2a5384f82bf059a26e9a2b6b6d95d565254e0421606bc5", - "size": 13733, - "normalized_sha256": "668b1ce5ee5c9b96cd2a5384f82bf059a26e9a2b6b6d95d565254e0421606bc5" + "sha256": "faa8222630a4086996a5b6a1d32937c13c539f639af2024d1820ee3982c85586", + "size": 13887, + "normalized_sha256": "faa8222630a4086996a5b6a1d32937c13c539f639af2024d1820ee3982c85586" }, "docs/maintainers.md": { "role": "index", @@ -21736,9 +21736,9 @@ }, "packages/tui/src/tui/features/changelog/content.ts": { "role": "index", - "sha256": "157947c38df6e99c435bccf624e3253f6a8aeac73568dc145cb347853126fb89", - "size": 4112, - "normalized_sha256": "157947c38df6e99c435bccf624e3253f6a8aeac73568dc145cb347853126fb89" + "sha256": "3a52c4ba9a94590eb043834ac8166acf041bb12e4e02681764f3e17cbd601c58", + "size": 4020, + "normalized_sha256": "3a52c4ba9a94590eb043834ac8166acf041bb12e4e02681764f3e17cbd601c58" }, "packages/tui/src/tui/features/changelog/panel.ts": { "role": "index", @@ -21766,9 +21766,9 @@ }, "packages/tui/src/tui/features/composer/copy.ts": { "role": "index", - "sha256": "d05931872c8b5e98ec179afc552e3726405a15c88aac72465ff0eb77b6c18f7b", - "size": 553, - "normalized_sha256": "d05931872c8b5e98ec179afc552e3726405a15c88aac72465ff0eb77b6c18f7b" + "sha256": "e1ea46219c228ac34a330d81a711cbca9cc6f775c1b34bed98163d80b007ed1f", + "size": 465, + "normalized_sha256": "e1ea46219c228ac34a330d81a711cbca9cc6f775c1b34bed98163d80b007ed1f" }, "packages/tui/src/tui/features/composer/copy.zh-Hans.ts": { "role": "index", @@ -21982,9 +21982,9 @@ }, "packages/tui/src/tui/features/session-mutation/copy.ts": { "role": "index", - "sha256": "dbc158ec440c80d010aed1f75a5021d33487e7a26339ab631ad3bf5690cf9d2e", - "size": 1398, - "normalized_sha256": "dbc158ec440c80d010aed1f75a5021d33487e7a26339ab631ad3bf5690cf9d2e" + "sha256": "c3afe6d4e6697a1c7e37b4598fc830740739455b406336270ab9462d51db42bc", + "size": 1348, + "normalized_sha256": "c3afe6d4e6697a1c7e37b4598fc830740739455b406336270ab9462d51db42bc" }, "packages/tui/src/tui/features/session-mutation/copy.zh-Hans.ts": { "role": "index", @@ -22048,9 +22048,9 @@ }, "packages/tui/src/tui/features/settings/status-line-copy.ts": { "role": "index", - "sha256": "f77c7845611b5bcf0adfb61d26586a886ce08097ee64ce4f3cbba7800789d39f", - "size": 3337, - "normalized_sha256": "f77c7845611b5bcf0adfb61d26586a886ce08097ee64ce4f3cbba7800789d39f" + "sha256": "42d4451ecb7dcc54660555b394f40ceb52bbc28678af1a528cf67fff1aefd175", + "size": 3372, + "normalized_sha256": "42d4451ecb7dcc54660555b394f40ceb52bbc28678af1a528cf67fff1aefd175" }, "packages/tui/src/tui/features/settings/status-line-picker.ts": { "role": "index", @@ -22082,6 +22082,12 @@ "size": 5201, "normalized_sha256": "6913c4360f7c9ea8e8ff4a6b6219cf696535bd5bffe722e7a4abbacbd7958505" }, + "packages/tui/src/tui/foundation/locale.ts": { + "role": "index", + "sha256": "6e059cf9cd519d126eb758bccff0442a55802b23041a29a55120611b00d4bb2b", + "size": 173, + "normalized_sha256": "6e059cf9cd519d126eb758bccff0442a55802b23041a29a55120611b00d4bb2b" + }, "packages/tui/src/tui/goal-composition.ts": { "role": "index", "sha256": "51f8a3d3ddb64de3578d951e0e5660a9d5fe6ed5cdc7351e888675989cc5f343", @@ -22234,9 +22240,9 @@ }, "packages/tui/src/tui/shell/chrome.ts": { "role": "index", - "sha256": "f1ce259a969882bac3ded4163bc6b45fc771c8f063499d5b0bcbe521ea0a30bc", - "size": 25340, - "normalized_sha256": "f1ce259a969882bac3ded4163bc6b45fc771c8f063499d5b0bcbe521ea0a30bc" + "sha256": "7da9aecb348d6fb879fccb425d7fa90abcb2eb6e1ccb776e5f70e4149b7dfc40", + "size": 25372, + "normalized_sha256": "7da9aecb348d6fb879fccb425d7fa90abcb2eb6e1ccb776e5f70e4149b7dfc40" }, "packages/tui/src/tui/shell/composer.ts": { "role": "index", @@ -23164,9 +23170,9 @@ }, "packages/tui/test/unit/tui-status-line-items.test.ts": { "role": "observe", - "sha256": "3c5dbf82a0c69e2ebe812e714675a353520f48ae012bdf518c99d7eb1e35a7d7", - "size": 29445, - "normalized_sha256": "3c5dbf82a0c69e2ebe812e714675a353520f48ae012bdf518c99d7eb1e35a7d7" + "sha256": "17220487e4db812e97aff41b1b2a2bf2a6df8763f0821e0e943669afbca76e74", + "size": 29832, + "normalized_sha256": "17220487e4db812e97aff41b1b2a2bf2a6df8763f0821e0e943669afbca76e74" }, "packages/tui/test/unit/tui-stream-events.test.ts": { "role": "observe", @@ -32034,9 +32040,9 @@ }, "release/public-source.json": { "role": "index", - "sha256": "889a7423fe6d64dbe26a6e07d6df22b4bef6bc8194a06fc04c0e3fb2c287785d", - "size": 457094, - "normalized_sha256": "889a7423fe6d64dbe26a6e07d6df22b4bef6bc8194a06fc04c0e3fb2c287785d" + "sha256": "63c07683867cfb8534b9108565c6b348b4b2d7f7f5e2849fd684a548fb71bb48", + "size": 457143, + "normalized_sha256": "63c07683867cfb8534b9108565c6b348b4b2d7f7f5e2849fd684a548fb71bb48" }, "release/webui-npm/README.md": { "role": "index", @@ -32454,9 +32460,9 @@ }, "scripts/run-vitest-suite.mjs": { "role": "index", - "sha256": "4e6f1ea5087536d1ad1c1c9b3a2b45e74876fda9bd1429035a043f9492440fb3", - "size": 2500, - "normalized_sha256": "4e6f1ea5087536d1ad1c1c9b3a2b45e74876fda9bd1429035a043f9492440fb3" + "sha256": "5f892851ed853f2de96f15690cd7fd5f5fbd7679acd95db320883f398feec290", + "size": 2540, + "normalized_sha256": "5f892851ed853f2de96f15690cd7fd5f5fbd7679acd95db320883f398feec290" }, "scripts/run-webui-server.mjs": { "role": "index", @@ -32550,9 +32556,9 @@ }, "test/source-sync.test.mjs": { "role": "index", - "sha256": "d39f4736e954df57652b623fa3fffb8f511994c39cc69317845538f9cb258aea", - "size": 95467, - "normalized_sha256": "d39f4736e954df57652b623fa3fffb8f511994c39cc69317845538f9cb258aea" + "sha256": "0361f51f0cce349c80c1c19cbac951c668be935875b845ed1be78667c804184e", + "size": 95653, + "normalized_sha256": "0361f51f0cce349c80c1c19cbac951c668be935875b845ed1be78667c804184e" }, "test/sqlite-message-contention.test.ts": { "role": "observe", diff --git a/aoci.code.txt b/aoci.code.txt index b6c5f1a9e..f8db63fa3 100644 --- a/aoci.code.txt +++ b/aoci.code.txt @@ -197,7 +197,7 @@ architecture.md[SG4T]: F:Explains package boundaries and integration among clien demo.md[SG4T]: F:Walks through a recorded product demo that turns a request into a verified code change. | R:- | A:- | S:- examples.md[SG4M]: F:Provides practical examples for editing code, running tests, and using a custom model. | R:- | A:- | S:- hooks.md[SG4T]: F:Specifies how hook messages reach the TUI and model context, including event limits. | R:- | A:- | S:- -installation.md[SG4S]: F:Documents checksum-verified release archive installation and source builds. | R:- | A:- | S:- +installation.md[SG4S]: F:Documents verified release installation, source builds, data directories and the TUI language override. | R:code:packages/tui/src/tui/foundation/locale.ts | A:- | S:- maintainers.md[SG4T]: F:Defines maintainer responsibilities, issue triage, and release and review ownership. | R:- | A:- | S:- open-source-status.md[SG4T]: F:Records the public source release baseline, supported scope, and evidence boundaries. | R:- | A:- | S:- performance-ci.md[SG4S]: F:Defines performance CI profiles, suite selection, and required comparison evidence. | R:- | A:- | S:- @@ -4267,14 +4267,14 @@ codex-login.ts[SE4M]: F:Renders the Codex login component. | R:- | A:- | S:- login-region-picker.ts[SE4T]: F:Presents the login region picker. | R:- | A:- | S:- ===//packages/tui/src/tui/features/changelog/=== -content.ts[SE4S]: F:Loads and extracts localized TUI changelog content. | R:- | A:- | S:- +content.ts[SL4S]: F:Loads localized TUI changelog content and extracts release sections. | R:code:packages/tui/src/tui/foundation/locale.ts | A:- | S:- panel.ts[SE4S]: F:Implements the TUI changelog panel. | R:- | A:- | S:- ===//packages/tui/src/tui/features/composer/=== attachments.ts[SE4S]: F:Formats attachment labels for the TUI composer. | R:- | A:- | S:- clipboard-image-draft.ts[SE4M]: F:Coordinates clipboard image reads and insertion into composer drafts. | R:- | A:- | S:- copy.en.ts[SE4T]: F:Defines English composer strings and their translation keys. | R:- | A:- | S:- -copy.ts[SE4T]: F:Looks up localized composer strings. | R:- | A:- | S:- +copy.ts[SL4T]: F:Selects English or Chinese composer copy using the explicit or resolved TUI locale. | R:code:packages/tui/src/tui/foundation/locale.ts | A:- | S:- copy.zh-Hans.ts[SE4T]: F:Defines Simplified Chinese composer strings. | R:- | A:- | S:- draft-lifecycle.ts[SE4L]: F:Manages TUI composer draft lifecycle. | R:- | A:- | S:- draft-recovery.ts[SE4L]: F:Recovers composer drafts and reports typed recovery errors. | R:- | A:- | S:- @@ -4332,7 +4332,7 @@ paused-send-panel.ts[SE4T]: F:Presents send choices when the message queue is pa ===//packages/tui/src/tui/features/session-mutation/=== copy.en.ts[SE4S]: F:Defines English session history text and translation keys. | R:- | A:- | S:- -copy.ts[SE4T]: F:Selects locale and supplies session history and mutation text. | R:- | A:- | S:- +copy.ts[SL4T]: F:Supplies localized session history and mutation copy. | R:code:packages/tui/src/tui/foundation/locale.ts | A:- | S:- copy.zh-Hans.ts[SE4S]: F:Defines Simplified Chinese session history and mutation text. | R:- | A:- | S:- format.ts[SE4S]: F:Formats session timestamps and truncates prompt previews for display. | R:- | A:- | S:- history-explorer.ts[SE4L]: F:Presents session history and exposes available history actions. | R:- | A:- | S:- @@ -4347,7 +4347,7 @@ manager.ts[SE4L]: F:Implements the interactive session manager. | R:- | A:- | S: ===//packages/tui/src/tui/features/settings/=== hotkeys-picker.ts[SE4M]: F:Presents configurable TUI hotkeys. | R:- | A:- | S:- picker.ts[SE4S]: F:Implements the TUI settings picker. | R:- | A:- | S:- -status-line-copy.ts[SE4T]: F:Looks up localized status line labels and item descriptions. | R:- | A:- | S:- +status-line-copy.ts[SL4T]: F:Supplies localized status line settings labels and item descriptions. | R:code:packages/tui/src/tui/foundation/locale.ts | A:- | S:- status-line-picker.ts[SE4M]: F:Implements interactive selection of status line items. | R:- | A:- | S:- theme-picker.ts[SE4M]: F:Models automatic and explicit theme appearance choices and provides a picker. | R:- | A:- | S:- @@ -4359,6 +4359,7 @@ panel.ts[SE4L]: F:Presents TUI software update status and actions. | R:- | A:- | ===//packages/tui/src/tui/foundation/=== bordered-table.ts[SE4S]: F:Renders bordered terminal tables from rows and sections. | R:- | A:- | S:- +locale.ts[CL5T]: F:Resolves the default TUI display locale. | R:- | A:resolveTuiLocale | S:A nonempty MCODE_TUI_LOCALE overrides the host ICU locale. ===//packages/tui/src/tui/interaction/=== permission.ts[SE4T]: F:Formats pending permission requests and their resolutions. | R:- | A:- | S:- @@ -4390,7 +4391,7 @@ url.ts[SE4T]: F:Sanitizes URLs displayed by the TUI. | R:- | A:- | S:- ===//packages/tui/src/tui/shell/=== activity-line.ts[SE4M]: F:Defines activity phases and renders turn controls and status. | R:- | A:- | S:- chat-layout.ts[SE4L]: F:Defines chat surface types and computes viewport layout. | R:- | A:- | S:- -chrome.ts[SE4L]: F:Composes the shell chrome and exposes the welcome component. | R:- | A:- | S:- +chrome.ts[SU4L]: F:Composes TUI shell chrome, including localized lightweight-mode labels, and exports the welcome component. | R:code:packages/tui/src/tui/foundation/locale.ts | A:- | S:- composer.ts[SE4M]: F:Implements the TUI composer and defines its interaction modes and state. | R:- | A:- | S:- contracts.ts[SE4T]: F:Defines runtime status and shell state contracts. | R:- | A:- | S:- custom-status-text.ts[SE4T]: F:Renders custom terminal status lines. | R:- | A:- | S:- @@ -5800,7 +5801,7 @@ package-webui-npm.mjs[SE4M]: F:Packages the WebUI npm distribution. | R:- | A:- prepare-source-sync.mjs[SE4S]: F:Prepares an incoming public source synchronization. | R:- | A:- | S:- publish-cli-release.mjs[SE4T]: F:Publishes CLI release artifacts. | R:- | A:- | S:- release-cli.mjs[SE4T]: F:Coordinates the CLI release workflow. | R:- | A:- | S:- -run-vitest-suite.mjs[SE4T]: F:Runs a named declared Vitest suite. | R:- | A:- | S:- +run-vitest-suite.mjs[XQ4T]: F:Starts a declared Vitest suite with deterministic test settings. | R:code:test/vitest-suites.json | A:- | S:MCODE_TUI_LOCALE fixes TUI copy independently of the host ICU locale on Windows. run-webui-server.mjs[SE4M]: F:Starts the WebUI server for local verification. | R:- | A:- | S:- source-candidate.mjs[SE4T]: F:Validates an incoming source candidate. | R:- | A:- | S:- source-inventory.mjs[SE4M]: F:Generates and checks the public source inventory. | R:- | A:- | S:- @@ -5860,7 +5861,7 @@ network-deny.mjs[SE4T]: F:Provides test helpers that deny network access. | R:- offline-environment.mjs[SE4T]: F:Prepares an offline environment for verification. | R:- | A:- | S:- public-artifact.test.mjs[SE4T]: F:Checks the contents and contracts of public artifacts. | R:- | A:- | S:- smoke.test.mjs[SE4M]: F:Runs smoke checks for the public distribution. | R:- | A:- | S:- -source-sync.test.mjs[TV6L]: F:Tests source synchronization, public CI policies and release tooling. | R:code:scripts/lib/acceptance-records.mjs,code:.github/workflows/webui-ci.yml | A:- | S:The public workflow contract permits only WebUI checks and named provisioning steps, protects active main runs from cancellation, and prevents the baseline refresh from publishing. +source-sync.test.mjs[TV6L]: F:Tests source synchronization, CI policies, suite runner environment and release tooling. | R:code:scripts/run-vitest-suite.mjs,code:.github/workflows/webui-ci.yml | A:- | S:Runner tests fake the platform for startup logic but the child ICU locale still comes from the actual host. vitest-suites.json[FQ6L]: F:Declares the Vitest files every verification suite runs, per group. | R:- | A:- | S:A new Vitest file is registered in its group here; the Vitest config and the package scripts read this file instead of naming files themselves. windows-contract.test.mjs[SE4S]: F:Tests Windows-specific distribution and runtime contracts. | R:- | A:- | S:- diff --git a/docs/installation.md b/docs/installation.md index eaa64b2af..8dd804c2e 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -94,6 +94,9 @@ To locate data safely: For tests, explicitly set `MINIMAX_DATA_DIR` to a temporary directory to keep normal sessions separate. Use `$env:MINIMAX_DATA_DIR = 'C:\path\to\test-profile'` in PowerShell or `export MINIMAX_DATA_DIR=/path/to/test-profile` in a POSIX shell. +The TUI uses the host locale by default. Set `MCODE_TUI_LOCALE` to `en-US` or +`zh-CN` before starting the CLI to select its display language explicitly. + ## macOS terminal shortcuts: Ghostty Option+M In the composer, `Alt+M` (`Option+M` on macOS) cycles permission modes through Ask, Auto, and Full access. Its binding ID is `composer.cycle-permission`. `Shift+Tab` toggles **Plan mode**, a separate setting. You can also use `/permission` to choose a permission mode and `/permission status` to inspect it without an Option shortcut. diff --git a/packages/tui/src/tui/features/changelog/content.ts b/packages/tui/src/tui/features/changelog/content.ts index 0ea5902ea..fccf9f208 100644 --- a/packages/tui/src/tui/features/changelog/content.ts +++ b/packages/tui/src/tui/features/changelog/content.ts @@ -1,5 +1,6 @@ import { readFileSync } from 'node:fs'; import { getRuntimeLocaleLanguage } from '@mavis/shared/runtime-i18n'; +import { resolveTuiLocale } from '../../foundation/locale.js'; declare const __IS_NPM_BUILD__: boolean | undefined; @@ -22,7 +23,7 @@ export const TUI_CHANGELOG_URLS: Readonly> = { }; export function resolveTuiChangelogLanguage( - locale: string = resolveSystemLocale(), + locale = resolveTuiLocale(), ): TuiChangelogLanguage { return getRuntimeLocaleLanguage(locale) === 'zh' ? 'zh-CN' : 'en'; } @@ -124,11 +125,3 @@ function normalizeMarkdownInline(value: string): string { function escapeRegExp(value: string): string { return value.replace(/[.*+?^${}()|[\]\\]/gu, '\\$&'); } - -function resolveSystemLocale(): string { - try { - return Intl.DateTimeFormat().resolvedOptions().locale; - } catch { - return 'en'; - } -} diff --git a/packages/tui/src/tui/features/composer/copy.ts b/packages/tui/src/tui/features/composer/copy.ts index 5b8a2b132..be82f7aec 100644 --- a/packages/tui/src/tui/features/composer/copy.ts +++ b/packages/tui/src/tui/features/composer/copy.ts @@ -1,17 +1,10 @@ import { getRuntimeLocaleLanguage } from '@mavis/shared/runtime-i18n'; +import { resolveTuiLocale } from '../../foundation/locale.js'; import { COMPOSER_COPY, type ComposerCopyKey } from './copy.en.js'; import { ZH_HANS_COMPOSER_COPY } from './copy.zh-Hans.js'; -function resolveComposerLocale(): string { - try { - return Intl.DateTimeFormat().resolvedOptions().locale; - } catch { - return 'en'; - } -} - -export function composerText(key: ComposerCopyKey, locale = resolveComposerLocale()): string { +export function composerText(key: ComposerCopyKey, locale = resolveTuiLocale()): string { return getRuntimeLocaleLanguage(locale) === 'zh' ? ZH_HANS_COMPOSER_COPY[key] : COMPOSER_COPY[key]; diff --git a/packages/tui/src/tui/features/session-mutation/copy.ts b/packages/tui/src/tui/features/session-mutation/copy.ts index f322fc41a..978a1f004 100644 --- a/packages/tui/src/tui/features/session-mutation/copy.ts +++ b/packages/tui/src/tui/features/session-mutation/copy.ts @@ -1,4 +1,5 @@ import { getRuntimeLocaleLanguage } from '@mavis/shared/runtime-i18n'; +import { resolveTuiLocale } from '../../foundation/locale.js'; import { SESSION_HISTORY_COPY, @@ -10,13 +11,7 @@ import { ZH_HANS_SESSION_HISTORY_COPY, ZH_HANS_SESSION_MUTATION_COPY } from './c export type { SessionHistoryCopyKey } from './copy.en.js'; -export function sessionMutationLocale(): string { - try { - return Intl.DateTimeFormat().resolvedOptions().locale; - } catch { - return 'en'; - } -} +export { resolveTuiLocale as sessionMutationLocale }; function isChineseLocale(locale: string): boolean { return getRuntimeLocaleLanguage(locale) === 'zh'; @@ -24,14 +19,14 @@ function isChineseLocale(locale: string): boolean { export function sessionHistoryText( key: SessionHistoryCopyKey, - locale = sessionMutationLocale(), + locale = resolveTuiLocale(), ): string { return isChineseLocale(locale) ? ZH_HANS_SESSION_HISTORY_COPY[key] : SESSION_HISTORY_COPY[key]; } export function sessionMutationText( key: SessionMutationCopyKey, - locale = sessionMutationLocale(), + locale = resolveTuiLocale(), ): string { return isChineseLocale(locale) ? ZH_HANS_SESSION_MUTATION_COPY[key] : SESSION_MUTATION_COPY[key]; } @@ -39,7 +34,7 @@ export function sessionMutationText( export function sessionMutationTemplate( key: SessionMutationCopyKey, values: Readonly>, - locale = sessionMutationLocale(), + locale = resolveTuiLocale(), ): string { return Object.entries(values).reduce( (text, [name, value]) => text.replaceAll(`{${name}}`, String(value)), diff --git a/packages/tui/src/tui/features/settings/status-line-copy.ts b/packages/tui/src/tui/features/settings/status-line-copy.ts index 9ee787c42..ef2e99f8c 100644 --- a/packages/tui/src/tui/features/settings/status-line-copy.ts +++ b/packages/tui/src/tui/features/settings/status-line-copy.ts @@ -1,4 +1,5 @@ import { getRuntimeLocaleLanguage } from '@mavis/shared/runtime-i18n'; +import { resolveTuiLocale } from '../../foundation/locale.js'; import type { TuiStatusLineItem } from '../../shell/status-line-items.js'; const en = { @@ -58,7 +59,7 @@ const descriptions: Record, readonly [s function isChinese(locale?: string): boolean { return ( - getRuntimeLocaleLanguage(locale ?? Intl.DateTimeFormat().resolvedOptions().locale) === 'zh' + getRuntimeLocaleLanguage(locale ?? resolveTuiLocale()) === 'zh' ); } diff --git a/packages/tui/src/tui/foundation/locale.ts b/packages/tui/src/tui/foundation/locale.ts new file mode 100644 index 000000000..f2659d56a --- /dev/null +++ b/packages/tui/src/tui/foundation/locale.ts @@ -0,0 +1,4 @@ +export function resolveTuiLocale(): string { + const override = process.env.MCODE_TUI_LOCALE?.trim(); + return override || Intl.DateTimeFormat().resolvedOptions().locale; +} diff --git a/packages/tui/src/tui/shell/chrome.ts b/packages/tui/src/tui/shell/chrome.ts index e098be4ab..71f41d0ee 100644 --- a/packages/tui/src/tui/shell/chrome.ts +++ b/packages/tui/src/tui/shell/chrome.ts @@ -2,6 +2,7 @@ import type { TuiCustomStatusLineConfig } from '@mavis/config'; import { getRuntimeLocaleLanguage } from '@mavis/shared/runtime-i18n'; import { formatContextWindow } from '../../application/context-window.js'; import type { Component } from '../rendering/component.js'; +import { resolveTuiLocale } from '../foundation/locale.js'; import { stripAnsi, truncateToWidth, visibleWidth } from '../rendering/text.js'; import { formatTuiPermissionMode, @@ -391,7 +392,7 @@ function fitStatusSegments(segments: readonly StatusSegment[], width: number): s return fitLine(render(), width); } -function lightweightModeLabels(locale = Intl.DateTimeFormat().resolvedOptions().locale): string[] { +function lightweightModeLabels(locale = resolveTuiLocale()): string[] { return getRuntimeLocaleLanguage(locale) === 'zh' ? ['轻量模式', '轻量', '轻'] : ['Lightweight', 'Light', 'Lite']; diff --git a/packages/tui/test/unit/tui-status-line-items.test.ts b/packages/tui/test/unit/tui-status-line-items.test.ts index b0f844eb6..f6a2d5df5 100644 --- a/packages/tui/test/unit/tui-status-line-items.test.ts +++ b/packages/tui/test/unit/tui-status-line-items.test.ts @@ -89,9 +89,15 @@ describe('TuiStatusLine default items', () => { const locale = vi .spyOn(Intl.DateTimeFormat.prototype, 'resolvedOptions') .mockReturnValue({ locale: 'zh-CN' } as Intl.ResolvedDateTimeFormatOptions); + const previousOverride = process.env.MCODE_TUI_LOCALE; try { + delete process.env.MCODE_TUI_LOCALE; expect(stripAnsi(render({ ...BASE_STATE, lightweightMode: true }))).toContain('轻量模式'); + process.env.MCODE_TUI_LOCALE = 'en-US'; + expect(stripAnsi(render({ ...BASE_STATE, lightweightMode: true }))).toContain('Lightweight'); } finally { + if (previousOverride === undefined) delete process.env.MCODE_TUI_LOCALE; + else process.env.MCODE_TUI_LOCALE = previousOverride; locale.mockRestore(); } }); diff --git a/release/public-source.json b/release/public-source.json index 3d33a097d..3b24c1a1a 100644 --- a/release/public-source.json +++ b/release/public-source.json @@ -3588,6 +3588,7 @@ "packages/tui/src/tui/features/transcript/panel.ts", "packages/tui/src/tui/features/update/panel.ts", "packages/tui/src/tui/foundation/bordered-table.ts", + "packages/tui/src/tui/foundation/locale.ts", "packages/tui/src/tui/goal-composition.ts", "packages/tui/src/tui/interaction/permission.ts", "packages/tui/src/tui/interaction/questionnaire.ts", diff --git a/scripts/run-vitest-suite.mjs b/scripts/run-vitest-suite.mjs index 4d4fc06d1..d68beec0d 100644 --- a/scripts/run-vitest-suite.mjs +++ b/scripts/run-vitest-suite.mjs @@ -24,6 +24,7 @@ environment.LANG = "C"; environment.LANGUAGE = "C"; environment.LC_ALL = "C"; environment.LC_MESSAGES = "C"; +environment.MCODE_TUI_LOCALE = "en-US"; if (process.platform === "win32") { environment.TEMP = environment.TMP = realpathSync.native(tmpdir()); } diff --git a/test/source-sync.test.mjs b/test/source-sync.test.mjs index c9e8fa221..204e72351 100644 --- a/test/source-sync.test.mjs +++ b/test/source-sync.test.mjs @@ -1269,7 +1269,16 @@ test('suite runner pins its locale, preserves gate arguments and canonicalizes W copyFileSync(new URL(`../${file}`, import.meta.url), path.join(root, file)); writeFileSync(path.join(root, 'test/vitest-suites.json'), JSON.stringify({ suites: { fixture: ['test/example.test.ts'] } })); writeFileSync(path.join(root, 'node_modules/vitest/package.json'), JSON.stringify({ bin: { vitest: 'cli.cjs' } })); - writeFileSync(path.join(root, 'node_modules/vitest/cli.cjs'), 'console.log(JSON.stringify({args:process.argv.slice(2),temp:process.env.TEMP,tmp:process.env.TMP,cwd:process.cwd(),lang:process.env.LANG,language:process.env.LANGUAGE,lcAll:process.env.LC_ALL,lcMessages:process.env.LC_MESSAGES,locale:Intl.DateTimeFormat().resolvedOptions().locale})); process.exit(17);'); + writeFileSync(path.join(root, 'node_modules/vitest/cli.cjs'), ` + console.log(JSON.stringify({ + args: process.argv.slice(2), temp: process.env.TEMP, tmp: process.env.TMP, + cwd: process.cwd(), lang: process.env.LANG, language: process.env.LANGUAGE, + lcAll: process.env.LC_ALL, lcMessages: process.env.LC_MESSAGES, + locale: Intl.DateTimeFormat().resolvedOptions().locale, + tuiLocale: process.env.MCODE_TUI_LOCALE, + })); + process.exit(17); + `); const alias = path.join(root, 'temporary-alias'); symlinkSync(path.join(root, 'temporary'), alias, process.platform === 'win32' ? 'junction' : 'dir'); for (const platform of ['linux', 'darwin', 'win32']) { @@ -1283,6 +1292,7 @@ test('suite runner pins its locale, preserves gate arguments and canonicalizes W LANGUAGE: 'zh_CN:zh', LC_ALL: 'zh_CN.UTF-8', LC_MESSAGES: 'zh_CN.UTF-8', + MCODE_TUI_LOCALE: 'zh-CN', TEMP: alias, TMP: alias, TMPDIR: alias, @@ -1290,6 +1300,7 @@ test('suite runner pins its locale, preserves gate arguments and canonicalizes W }); assert.equal(result.status, 17, result.stderr); const child = JSON.parse(result.stdout); + assert.equal(child.tuiLocale, 'en-US'); assert.deepEqual(child.args, ['run', '--config', 'vitest.oss.config.mjs', ...(platform === 'win32' ? ['--maxWorkers', '1'] : []), 'test/example.test.ts']); assert.equal(realpathSync(child.cwd), realpathSync(root));