Skip to content

fix(i18n): don't treat mustache-style {{tokens}} as named substitutions#2486

Open
thribhuvan003 wants to merge 1 commit into
wxt-dev:mainfrom
thribhuvan003:fix/i18n-mustache-literal-tokens
Open

fix(i18n): don't treat mustache-style {{tokens}} as named substitutions#2486
thribhuvan003 wants to merge 1 commit into
wxt-dev:mainfrom
thribhuvan003:fix/i18n-mustache-literal-tokens

Conversation

@thribhuvan003

Copy link
Copy Markdown

Problem

Since 0.2.6, messages containing mustache-style application tokens ({{targetLanguage}}) are scanned as named substitutions, so the generated types require a substitution object and a plain i18n.t("key") call fails with not assignable to parameter of type never — even when the app intentionally wants the raw localized template back (e.g. AI prompt templates rendered later by the app itself).

Fix

NAMED_SUBSTITUTION_RE now matches single-brace {name} placeholders only, using lookarounds to skip brace groups wrapped in additional braces:

/(?<!\{)\{([A-Za-z0-9_]+)\}(?!\})/g

The regex is shared by the type scanner (getNamedSubstitutionNames) and the runtime (applyNamedSubstitutions), so both stay consistent:

  • {{selection}} / {{targetLanguage}} → left as literals, not scanned, not substituted
  • {name} → still scanned and substituted exactly as before
  • mixed messages ({greeting}, keep {{token}} as-is) → only {greeting} is a substitution

This is the first option proposed in the issue (single-brace only), which keeps 0.2.6 behavior for all existing single-brace users and restores 0.2.5 behavior for mustache templates.

Verification

Added 4 regression tests (scanner + runtime, pure-mustache and mixed cases), using the reproduction strings from the issue.

  • bun run test: 49 passed (45 existing + 4 new)
  • bun run check: Oxlint ✔ Publint ✔ TypeScript ✔

Fixes #2482

@thribhuvan003 thribhuvan003 requested a review from aklinker1 as a code owner July 4, 2026 10:27
@netlify

netlify Bot commented Jul 4, 2026

Copy link
Copy Markdown

Deploy Preview for creative-fairy-df92c4 ready!

Name Link
🔨 Latest commit 12a3f7e
🔍 Latest deploy log https://app.netlify.com/projects/creative-fairy-df92c4/deploys/6a48e025a9031500080f6f94
😎 Deploy Preview https://deploy-preview-2486--creative-fairy-df92c4.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions github-actions Bot added the pkg/i18n Includes changes to the `packages/i18n` directory label Jul 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg/i18n Includes changes to the `packages/i18n` directory

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@wxt-dev/i18n: named substitutions treat mustache-style {{tokens}} as required i18n arguments

1 participant