Skip to content

fix(i18n): catch formatter returns and localize helper text - #7849

Merged
nynexman4464 merged 6 commits into
mainfrom
fix/i18n-formatter-returns
Oct 28, 2026
Merged

nynexman4464 merged 6 commits into
mainfrom
fix/i18n-formatter-returns

Conversation

@nynexman4464

@nynexman4464 nynexman4464 commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

User impact

Pasted-text counts, file-size validation limits, and keyboard shortcut names could stay in English under a non-English provider. Their helper returns also bypassed the hardcoded-string lint rule.

Problem and solution fit

The rule checked text props and announcements but not named text-formatting helpers. That let constructed English escape the catalog, preventing applications from localizing system-owned text. Check those helper returns and move the remaining text into the canonical catalog.

Expected behavior and authority

Internationalization INV1a requires catalog-backed system text and ICU messages for runtime-varying text. INV3 and INV4 require deterministic English fallback and live provider updates.

Smallest restoration

  • Recognize format* and get*String/Text/Label/Message returns, including arrows, methods, class fields, assignments, and conventional memo/callback wrappers. Walk templates, concatenation, fallbacks, and TypeScript assertions without tracing identifiers or descending into unrelated callbacks.
  • Exclude obvious CSS/SVG serializers and punctuation-only fragments. Text-bearing suffixes such as formatColorLabel remain checked.
  • Catalog-back count, file-size, and shortcut text, preserving English output, binary size thresholds, key aliases, glyphs, and unknown caller-supplied key behavior. The count message supports exact single-line selection and translated character plurals; file-size messages keep one decimal through the supported .0 number skeleton.

No public props, styling, layout, interaction, or translation-runtime changes. New keys fall back to English until translated.

Evidence

  • Reproduction before the change: the new formatter regression failed with zero diagnostics; 20 localization assertions failed against the original component implementations.
  • Result after the change: 81 RuleTester cases and 139 tests across five UI suites pass.
  • Rule-only audit of all 673 tracked production TypeScript files in the existing core/richtext scopes, with the configured theme/i18n exclusions: 7 findings on main b0981237 → 0 on this branch.
  • Representative unchanged paths: empty/single/multiline English counts; byte/KB/MB threshold and fixed-precision messages; Mac/non-Mac shortcuts, aliases, glyphs, unknown keys, and ARIA precedence.
  • Regression proof: provider overrides supply different words/order; locale rerenders restore English; a 21-line Russian case cannot take the exact-one-line branch. CSS serializer and punctuation negatives prevent audit noise.

Scope

  • One defect is restored: system text escaping the formatter/catalog boundary.
  • Separable contradictory or unsettled tagalongs were removed or split.
  • No new public API, visual representation, default, or interaction model is hidden under the bug-fix label.
  • Public text and artifacts contain no internal Meta context.

Testing

node internal/eslint-plugin-astryx/no-hardcoded-i18n-string.test.mjs
pnpm exec vitest run --project ui \
  packages/core/src/Chat/ChatPastedTextToken.test.tsx \
  packages/core/src/FileInput/FileInput.test.tsx \
  packages/core/src/FileInput/FileInput.fr10.test.tsx \
  packages/core/src/Kbd/Kbd.test.tsx \
  packages/core/src/i18n/useTranslator.test.tsx --maxWorkers=4
pnpm check:i18n-catalog
pnpm check:i18n-runtime
pnpm check:knowledge
pnpm check:changesets

Focused ESLint: no errors or i18n findings; the existing unused BaseProps import warning in FileInput is unchanged. Full CI and real-browser verification are not claimed by this draft. No pixels, focus, or interaction logic changed.

CSS serializer regression follow-up (2026-10-27)

The rebase exposed two formatter-return false positives in motion CSS serializers: format() returns a px chunk and formatMotionRoleValue() returns an s chunk. The rule now skips only px/s/ms/deg-only template chunks after interpolations, and only on formatter returns. Prose such as s remaining, seconds remaining, and in, plain string returns, and announcement checks remain enforced. No motion code changed.

  • 92 RuleTester cases pass, including both actual serializer shapes and positive cases that defend the English-text checks.
  • Rule-only audit using the corrected rule against current main b8fd8615 and this PR: 736 tracked production files; main 7 findings, PR 0 findings. The original three component findings remain detectable; neither motion serializer is flagged.
  • Repository checks and full strict ESLint over 6,694 tracked source files pass with 0 errors. Fresh CI is rerunning on the corrected head eaec231e.

Review suggestions follow-up

The CSS-unit exemption now requires the unit immediately after an interpolation. Space-separated display text such as ${n} s or ${n} ms is checked, while both motion serializers remain exempt. The changeset now explicitly covers translated Ctrl/Esc keycaps and provider-locale file-size digits.

  • 96 RuleTester cases and 139 UI tests pass.
  • Audit against main 6b96fc3e: 738 production files, 7 real findings; this PR's 736 production files, 0 findings.
  • Full strict lint and fresh CI/review are rerunning on e928b97a before merge.

@vercel

vercel Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
astryx Ready Ready Preview Oct 27, 2026 11:26pm UTC

