Skip to content

[feat] i18n: route ternary + templated strings through useTranslator() - #4013

Merged
nynexman4464 merged 1 commit into
mainfrom
nynexman4464/feat/i18n-more-strings
Jul 17, 2026
Merged

nynexman4464 merged 1 commit into
mainfrom
nynexman4464/feat/i18n-more-strings

Conversation

@nynexman4464

@nynexman4464 nynexman4464 commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #4010. Extends the i18n migration series to catch string literals inside ternary and template-literal expressions on JSX attributes — patterns a plain-literal audit missed:

aria-label={isOpen ? 'Close X' : 'Open X'}    // ternary in JSX attribute
aria-label={`Clear ${label}`}                 // templated string

Both slipped past the initial migration because the attribute value is a JSXExpressionContainer, not a bare Literal. Real-world integration testing (pseudo-locale + French locale swap on a consumer app) surfaced ~50 pre-existing hardcoded strings across 24 files.

Catalog

33 new entries in packages/core/locales/en.json, all @astryx.<component>.* camelCase. All interpolations expressed as ICU MessageFormat variables ({label}, {header}, {sender}, {title}, …). Notable consolidation: useTableFiltering had 14 sites of `Filter ${header}` all sharing one key with an ICU variable.

Zero user-visible English changes — every defaultMessage matches the pre-migration string exactly.

Testing

  • 4,614 core tests pass (206 files)
  • pnpm -F @astryxdesign/core lint: clean
  • pnpm -F @astryxdesign/core typecheck: clean

Refs #3641, builds on #4010. Follow-up PR extends the no-hardcoded-i18n-string rule so this class of miss can't happen again.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 15, 2026
@vercel

vercel Bot commented Jul 15, 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, Comment Jul 17, 2026 9:31pm

Request Review

@nynexman4464
nynexman4464 marked this pull request as ready for review July 15, 2026 22:29
@nynexman4464
nynexman4464 force-pushed the nynexman4464/feat/i18n-lint-rule branch from 1503117 to be1a23b Compare July 15, 2026 22:51
@nynexman4464
nynexman4464 force-pushed the nynexman4464/feat/i18n-more-strings branch from ee7dbfe to bdadf04 Compare July 15, 2026 22:51
nynexman4464 added a commit that referenced this pull request Jul 15, 2026
…late patterns

Walks into a JSX-expression container (or a destructure default) and
recursively reports string literals nested inside conditional, logical,
and template-literal expressions. Handles the two patterns that a
plain-literal check missed:

  aria-label={isOpen ? 'Close X' : 'Open X'}     // ConditionalExpression
  aria-label={cond && 'Something'}                // LogicalExpression
  aria-label={fallback ?? 'Default'}              // LogicalExpression
  aria-label={`Clear ${label}`}                 // TemplateLiteral

Deliberately does NOT walk into CallExpression (already handled — t()
calls are the correct form), MemberExpression, Identifier, arrow
function bodies, or JSX expressions — those are either fine or too
likely to false-positive.

Same behavior for the destructure-default case:

  function Foo({label = cond ? 'A' : 'B'}) { ... }
  function Foo({label = `Default ${x}`}) { ... }

Both are now flagged as `hardcodedDefault`.

Real-world integration testing (pseudo-locale swap on a consumer app)
was the forcing function. The pattern is common enough that a 24-file
migration was needed to green up the extension — landed separately in
#4013 which this PR stacks on.

Refs #3641, builds on #4013
@nynexman4464
nynexman4464 force-pushed the nynexman4464/feat/i18n-lint-rule branch from be1a23b to 062f650 Compare July 17, 2026 16:26
@nynexman4464
nynexman4464 force-pushed the nynexman4464/feat/i18n-more-strings branch from bdadf04 to 995e996 Compare July 17, 2026 16:26
nynexman4464 added a commit that referenced this pull request Jul 17, 2026
…late patterns

