i18next-parser
i18next-parser copied to clipboard
Empty translation string causes deletion of other translation(s)
🐛 Bug Report
When t('') is used anywhere in code, other translations cannot be found/referenced by i18next-parser.
To Reproduce
return (
<div className={clsx(style.root)}>
<p>{t('TITLE')}</p>
<p>
{t('')}
<Trans t={t} i18nKey="DESCRIPTION">
Press <Button content={t('BUTTON_TITLE')} onClick={reset} plain underline /> to go back.
</Trans>
</p>
</div>
);
The key TITLE is removed form the translation.json
Expected behavior
The key TITLE should not be removed from the translation.json.
Fix / Workaround
Removing {t('')} fixes the issue. The TITLE key remains in the original translation
Your Environment
- runtime version: i.e. node 16
- i18next version: i.e. 5.3.0
- os: Mac
I experienced this same issue. It took a very long time to figure out why only half of my translations were showing up in the output file. It is due to src/helpers.js:35-41 which is this code.
// There is no key to process so we return an empty object
if (!key) {
if (!target[entry.namespace]) {
target[entry.namespace] = {}
}
return { target, duplicate, conflict }
}
I don't understand why we would want to overwrite all previous translations just because there's an empty key. At the very least, keep old translations and just skip this key.
@justinbc820 Can you please make a PR to fix this?