Skip to content

feat: Extract useTranslations/getTranslations usages in SWC plugin#2344

Merged
amannn merged 1 commit into
canaryfrom
feat/swc-extract-use-translations
Jun 5, 2026
Merged

feat: Extract useTranslations/getTranslations usages in SWC plugin#2344
amannn merged 1 commit into
canaryfrom
feat/swc-extract-use-translations

Conversation

@amannn

@amannn amannn commented Jun 5, 2026

Copy link
Copy Markdown
Owner

Summary

Extends the SWC extractor plugin to also collect statically-analyzable useTranslations / getTranslations key usages, alongside the existing inline-message extraction (useExtracted / getExtracted).

The plugin's results payload is a tagged union (type: "extracted" | "translation"):

  • extracted — an inline message from useExtracted / getExtracted: { type: "extracted", id, message, description, reference }
  • translation — a useTranslations / getTranslations key reference: { type: "translation", id, reference }, where id is the fully-qualified namespace.key

translation extraction

  • const t = useTranslations('ns'); t('key')id: "ns.key"
  • root namespace useTranslations(); t('key')id: "key"
  • rich / markup / has / raw member calls are recognized
  • the id is resolved as far as is statically known — a dynamic key under a namespace records the namespace (id: "ns"); a dynamic key in the global namespace is skipped
  • await getTranslations(...) (server) is supported

Consumer

next-intl's MessageExtractor consumes the extracted variant; the catalog SourceMessage type is renamed to SourceExtractedMessage to make explicit that the pipeline only handles extracted messages.

Tests

Covered by the tests/fixture/** snapshots — each fixture's output.json carries the tagged union (incl. use-translations, use-translations-dynamic-key, get-translations, use-translations-with-extracted).

@vercel

vercel Bot commented Jun 5, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
next-intl-docs Ready Ready Preview, Comment Jun 5, 2026 1:41pm
next-intl-example-app-router Ready Ready Preview, Comment Jun 5, 2026 1:41pm
next-intl-example-app-router-without-i18n-routing Ready Ready Preview, Comment Jun 5, 2026 1:41pm

Request Review

@amannn amannn changed the base branch from feat/tree-shaking-messages to main June 5, 2026 10:59
@amannn amannn force-pushed the feat/swc-extract-use-translations branch 3 times, most recently from 226b87d to f11ca6d Compare June 5, 2026 12:04
@amannn

amannn commented Jun 5, 2026

Copy link
Copy Markdown
Owner Author

@claude this repo currently uses a separate workflow for stable releases and prereleases. for trusted publishing, i can only specify a single workflow file. you need to combine both into a single file while making sure only canary publishing or stable publishing is triggered based on the correct branch name

@amannn amannn force-pushed the feat/swc-extract-use-translations branch from f11ca6d to bfae242 Compare June 5, 2026 13:07
@amannn amannn changed the base branch from main to canary June 5, 2026 13:08
…sages

Emit a single `results` payload as a tagged union (`type: "extracted" | "translation"`):

- `extracted` — an inline message from `useExtracted` / `getExtracted`
- `translation` — a `useTranslations` / `getTranslations` key reference
  (`{ id, reference }`), where `id` is the fully-qualified `namespace.key`,
  resolved as far as is statically known: a dynamic key under a namespace
  records the namespace; a dynamic key in the global namespace is skipped

`rich` / `markup` / `has` / `raw` member calls are recognized, and
`await getTranslations(...)` (server) is supported.

next-intl's `MessageExtractor` consumes the `extracted` variant (the catalog
`SourceMessage` type is renamed to `SourceExtractedMessage`). Covered by the
`tests/fixture/**` snapshots.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@amannn amannn force-pushed the feat/swc-extract-use-translations branch from bfae242 to 9d77169 Compare June 5, 2026 13:38
@amannn amannn changed the title feat(swc-plugin-extractor): extract useTranslations/getTranslations usages feat: extract useTranslations/getTranslations usages Jun 5, 2026
@amannn amannn changed the title feat: extract useTranslations/getTranslations usages feat: Extract useTranslations/getTranslations usages in SWC plugin Jun 5, 2026
@amannn amannn merged commit 2f201b8 into canary Jun 5, 2026
9 of 10 checks passed
@amannn amannn deleted the feat/swc-extract-use-translations branch June 5, 2026 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant