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

Namespace detection in multi-scope useTranslation('ns') calls is file-level, not function-level

Open rocky-luo-opus opened this issue 9 months ago • 1 comments

🐛 Bug Report

When using multiple useTranslation('namespace') calls in a single file, i18next-parser incorrectly applies the last-found namespace to all t() calls in the file, regardless of their actual lexical scope.

This leads to incorrect key extraction and keys being written to the wrong namespace files.

To Reproduce

A minimal reproducible example. A codesandbox example or similar or at least steps to reproduce the behavior:

// Notifications.tsx

function NotificationItem() {
  const { t } = useTranslation('clip')
  t('changes_not_saved') // ❌ Extracted as common:changes_not_saved
}

function NotificationContent() {
  const { t } = useTranslation('common')
  t('news') // ✅ Correctly extracted as common:news
}

Your Environment

  • runtime version: i.e. node v20.19.0
  • i18next version: i.e. ^23.11.2
  • os: Mac
  • any other relevant information

rocky-luo-opus avatar May 11 '25 08:05 rocky-luo-opus

If you like you could try if it works with: https://github.com/i18next/i18next-cli

adrai avatar Sep 25 '25 13:09 adrai