Request Review

@astracat-bot

astracat-bot Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Oct 27, 2026, 11:51 PM UTC

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

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

Previews ready: Storybook and Sandbox were built with this PR's docsite. CI evidence will be added when available.

View Storybook for this PR · View Sandbox for this PR

@nynexman4464
nynexman4464 marked this pull request as ready for review October 22, 2026 15:22

@astracat-bot astracat-bot Bot 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.

Recommending approval: the pasted-text count, file-size limit and keyboard-shortcut text now come from the catalog with English output unchanged, and the lint extension catches exactly the helper returns this PR fixes. Nothing is required before merge; optionally, the changeset could mention that the visible Ctrl/Esc keycaps are translatable too, and that file-size digits now follow the provider locale (for example 1,5 KB under de) even before translations exist.

[Automated review]

@astracat-bot astracat-bot Bot 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.

Requesting changes: the catalog changes for Kbd, the pasted-text count and FileInput keep English output unchanged and look right, but the extended lint rule now fails CI's Lint job on this branch. Its new formatter-return check flags two CSS serializers that landed on main after this branch's original base: format() in packages/core/src/motion/animator.ts (line 551) and formatMotionRoleValue() in packages/core/src/motion/roleValue.ts (line 90). Please have the rule skip CSS value fragments such as px and s (or rename or annotate those two helpers), then rerun the rule-only audit against the current main.

[Automated review]

}
// These names describe CSS output, not interface copy. A text-sink suffix
// still wins: formatColorLabel is not a color serializer.
return !/(?:CSS|Css|Style|Styles|Color|Shadow|Transform|Gradient|Length|Angle|RGB|Rgb|HSL|Hsl|Hex|Transition|Font|Border|GridTemplate|ClassName|MediaQuery|Selector|Path)(?:String|Value)?$/.test(

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.

This exclusion misses the two CSS serializers now on main: format() in packages/core/src/motion/animator.ts (line 551, "px ") and formatMotionRoleValue() in packages/core/src/motion/roleValue.ts (line 90, "s "). CI's Lint job fails with exactly those two errors. Skipping CSS unit fragments such as px, s, ms and deg, or renaming or annotating those two helpers, would clear it.

@astracat-bot astracat-bot Bot 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.

Recommending approval: the pasted-text count, file-size limit and keyboard-shortcut text now come from the catalog with English output unchanged, and the extended lint rule is clean on current main. One optional follow-up: the unit-chunk exemption in no-hardcoded-i18n-string.js also matches a leading space, so a formatter returning ${n} s or ${n} ms (display text, not CSS) slips past the new check, and dropping the leading \s* keeps both motion serializers exempt. The changeset could also mention that the visible Ctrl/Esc keycaps become translatable and that file-size digits follow the provider locale (for example 1,5 KB under German) before any translation exists.

[Automated review]

const raw = quasi.value?.cooked ?? quasi.value?.raw ?? '';
// A unit following an interpolation is CSS, not English prose. Keep
// this formatter-only and do not exempt chunks like "s remaining".
if (opts.requireEnglish && index > 0 && /^\s*(?:px|s|ms|deg)\s*$/.test(raw)) {

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.

Optional: the leading \s* isn't needed for the two motion serializers (their chunks are px and s ), but it also exempts space-separated units such as ${n} s or ${n} ms returned by a formatter. Those are display text rather than CSS, since CSS never puts a space between a number and its unit. Dropping it keeps both serializers exempt:

if (opts.requireEnglish && index > 0 && /^(?:px|s|ms|deg)\s*$/.test(raw)) {

@astracat-bot astracat-bot Bot 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.

Incremental review of eaec231..e928b97; prior findings carried: user_impact

Recommending approval: the CSS-unit exemption in no-hardcoded-i18n-string.js now skips only a unit that starts right at an interpolation, so formatters returning display units such as ${n} s or ${n} ms are flagged again while both motion serializers stay exempt, and the changeset now describes the translatable Ctrl/Esc keycaps and the provider-locale file-size digits. The rule stays clean on this branch merged with current main, and nothing else is needed before merge.

[Automated review]

@astracat-bot astracat-bot Bot 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.

Recommending approval: the pasted-text count, file-size limit and keyboard-shortcut text now come from the catalog with English output unchanged, and the extended lint rule catches the helper returns this PR rewrites while staying clean at this head. Nothing is required before merge.

[Automated review]

@nynexman4464
nynexman4464 merged commit c86dc62 into main Oct 28, 2026
74 checks passed
vjeux added a commit to vjeux/astryx that referenced this pull request Oct 28, 2026
Main's meta#7849 localized Kbd's key names through useTranslator(), the whole
English catalog. Kbd now renders with useComponentTranslator over the kbd
namespace it reads, like every core component in this sweep.

Red first: check:i18n-catalog (six slice coverage problems in Kbd.tsx
before, none now).
@github-actions
github-actions Bot deleted the fix/i18n-formatter-returns branch October 28, 2026 06:17

This branch was successfully deployed

1 active deployment
Preview — 17f68be0 Deployed Oct 27, 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