Walks into a JSX-expression container (or a destructure default) and
recursively reports string literals nested inside conditional, logical,
and template-literal expressions. Handles the two patterns that a
plain-literal check missed:

  aria-label={isOpen ? 'Close X' : 'Open X'}     // ConditionalExpression
  aria-label={cond && 'Something'}                // LogicalExpression
  aria-label={fallback ?? 'Default'}              // LogicalExpression
  aria-label={`Clear ${label}`}                 // TemplateLiteral

Deliberately does NOT walk into CallExpression (already handled — t()
calls are the correct form), MemberExpression, Identifier, arrow
function bodies, or JSX expressions — those are either fine or too
likely to false-positive.

Same behavior for the destructure-default case:

  function Foo({label = cond ? 'A' : 'B'}) { ... }
  function Foo({label = `Default ${x}`}) { ... }

Both are now flagged as `hardcodedDefault`.

Real-world integration testing (pseudo-locale swap on a consumer app)
was the forcing function. The pattern is common enough that a 24-file
migration was needed to green up the extension — landed separately in
#4013 which this PR stacks on.

Refs #3641, builds on #4013
@nynexman4464
nynexman4464 force-pushed the nynexman4464/feat/i18n-lint-rule branch from 062f650 to 726cf27 Compare July 17, 2026 17:54
@nynexman4464
nynexman4464 force-pushed the nynexman4464/feat/i18n-more-strings branch from 995e996 to bdba214 Compare July 17, 2026 17:54
nynexman4464 added a commit that referenced this pull request Jul 17, 2026
…late patterns

Walks into a JSX-expression container (or a destructure default) and
recursively reports string literals nested inside conditional, logical,
and template-literal expressions. Handles the two patterns that a
plain-literal check missed:

  aria-label={isOpen ? 'Close X' : 'Open X'}     // ConditionalExpression
  aria-label={cond && 'Something'}                // LogicalExpression
  aria-label={fallback ?? 'Default'}              // LogicalExpression
  aria-label={`Clear ${label}`}                 // TemplateLiteral

Deliberately does NOT walk into CallExpression (already handled — t()
calls are the correct form), MemberExpression, Identifier, arrow
function bodies, or JSX expressions — those are either fine or too
likely to false-positive.

Same behavior for the destructure-default case:

  function Foo({label = cond ? 'A' : 'B'}) { ... }
  function Foo({label = `Default ${x}`}) { ... }

Both are now flagged as `hardcodedDefault`.

Real-world integration testing (pseudo-locale swap on a consumer app)
was the forcing function. The pattern is common enough that a 24-file
migration was needed to green up the extension — landed separately in
#4013 which this PR stacks on.

Refs #3641, builds on #4013
@nynexman4464
nynexman4464 force-pushed the nynexman4464/feat/i18n-lint-rule branch from 726cf27 to 3e97482 Compare July 17, 2026 21:12
Extends the i18n migration series to catch the two patterns that a
plain-literal audit missed:

  aria-label={isOpen ? 'Close X' : 'Open X'}     (ternary in JSX attr)
  aria-label={`Clear ${label}`}                (templated string)

Both slipped past the initial migration because the value on the
attribute is a JSX expression container, not a bare string literal.
Real-world integration testing (French / pseudo locale swap on a
consumer app) caught them.

Migrations by component (27 files):

  DateInput / DateRangeInput / DateTimeInput
    - calendar toggle aria-label (open/close)
    - clear button aria-label (`Clear ${label}`)
  Banner, SideNavItem, ChatComposerDrawer
    - expand/collapse ternaries
  ChatSendButton
    - send/stop ternary
  ChatLayout, ChatLayoutScrollButton, ChatMessage, ChatTriggerMenu
    - templated aria-labels
  Citation, CodeBlock, Lightbox, MobileNav
    - templated / static aria-labels
  MultiSelector, NumberInput, Selector, TextInput, TimeInput, FileInput
    - `Clear ${label}` aria-labels
  SideNavCollapseButton
    - expand/collapse sidebar ternary
  Table plugins:
    - useTableFiltering — 14 `Filter ${header}` sites consolidated
      behind one shared key with ICU {header} variable
    - useTableGroupedRows — expand/collapse group templates
    - useTableRowExpansion — row-toggle and all-rows-toggle ternaries
  Thumbnail, Token
    - remove/open templates

