i18next-parser icon indicating copy to clipboard operation
i18next-parser copied to clipboard

Nesting t calls causes unwanted key removal

Open adroste opened this issue 1 year ago • 1 comments

🐛 Bug Report

Nesting t calls causes unwanted removal of keys

To Reproduce

const condition = true
t('test.outer', { subString: condition ? t('test.inner1') : t('test.inner2') })

The keys test.inner1 and test.inner2 will be removed from the translations file.

Expected behavior

Keys should not be removed.

Your Environment

  • runtime version: node 20
  • i18next-parser version: 9.0.1 (happens also in v8)
  • os: macos 14.3

adroste avatar Jul 27 '24 21:07 adroste

You can prevent the removal of false i18n keys like this!

condition ? 
  t('test.outer', { subString: t('test.inner1') }) : 
  t('test.outer', { subString: t('test.inner2') })

or

const testOuterSubString = condition ? t('test.inner1') : t('test.inner2')

t('test.outer', { subString: testOuterSubString })

Insik-Han avatar Jan 30 '25 05:01 Insik-Han