Skip to content

fix(extract): match whole count / context option names in nested $t() - #332

Merged
adrai merged 1 commit into
i18next:mainfrom
zzoraemon043:nested-options-whole-names
Nov 19, 2026
Merged

adrai merged 1 commit into
i18next:mainfrom
zzoraemon043:nested-options-whole-names

Conversation

@zzoraemon043

Copy link
Copy Markdown
Contributor

parseNestedReferences looks for count and context anywhere in the options string, so option names that only contain them are picked up too:

  • $t(price, {"discount": {{d}} }) is treated as a plural reference. extract writes price_one / price_other instead of price, and with removeUnusedKeys an existing price translation that is only referenced from another value is replaced by empty plural keys.
  • $t(name, {"subcontext": "formal"}) is treated as context formal.

The two regexes now only match a whole property name (at the start, or after {, , or whitespace, optionally quoted). "count", count and 'count' still match as before.

Tests: one case in extractor.nested-translations.test.ts (source code) and one in extractor.nested-translations-in-value.test.ts (removeUnusedKeys). Both fail before the change. npm test (lint + 1629 tests) and tsc --noEmit pass.

parseNestedReferences looked for count and context anywhere in the
options string, so $t(price, {"discount": 5}) was treated as a plural
reference and $t(name, {"subcontext": "formal"}) as a context one.
Extraction emitted price_one/price_other instead of price, and with
removeUnusedKeys an existing price translation was dropped.
@adrai
adrai merged commit 37dcbb1 into i18next:main Nov 19, 2026
11 checks passed
adrai added a commit that referenced this pull request Nov 19, 2026
…ole name

Like the nested $t() parser in #332: { discount: 5 } made plural keys, { subcontext: 'vip' } a context key and { dns: 'other' } a namespace. A quoted name ({ "count": 2 }) was not read at all.
@adrai

adrai commented Nov 19, 2026

Copy link
Copy Markdown
Member

Thanks for this, nice catch and a clean fix. I could reproduce it on main: with removeUnusedKeys an existing price translation was replaced by empty plural keys. Matching whole option names in the shared parser fixes it for extract and status at once.

The comment parser had the same pattern (// t('price', { discount: 5 })), I fixed that alongside. Both are included in v1.91.1.

zzoraemon043 added a commit to zzoraemon043/zzoraemon043 that referenced this pull request Nov 19, 2026
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.

2 participants