Skip to content

fix(@inquirer/i18n): let the user theme override locale defaults - #2371

Merged
SBoudrias merged 2 commits into
SBoudrias:mainfrom
NgoQuocViet2001:fix-i18n-theme-precedence
Oct 31, 2026
Merged

SBoudrias merged 2 commits into
SBoudrias:mainfrom
NgoQuocViet2001:fix-i18n-theme-precedence

Conversation

@NgoQuocViet2001

Copy link
Copy Markdown
Contributor

The localized select, checkbox, search, editor and password wrappers called makeTheme(config.theme, { style: { ...locale } }), so the locale strings were merged last and replaced what the user passed. With @inquirer/i18n/zh (or the root import under a non-English locale), keysHelpTip: () => undefined no longer hides the help line, a custom keysHelpTip formatter is never called, and maskedText, waitingMessage and loadingMessage are ignored. The same code works with @inquirer/prompts and the en locale.

password({ message: 'pw', theme: { style: { maskedText: '[hidden]' } } });
// before: ? pw [输入已隐藏]
// after:  ? pw [hidden]

This merges the locale strings first and config.theme second, so they act as defaults. Keys the user does not set stay localized (the zh password help line is still ctrl+t 切换可见性). A custom keysHelpTip receives the English labels, as it does with @inquirer/prompts; if you'd rather pass it the translated labels, I can switch to that. I left confirm as is; its keywords could get the same treatment if wanted.

  • Ran: yarn vitest --run packages/i18n (67 passed; the 2 new tests fail on main), yarn vitest --run packages (539 passed, 1 skipped)
  • Ran: yarn tsc, yarn oxlint ., yarn eslint ., yarn oxfmt --check packages/i18n, all clean

The localized select, checkbox, search, editor and password wrappers
merged the locale strings after `config.theme`, so a user's
`keysHelpTip`, `maskedText`, `waitingMessage` or `loadingMessage` was
replaced by the locale one. Merge the locale strings first so they act
as defaults, matching how `@inquirer/prompts` honors the theme.
@codecov

codecov Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.48936% with 4 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@34d7d36). Learn more about missing BASE report.

Files with missing lines Patch % Lines
packages/i18n/src/create.ts 91.48% 4 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2371   +/-   ##
=======================================
  Coverage        ?   94.89%           
=======================================
  Files           ?       48           
  Lines           ?     2430           
  Branches        ?      645           
=======================================
  Hits            ?     2306           
  Misses          ?      123           
  Partials        ?        1           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

…bels

- confirm: locale keywords are defaults, config.theme overrides them
- keysHelpTip: custom formatters now receive the translated labels
  (the user formatter, or the built-in layout when none is given);
  returning undefined still hides the help line
- docs: document the theme/locale split, fix the custom-locale example
  (missing invalidAnswer and helpToggle)

@SBoudrias SBoudrias left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@SBoudrias
SBoudrias merged commit 967430c into SBoudrias:main Oct 31, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants