Open RobHannay opened 1 year ago
Is there a reason you don't simply use the namespace everywhere? It would be more verbose but consistent and should work with the parser.
Yeah this was a conscious decision to avoid doing useTranslation('key', 'admin')
everywhere, but if you think that's just the most sensible path then we will have another think. But there is something nice about it being both automatic (using IDE imports) and lintable (enforce that only useAdminTranslation
is import within the admin package, etc)
π Feature Proposal
True namespace detection through static function call analysis, or through allowing easy project-specific config.
See example below for what I would like to achieve.
Either adding functionality to detect the namespace specified in the 'wrapping' hook, or allow some config to be added to specify that the hook being used in any given package has a certain default namespace, other than the usual config.
Motivation
Please outline the motivation for the proposal.
I have multiple projects in a monorepo, which use their own namespace to split translations, but share a common one too. They also import from each other.
I want to avoid duplication and enforce consistency by providing a
useTranslation
hook per project.Example
Some component-library component
And in some app component:
This all works correctly, and helps us enforce using the correct namespace in each part of the app.
However, the
parser
is not aware that they are using the namespaces used within the project-specificuseTranslation
hooks.Is this something that would even be feasible with how the parser works currently?
Workaround
My idea for a workaround would just be to customise the config for every package, and specify a different default namespace.
For example,
and then run that script multiple times:
i18next -c i18next.admin.config.js && i18next -c i18next.webapp.config.js &&...