Skip to content

fix: transform a useLingui t nested in a placeholder of another t - #285

Merged
andrii-bodnar merged 1 commit into
lingui:mainfrom
cristianchiriac:fix-nested-use-lingui-t
Oct 15, 2026
Merged

andrii-bodnar merged 1 commit into
lingui:mainfrom
cristianchiriac:fix-nested-use-lingui-t

Conversation

@cristianchiriac

Copy link
Copy Markdown
Contributor

JsMacroFolder built the i18n call for t`...`, t({...}) and plural/select, then returned it without folding it. Placeholder expressions are copied verbatim into values, so a t from useLingui() nested in a placeholder was left as a tagged template on the runtime function, and at runtime i18n._() got a TemplateStringsArray and returned "". The produced call's children are now folded too, as LinguiMacroFolder does for the core macros and as #279 did for JSX. Only the call's arguments are folded (CallExpr::fold_children_with), so the produced call doesn't go through fold_call_expr a second time.

Tests (use_lingui.rs), each producing the output the issue expects:

  • t`Calibrated for ${device || t`Microphone`}` → 0: device || $__({ id: "1iY5xv", message: "Microphone" }).
  • The issue's other case, a nested t next to a plural placeholder.
  • A nested t inside the placeholder of t({ message: ... }).

All three fail without the change, and cargo test -p lingui_macro, cargo fmt --check and cargo clippy -p lingui_macro --all-targets -- -D warnings pass. I couldn't run the extractor and native-tools crates locally, because napi-build doesn't build on my Windows GNU toolchain. CI covers those.

Fixes #284

JsMacroFolder returned the i18n call built for `t`, `t({...})` and
plural/select without folding it, so a nested `t` from useLingui()
copied into the values was left as a tagged template on the runtime
function, which returns "". Fold the produced call's children, like
LinguiMacroFolder does and as #279 did for JSX.

Fixes #284
@codecov

codecov Bot commented Oct 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.42%. Comparing base (b9735d3) to head (0caec55).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #285   +/-   ##
=======================================
  Coverage   94.42%   94.42%           
=======================================
  Files          11       11           
  Lines        2529     2530    +1     
=======================================
+ Hits         2388     2389    +1     
  Misses        141      141           
Flag Coverage Δ
unittests 94.42% <100.00%> (+<0.01%) ⮆ïļ

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
crates/lingui_macro/src/js_macro_folder.rs 98.70% <100.00%> (+<0.01%) ⮆ïļ
🚀 New features to boost your workflow:
  • ❄ïļ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ðŸŸĒ Approval recommended

The localized fix preserves message construction, covers the reported regressions, and has no identified blocking issues.

0 open findings

What changed in this PR

Fixes #284 by transforming nested useLingui().t calls inside message placeholders, extending the existing nested-macro handling.

Changes:

  • Folds generated call children without reprocessing the call itself.
  • Adds three regression tests and snapshots covering template, plural-adjacent, and descriptor placeholders.
File Description
crates/​lingui_macro/​tests/​use_lingui.rs Adds three nesting regression tests.
crates/​lingui_macro/​tests/​snapshots/​use_lingui__js_use_lingui_nested_t_next_to_plural_placeholder.snap Verifies nesting alongside a plural placeholder.
crates/​lingui_macro/​tests/​snapshots/​use_lingui__js_use_lingui_nested_t_in_placeholder.snap Verifies nesting in a template placeholder.
crates/​lingui_macro/​tests/​snapshots/​use_lingui__js_use_lingui_nested_t_in_descriptor_placeholder.snap Verifies nesting in a descriptor placeholder.
crates/​lingui_macro/​src/​js_macro_folder.rs Folds generated call children to transform nested macros.

🧠 Review effort: Balanced


ðŸ’Ą Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@andrii-bodnar
andrii-bodnar merged commit c78373a into lingui:main Oct 15, 2026
28 checks passed
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.

t from useLingui nested in another t placeholder is not transformed

4 participants