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

Incorrect extraction for multiple useTranslation on the same page #973

Open
affanshahid opened this issue Feb 19, 2024 · 0 comments
Open

Comments

@affanshahid
Copy link

馃悰 Bug Report

If I have multiple invocations of useTranslation using different namespaces on the same page, the extraction does not work correctly.

To Reproduce

Create a component like:

const useSchema = () => {
  const { t } = useTranslation('validation');
  t('errors.invalid_type_received_undefined') // Note: `errors.invalid_type_received_undefined` is in ns validation
  // ...
};



export const HomePlanStep = () => {
  const { t } = useTranslation(['application-address', 'common']);
  useSchema()

  return <p>{t('homePlanStep.submitBtnText')}</p> // Note: this is in ns application-address
};

The dictionary that gets generated incorrectly has errors.invalid_type_received_undefined associated with NS: 'application-address'. The actual app runs just fine like this, only the extraction generates incorrect dictionaries.

If I make the following change, the dictionary gets generated correctly:

const useSchema = () => {
  const { t } = useTranslation('validation');
  t('errors.invalid_type_received_undefined', { ns: 'validation' }) // Note: added explicit ns
  // ...
};

Now the dictionary does not associate errors.invalid_type_received_undefined with NS: 'application-address'.

Expected behavior

The extractor should not mix-up namespaces when extracting

Your Environment

  • runtime version: Node v18.19.0
  • i18next version: v23.7.16
  • i18next-parser version: v8.12.0
  • os: MacOS Sonoma 14.2.1
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

1 participant