Skip to content

fix(i18n): translate announce() live-region strings - #4920

Merged
nynexman4464 merged 4 commits into
mainfrom
nynexman4464/fix/i18n-announce-strings
Aug 17, 2026
Merged

nynexman4464 merged 4 commits into
mainfrom
nynexman4464/fix/i18n-announce-strings

Conversation

@nynexman4464

@nynexman4464 nynexman4464 commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Finishes the announce() half of the i18n sweep started in #4387.

What changed

  • Live-region announcements are localizable. Every hardcoded English string passed to announce() in packages/core now resolves through the message catalog: selection counts, search result counts, empty-search results, file selections, token add/remove, and Lightbox position. Under an InternationalizationProvider these were the last part of the UI still speaking English.
  • Counts are ICU plurals, not ${n} result${n === 1 ? '' : 's'}. A JS-side plural carries only the two English forms and cannot be translated at all; the new keys follow the shape already established by @astryx.commandPalette.resultCount. FileInput's two shapes ("1 file selected: " vs "N files selected") fold into a single message with an ICU =1 branch, because naming the file is an exactly-one case rather than a plural category.
  • One key per component, per the existing convention (duplicate English across components stays duplicated), each with a translator description noting that it is live-region text and never visible on screen.
  • The temporary allowedCalleeStrings allowlist is gone. It was added alongside the check in lint: flag hardcoded strings passed to announce() #4387 with a note to delete it once the sweep landed; 'Copied' had already gone stale when CodeBlock migrated.
  • The lint rule no longer misses the interesting shapes. Its call-argument branch hand-rolled literal detection and only recognized a bare string or an expression-free template, so announce(cond ? 'A' : 'B') and announce(`${n} results`) — exactly what these announcements looked like — were never flagged. It now reuses reportUserFacingLiteralsIn, the same walk the aria-label path uses. That is the last commit and can be dropped on its own if reviewers would rather land it separately.

Verification

  • Live-region tests assert against strings the test itself supplies, via an InternationalizationProvider overrides entry — the pattern the suite already used elsewhere. No assertion depends on a catalog, so each one proves the component looked up that key, passed those arguments, and let the resolver format the result. Count messages keep their ICU plural in the override, so the singular and plural branches are each still asserted, and FileInput's =1 branch is asserted to name the file where its other branch is asserted not to.
  • Confirmed red by reverting the source fix: 8 failures in MultiSelector and 3 in FileInput, of the form expected '1 of 3 selected' to be '1 sur 3 sélectionnés'. All 454 tests across the six suites and the i18n suites pass with the fix in place.
  • With the sweep applied, the widened rule reports no violations in packages/core/src. Run against unmodified main it flags exactly the sites this PR fixes — nothing further to scope.
  • One known blind spot remains, unrelated to this change: the walk does not descend into a template's interpolated expressions, so a conditional nested inside a template (Typeahead's old ${n} ${n === 1 ? 'result' : 'results'}) is still invisible to the rule. It is fixed here by hand.

@vercel

vercel Bot commented Aug 11, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
astryx Ready Ready Preview Aug 17, 2026 10:42pm

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 11, 2026
@github-actions

github-actions Bot commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

🧪 Sandbox Preview

View Sandbox for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

Modified Components

FileInput (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 651 -
Complexity N/A Very High (102) -
Lightbox (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 637 -
Complexity N/A Very High (83) -
MultiSelector (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 1460 -
Complexity N/A Very High (183) -
Selector (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 1502 -
Complexity N/A Very High (156) -
Tokenizer (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 671 -
Complexity N/A Very High (102) -
Typeahead (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 1131 -
Complexity N/A Very High (161) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.8KB 1.2KB

Accessibility Audit

Status: 2 accessibility violation(s) found — 2 serious.

FileInput - 1 issue(s)
  • 🟠 serious: Ensure the contrast between foreground and background colors meets WCAG 2 AA minimum contrast ratio thresholds
    • Rule: color-contrast · Affects 3/15 stories · Learn more
    • WCAG: 1.4.3 (Level AA)
Tokenizer - 1 issue(s)
  • 🟠 serious: Ensure the contrast between foreground and background colors meets WCAG 2 AA minimum contrast ratio thresholds
    • Rule: color-contrast · Affects 2/21 stories · Learn more
    • WCAG: 1.4.3 (Level AA)

Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

MultiSelector, Selector, Typeahead, FileInput, Tokenizer and Lightbox
passed hardcoded English to announce(), so their live-region text stayed
English under an InternationalizationProvider. Route every user-facing
announcement through t() with a per-component catalog key.

Counts are ICU plurals now, not `${n} result${n === 1 ? '' : 's'}`:
a JS-side plural only has the two English forms and cannot be
translated. FileInput's two shapes ("1 file selected: <name>" vs
"N files selected") fold into one message with an ICU `=1` branch,
since naming the file is an exactly-one case, not a plural category.

Live-region assertions now resolve their expected text from the shipped
catalog, and MultiSelector, Typeahead and FileInput each gain a
pseudo-locale test that fails if an announcement is hardcoded again.
no-hardcoded-i18n-string carried three grandfathered strings while the
i18n sweep ran. All three are gone from the codebase now ('Copied' with
the CodeBlock migration, the other two with the previous commit), so the
exemption has nothing left to exempt.
The call-argument branch hand-rolled its literal detection and only
recognized a bare string or an expression-free template, so
announce(cond ? 'A' : 'B') and announce(`${n} results`) — the shapes the
hardcoded announcements actually took — were never flagged. It now
reuses reportUserFacingLiteralsIn, the walk the aria-label path already
uses, which covers ternaries, ?? / || fallbacks and template chunks.

Kept separate from the sweep so it can be dropped on its own.
The announce() tests added with this PR resolved their expected text from
the same catalog the component reads. `enMessage('@astryx.multiSelector.
selectionCleared')` is literally 'Selection cleared', so those assertions
passed against hardcoded English too — they proved the arguments were
wired, not that anything was localized. The pseudo-locale twins did prove
resolution, but only because the vitest global setup generates
locales/pseudo.json, a gitignored build artifact.

Use the pattern the suite already had: render inside an
InternationalizationProvider whose `overrides` supply the expected string,
then assert that string. The assertion then depends on no catalog, and it
proves the component looked up that key, passed those arguments, and let
the resolver format the result.

Count messages keep their ICU plural in the override, so the singular and
plural branches are still each asserted; FileInput's `=1` branch names the
file and its `other` branch is asserted not to. Announcement presence and
absence checks (announce('') clearing, "does not announce until the user
searches") involve no catalog and are unchanged.

Both local helpers, and the en.json / pseudo.json / IntlMessageFormat
imports they needed, are gone.
@nynexman4464
nynexman4464 force-pushed the nynexman4464/fix/i18n-announce-strings branch from 363bb2c to 785e01e Compare August 17, 2026 22:38
@nynexman4464
nynexman4464 marked this pull request as ready for review August 17, 2026 22:38
github-actions Bot added a commit that referenced this pull request Aug 17, 2026
@nynexman4464
nynexman4464 merged commit 84ceb39 into main Aug 17, 2026
21 of 22 checks passed
@github-actions
github-actions Bot deleted the nynexman4464/fix/i18n-announce-strings branch August 18, 2026 06:11

This branch was successfully deployed

1 active deployment
Preview — 785e01e9 Deployed Aug 17, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant