Skip to content

[i18n] Translate backend messages by code (issues#3157) - #883

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

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

Conversation

@btopro

@btopro btopro commented Oct 19, 2026

Copy link
Copy Markdown
Member

Part of haxtheweb/issues#3157. Merge this one first: it holds the shared code list the backend PRs copy. It also works on its own with today's backends (no codes yet → the English message is shown as before, and the registry fix below already helps).

What it touches

  • haxcms-elements/lib/haxcms-api-codes.json (new, source of truth): 117 message codes, each with English text and the patterns the backends use to recognise the messages they already send (named groups become params, e.g. {maxMb}). Covers 1,166 of the 1,171 response messages surveyed across both backends.
  • haxcms-elements/locales/haxcms-api.<lang>.json: 102 languages, plus the manifest entry.
  • haxcms-elements/lib/core/utils/HAXCMSApiMessages.js (new): haxcmsApiMessage(response, fallback).
    • The user's language has a translation → show it.
    • English, or no translation, or a param is missing → show the server's English message, which is often more specific (it names the page or route).
    • Also exposed as globalThis.haxcmsApiMessage for hax-body, which can't import haxcms-elements.
  • Used in: site editor request errors and page details, files dialog, file actions (hax-upload-field), Excel import, archive export, app-hax site actions, site creation errors, system settings.
  • micro-frontend-registry fix: error results only read a top-level message, but both backends put it in data.message (or data.error), so most backend error text never reached people. It now reads those and keeps code/params.
  • AppHaxBackendAPI: hard-denial detection uses ACCESS_DENIED / USER_TOKEN_REQUIRED, keeping the English list for older backends. Because of the registry fix, these denials are actually detected now. Before, they always went down the token-refresh path.
  • Editor _responseStatusText: the backend message now wins over an HTTP reason phrase like "Bad Request" (the direct-fetch path set statusText from HTTP, which hid the real message).

Tests

  • New haxcms-elements/test/haxcms-api-messages.test.js:
    • English text matches the locale file and the code list.
    • Every translation has all keys and the same placeholders.
    • Response shapes, translation vs. English fallback, missing params.
  • micro-frontend-registry tests cover the envelope message and code.
  • Locally, app-hax + haxcms-elements + upload tests pass: 1,289 tests across 36 files.

Translation confidence

Lower confidence; worth a native speaker's look: co, eu, fo, fy, ga, gn, ha, haw, ig, jv, km, kn, ku, ky, lb, lo, mi, ml, my, ny, om, pa, pnb, ps, qu, sd, si, sn, so, tg, tk, tt, wuu, xh, yi, yo, zu.

Related PRs, in merge order

  1. this PR
  2. haxcms-nodejs and haxcms-php: send the codes (either order)
  3. create: shows translated messages in the CLI. Needs a haxcms-nodejs release that bundles this build.

Generated by Claude Code

Both HAXcms backends now send a `code` and `params` next to their English
message. This adds the shared code list and the front-end side:

- haxcms-elements/lib/haxcms-api-codes.json: the shared list (117 codes,
  English text, and the patterns the backends use to recognise their own
  messages). haxcms-nodejs and haxcms-php keep copies of this file.
- locales/haxcms-api.<lang>.json in 102 languages, plus the manifest entry.
- lib/core/utils/HAXCMSApiMessages.js: haxcmsApiMessage(response, fallback)
  shows the translation for the code in the user's language, or the
  server's English message (more specific) when English is in use or there
  is no translation. Also exposed as globalThis.haxcmsApiMessage for
  hax-body, which can't import haxcms-elements.
- Used by the site editor (request errors, page details), files dialog,
  file actions, Excel import, archive export, app-hax site actions and site
  creation, and system settings.
- micro-frontend-registry: error results now carry the backend message from
  data.message / data.error (both backends put it there) and its code;
  before, only a top-level message was read, so most error text was lost.
- AppHaxBackendAPI: hard-denial detection uses the code, keeping the
  English list for older backends.

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
@vercel

vercel Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
webcomponents Error Error Oct 19, 2026 5:30pm UTC

Request Review

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.

This branch had an error being deployed

1 failed deployment
Preview — 7978d4c4 Deployed Oct 19, 2026 by vercel[bot]
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