Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty translation string causes deletion of other translation(s) #661

Open
bhr opened this issue Oct 20, 2022 · 2 comments
Open

Empty translation string causes deletion of other translation(s) #661

bhr opened this issue Oct 20, 2022 · 2 comments

Comments

@bhr
Copy link

bhr commented Oct 20, 2022

馃悰 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
@justinbc820
Copy link

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.

@karellm
Copy link
Member

karellm commented Oct 29, 2023

@justinbc820 Can you please make a PR to fix this?

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

No branches or pull requests

3 participants