33 new catalog entries in packages/core/locales/en.json, all
@AstryX.<component>.* camelCase. All interpolations expressed as ICU
MessageFormat variables. Zero user-visible English changes —
defaultMessage always matches the pre-migration string exactly.

5 sub-components in useTableFiltering that lacked `useTranslator`
now have it. useTriggerMenu / useTableGroupedRows /
useTableRowExpansion needed `t` added to a few exhaustive-deps
arrays (no-op at runtime since useTranslator returns a stable
reference).

Refs #3641, builds on #4010
@nynexman4464
nynexman4464 force-pushed the nynexman4464/feat/i18n-more-strings branch from bdba214 to 5fd23ed Compare July 17, 2026 21:28
@nynexman4464
nynexman4464 changed the base branch from nynexman4464/feat/i18n-lint-rule to main July 17, 2026 21:28
github-actions Bot added a commit that referenced this pull request Jul 17, 2026
@nynexman4464
nynexman4464 merged commit b2a4936 into main Jul 17, 2026
19 checks passed
@github-actions

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.

No new or modified components detected.

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.7KB 0B

Accessibility Audit

Status: No accessibility violations detected.


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

nynexman4464 added a commit that referenced this pull request Jul 17, 2026
…late patterns

Walks into a JSX-expression container (or a destructure default) and
recursively reports string literals nested inside conditional, logical,
and template-literal expressions. Handles the two patterns that a
plain-literal check missed:

  aria-label={isOpen ? 'Close X' : 'Open X'}     // ConditionalExpression
  aria-label={cond && 'Something'}                // LogicalExpression
  aria-label={fallback ?? 'Default'}              // LogicalExpression
  aria-label={`Clear ${label}`}                 // TemplateLiteral

Deliberately does NOT walk into CallExpression (already handled — t()
calls are the correct form), MemberExpression, Identifier, arrow
function bodies, or JSX expressions — those are either fine or too
likely to false-positive.

Same behavior for the destructure-default case:

  function Foo({label = cond ? 'A' : 'B'}) { ... }
  function Foo({label = `Default ${x}`}) { ... }

Both are now flagged as `hardcodedDefault`.

Real-world integration testing (pseudo-locale swap on a consumer app)
was the forcing function. The pattern is common enough that a 24-file
migration was needed to green up the extension — landed separately in
#4013 which this PR stacks on.

Refs #3641, builds on #4013
nynexman4464 added a commit that referenced this pull request Jul 17, 2026
…late patterns (#4014)

Walks into a JSX-expression container (or a destructure default) and
recursively reports string literals nested inside conditional, logical,
and template-literal expressions. Handles the two patterns that a
plain-literal check missed:

  aria-label={isOpen ? 'Close X' : 'Open X'}     // ConditionalExpression
  aria-label={cond && 'Something'}                // LogicalExpression
  aria-label={fallback ?? 'Default'}              // LogicalExpression
  aria-label={`Clear ${label}`}                 // TemplateLiteral

Deliberately does NOT walk into CallExpression (already handled — t()
calls are the correct form), MemberExpression, Identifier, arrow
function bodies, or JSX expressions — those are either fine or too
likely to false-positive.

Same behavior for the destructure-default case:

  function Foo({label = cond ? 'A' : 'B'}) { ... }
  function Foo({label = `Default ${x}`}) { ... }

Both are now flagged as `hardcodedDefault`.

Real-world integration testing (pseudo-locale swap on a consumer app)
was the forcing function. The pattern is common enough that a 24-file
migration was needed to green up the extension — landed separately in
#4013 which this PR stacks on.

Refs #3641, builds on #4013
@github-actions
github-actions Bot deleted the nynexman4464/feat/i18n-more-strings branch July 18, 2026 06:42

This branch was successfully deployed

1 active deployment
Preview — 5fd23ed8 Deployed Jul 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