feat: Extract useTranslations/getTranslations usages in SWC plugin#2344
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
226b87d to
f11ca6d
Compare
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 |
f11ca6d to
bfae242
Compare
…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>
bfae242 to
9d77169
Compare
useTranslations/getTranslations usages in SWC plugin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Extends the SWC extractor plugin to also collect statically-analyzable
useTranslations/getTranslationskey usages, alongside the existing inline-message extraction (useExtracted/getExtracted).The plugin's
resultspayload is a tagged union (type: "extracted" | "translation"):extracted— an inline message fromuseExtracted/getExtracted:{ type: "extracted", id, message, description, reference }translation— auseTranslations/getTranslationskey reference:{ type: "translation", id, reference }, whereidis the fully-qualifiednamespace.keytranslationextractionconst t = useTranslations('ns'); t('key')→id: "ns.key"useTranslations(); t('key')→id: "key"rich/markup/has/rawmember calls are recognizedid: "ns"); a dynamic key in the global namespace is skippedawait getTranslations(...)(server) is supportedConsumer
next-intl's
MessageExtractorconsumes theextractedvariant; the catalogSourceMessagetype is renamed toSourceExtractedMessageto make explicit that the pipeline only handles extracted messages.Tests
Covered by the
tests/fixture/**snapshots — each fixture'soutput.jsoncarries the tagged union (incl.use-translations,use-translations-dynamic-key,get-translations,use-translations-with-extracted).