Skip to content

Commit 7055ed5

Browse files
LZY3538steipete
andauthored
fix(wizard): honor process locale when overrides are blank (#111076)
* fix(wizard): ignore blank locale env overrides * test(wizard): cover locale fallback chain * docs(wizard): document locale env precedence --------- Co-authored-by: Peter Steinberger <[email protected]>
1 parent ba62b94 commit 7055ed5

5 files changed

Lines changed: 36 additions & 7 deletions

File tree

‎docs/cli/onboard.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ openclaw onboard --reset --reset-scope full
179179

180180
## Locale
181181

182-
Interactive onboarding uses the CLI wizard locale for fixed setup copy. Resolve order:
182+
Interactive onboarding uses the CLI wizard locale for fixed setup copy. It uses the first nonblank value in this order:
183183

184184
1. `OPENCLAW_LOCALE`
185185
2. `LC_ALL`
@@ -191,6 +191,7 @@ Supported wizard locales are `en`, `zh-CN`, and `zh-TW`. Locale values may use u
191191

192192
```bash
193193
OPENCLAW_LOCALE=zh-CN openclaw onboard
194+
OPENCLAW_LOCALE=en openclaw onboard # Explicit English override
194195
```
195196

196197
## Non-interactive setup

‎docs/plugins/sdk-setup.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ For hot setup-only paths, prefer the narrow setup helper seams over the broader
351351

352352
Use the broader `plugin-sdk/setup` seam when you want the full shared setup toolbox, including config-patch helpers such as `moveSingleAccountChannelSectionToDefaultAccount(...)`.
353353

354-
Use `createSetupTranslator(...)` for fixed setup wizard copy. It follows the CLI wizard locale (`OPENCLAW_LOCALE`, then system locale variables) and falls back to English. Keep plugin-specific setup text in plugin-owned code and use shared catalog keys only for common setup labels, status text, and official bundled plugin setup copy.
354+
Use `createSetupTranslator(...)` for fixed setup wizard copy. It uses the first nonblank value from `OPENCLAW_LOCALE`, `LC_ALL`, `LC_MESSAGES`, and `LANG`, in that order, then falls back to English. Set `OPENCLAW_LOCALE=en` for an explicit English override. Keep plugin-specific setup text in plugin-owned code and use shared catalog keys only for common setup labels, status text, and official bundled plugin setup copy.
355355

356356
The setup patch adapters stay hot-path safe on import. Their bundled single-account promotion contract-surface lookup is lazy, so importing `plugin-sdk/setup-runtime` does not eagerly load bundled contract-surface discovery before the adapter is actually used.
357357

‎docs/start/wizard.md‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,13 @@ the browser through the Control UI. Docs: [Dashboard](/web/dashboard).
3838

3939
## Locale
4040

41-
The wizard localizes fixed onboarding copy. Resolve order: `OPENCLAW_LOCALE`,
42-
`LC_ALL`, `LC_MESSAGES`, `LANG`, then English. Supported locales: `en`,
43-
`zh-CN`, `zh-TW`.
41+
The wizard localizes fixed onboarding copy. It uses the first nonblank value from
42+
`OPENCLAW_LOCALE`, `LC_ALL`, `LC_MESSAGES`, and `LANG`, in that order, then
43+
falls back to English. Supported locales: `en`, `zh-CN`, `zh-TW`.
4444

4545
```bash
4646
OPENCLAW_LOCALE=zh-CN openclaw onboard
47+
OPENCLAW_LOCALE=en openclaw onboard # Explicit English override
4748
```
4849

4950
Product names, commands, config keys, URLs, provider IDs, model IDs, and

‎src/wizard/i18n/index.test.ts‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,36 @@ describe("wizard i18n", () => {
3636
});
3737

3838
it("uses OPENCLAW_LOCALE before process locale variables", () => {
39-
vi.stubEnv("OPENCLAW_LOCALE", "zh-TW");
39+
vi.stubEnv("OPENCLAW_LOCALE", "en");
4040
vi.stubEnv("LC_ALL", "zh-CN");
41+
vi.stubEnv("LANG", "zh-TW");
42+
expect(t("wizard.gateway.port")).toBe("Gateway port");
43+
});
44+
45+
it("ignores blank locale overrides when a process locale is available", () => {
46+
vi.stubEnv("OPENCLAW_LOCALE", " ");
47+
vi.stubEnv("LC_ALL", "");
48+
vi.stubEnv("LC_MESSAGES", "zh-CN");
4149
vi.stubEnv("LANG", "en-US");
50+
expect(t("wizard.gateway.port")).toBe("Gateway 端口");
51+
});
52+
53+
it("continues through a blank LC_MESSAGES value to LANG", () => {
54+
vi.stubEnv("OPENCLAW_LOCALE", "");
55+
vi.stubEnv("LC_ALL", " ");
56+
vi.stubEnv("LC_MESSAGES", "\t");
57+
vi.stubEnv("LANG", "zh-TW");
4258
expect(t("wizard.gateway.port")).toBe("Gateway 連接埠");
4359
});
4460

61+
it("uses English when every locale variable is blank", () => {
62+
vi.stubEnv("OPENCLAW_LOCALE", " ");
63+
vi.stubEnv("LC_ALL", "");
64+
vi.stubEnv("LC_MESSAGES", "\t");
65+
vi.stubEnv("LANG", " ");
66+
expect(t("wizard.gateway.port")).toBe("Gateway port");
67+
});
68+
4569
it("falls back to English and interpolates params", () => {
4670
expect(t("wizard.gateway.port", undefined, { locale: "zh-CN" })).toBe("Gateway 端口");
4771
expect(t("wizard.gateway.missing", undefined, { locale: "zh-CN" })).toBe(

‎src/wizard/i18n/index.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ function resolveWizardLocale(value: string | undefined): WizardLocale {
4949
}
5050

5151
function resolveWizardLocaleFromEnv(env: NodeJS.ProcessEnv = process.env): WizardLocale {
52-
return resolveWizardLocale(env.OPENCLAW_LOCALE ?? env.LC_ALL ?? env.LC_MESSAGES ?? env.LANG);
52+
const locale = [env.OPENCLAW_LOCALE, env.LC_ALL, env.LC_MESSAGES, env.LANG].find((value) =>
53+
value?.trim(),
54+
);
55+
return resolveWizardLocale(locale);
5356
}
5457

5558
function readKey(map: WizardTranslationMap, key: string): string | undefined {

0 commit comments

Comments
 (0)