feat: support aliased t
functions from useTranslation hooks
#278
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In my codebase, there are a lot of cases where we use aliased t function to differentiate between 2 useTranslation hook calls referring to different namespaces. (bcs of typescript perf issue as described in: i18next/i18next#2198)
The keys could be detected if we add
tCommon
andtProfile
into thetFunctionNames
options. Unfortunately, it can't detect the namespace and keyprefixes correctly. The t function call is detected as an "orphan" function call (as in, not originating from the hook).Because the way
useTranslationHook
extractor works is using a hardcoded "t", therefore the plugin couldn't identify if thet
function has been aliased.babel-plugin-i18next-extract/src/extractors/useTranslationHook.ts
Line 59 in 7cc5b80
This PR enables the plugin to detect if the t function has been aliased.
This PR also includes fixes and tests from #276 as the changed code is related. Credit to @guiedugt. Sorry for just copy pasting. I want to include their commits so they're included as Author in this PR, but I couldn't find a way to merge/include changes from a different fork repo.
This project will be very useful for us the moment this PR being merged. Thank you for creating this project!