Skip to content

feat(babel-plugin-lingui-macro): add nested msg and t support - #2625

Merged
andrii-bodnar merged 4 commits into
mainfrom
feat/nested-macro-support
Jul 24, 2026
Merged

andrii-bodnar merged 4 commits into
mainfrom
feat/nested-macro-support

Conversation

@timofei-iatsenko

Copy link
Copy Markdown
Collaborator

Description

Currently, plural/select/selectOrdinal macros are inlined into the ICU message string when nested inside t or msg. But t and msg tagged template macros are NOT inlined when nested — they produce separate i18n._() calls and become opaque positional placeholders ({0}). This PR making t and msg tagged templates also inline their message content when nested.

Before (current): t`Field ${t`First Name`} is required` → two separate i18n._() calls, outer message is "Field {0} is required"

After (desired): t`Field ${t`First Name`} is required` → single call, message is "Field First Name is required"

This is basically needed for #2618 where option values cannot be template literals:

Template literals inside plural/select options (e.g., She is ${gender}) are already evaluated by the time they reach the function. However, the full functionality is preserved — instead of a plain template literal, users wrap it with t to produce a macro marker: t`She is ${{gender}}` instead of She is ${gender}. Nested macro markers (plural, select, selectOrdinal) work as option values as well.

Example of pattern which is supported now by compile time macro (note the nested msg in the option):

plural({ count }, { 0: msg`No books {{placeholder}}`, 1: msg`One book`, other: "# books" })}

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Examples update

Fixes # (issue)

Checklist

  • I have read the CONTRIBUTING and CODE_OF_CONDUCT docs
  • I have added tests that prove my fix is effective or that my feature works
  • I have added the necessary documentation (if appropriate)

@vercel

vercel Bot commented Jul 24, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
js-lingui Ready Ready Preview Jul 24, 2026 9:16am

Request Review

@github-actions

Copy link
Copy Markdown

size-limit report 📦

Path Size
packages/core/dist/index.mjs 1.69 KB (0%)
packages/detect-locale/dist/index.mjs 633 B (0%)
packages/react/dist/index.mjs 1.9 KB (0%)

@andrii-bodnar
andrii-bodnar merged commit eb1fbec into main Jul 24, 2026
9 checks passed
@andrii-bodnar
andrii-bodnar deleted the feat/nested-macro-support branch July 24, 2026 13:24
@pkasarda

Copy link
Copy Markdown
Contributor

Thank you for fixing "old" issue #1848 ❤️

This branch was successfully deployed

1 active deployment
Preview — 625bb860 Deployed Jul 24, 2026 by vercel[bot]
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.

3 participants