fix(i18n): don't treat mustache-style {{tokens}} as named substitutions#2486
Open
thribhuvan003 wants to merge 1 commit into
Open
fix(i18n): don't treat mustache-style {{tokens}} as named substitutions#2486thribhuvan003 wants to merge 1 commit into
thribhuvan003 wants to merge 1 commit into
Conversation
✅ Deploy Preview for creative-fairy-df92c4 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
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.
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 plaini18n.t("key")call fails withnot 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_REnow matches single-brace{name}placeholders only, using lookarounds to skip brace groups wrapped in additional braces: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{greeting}, keep {{token}} as-is) → only{greeting}is a substitutionThis is the first option proposed in the issue (single-brace only), which keeps
0.2.6behavior for all existing single-brace users and restores0.2.5behavior 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