i18next-parser
i18next-parser copied to clipboard
Namespace detection in multi-scope useTranslation('ns') calls is file-level, not function-level
🐛 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
If you like you could try if it works with: https://github.com/i18next/i18next-cli