Skip to content

[i18n] Show backend messages in the CLI's language (issues#3157) - #59

Merged
btopro merged 1 commit into
mainfrom
i18n/3157-api-messages
Oct 19, 2026
Merged

btopro merged 1 commit into
mainfrom
i18n/3157-api-messages

Conversation

@btopro

@btopro btopro commented Oct 19, 2026

Copy link
Copy Markdown
Member

Part of haxtheweb/issues#3157. Merge last. It needs a haxcms-nodejs release that has dist/lib/apiMessageCodes.js and bundles the webcomponents build with haxcms-elements/locales/haxcms-api.*.json (haxtheweb/webcomponents#883). Until then it is a safe no-op: you get the English messages, as now.

What it touches

  • src/lib/api-messages.js (new):
    • apiMessage(body, fallback) translates by code using the locale files bundled with haxcms-nodejs (bundledElementLocales('haxcms-elements')), the same text the editor shows. Otherwise it falls back to the server's English message.
    • annotateApiBody() adds codes to bodies from routes the CLI calls in-process (invokeRoute), using haxcms-nodejs's own matcher.
  • src/lib/i18n.js:
    • translateOnly(): returns the current language's text or null, so callers can keep more specific English.
    • hasNamespace().
  • site.js:
    • node:add failures show the translated reason.
    • Site export failures now print t('siteExportFailed', {reason}) instead of an English log line holding raw JSON.
    • Import failures used to be silent and leave an empty site. They now warn: t('siteImportFailed', {source, reason}).
  • Two new strings (siteExportFailed, siteImportFailed) in all 102 languages. They pass the coverage test and validate_lang.

Tests

  • test/unit/api-messages.test.cjs: envelope shapes, English vs. translated, missing params, unknown codes, and the annotate no-op with an older haxcms-nodejs.
  • Full npm test: 380 pass, 0 fail.

Generated by Claude Code

…3157)

haxcms-nodejs responses now carry a `code` and `params` next to their
English message. The CLI translates them with the same
locales/haxcms-api.<lang>.json files the editor uses (bundled with
haxcms-nodejs), and falls back to the server's English message.

- src/lib/api-messages.js: apiMessage(body, fallback) and
  annotateApiBody(), which adds codes to bodies from routes the CLI calls
  in-process when the installed haxcms-nodejs supports them (no-op before).
- i18n.js: translateOnly() (a translation in the current language, or null
  so callers can keep more specific English) and hasNamespace().
- site.js: node:add failures, site export failures and import failures use
  the translated message. Import failures used to be silent and leave an
  empty site; they now warn with the reason.
- Two new strings (siteExportFailed, siteImportFailed) in all 102 languages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EN4mJgNh8uj2C44jDs4KAD
Copilot AI balanced review requested due to automatic review settings October 19, 2026 17:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@btopro
btopro merged commit 71c9566 into main Oct 19, 2026
6 checks passed
@btopro
btopro deleted the i18n/3157-api-messages branch October 19, 2026 17:55
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 19, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants