Skip to content

Support aliases for useTranslation function in providing scoped namespaces #1231

@TzviPM

Description

@TzviPM

Is your feature related to a specific framework or general for this extension

Yes. react-i18next

Is your feature request related to a problem? Please describe.

Yes. Our application wraps the useTranslation utility provided by react-i18next in order to provide some more fine-tuned DX enhancements for our internal conventions. Our wrapper is named useI18nContext. I noticed that using this wrapper leads i18n-ally to falsely report missing translation keys when relying on an unqualified key using the default namespace. For example:

const {t} = useTranslation(['common', 'someFeature']);

t('some-key');

would correctly be identified as referring to common:some-key because the call to useTranslation changes the default namespace in its scope.

However, the following does not work:

const {t} = useI18nContext(['common', 'someFeature']);

t('some-key');

Describe the solution you'd like

I would like to be able to configure an alternate name or list of names to use for matching the scoped default namespace instead of useTranslation

Additional context

I have already created a proof of concept for this that works quite well for our use case. I based my implementation on e89557c#diff-1945e219acf58a633d45d6d8ef766218782fe79bd75a905659b76934902a075c. that I discovered via #307. I will create a PR with my changes and would love to contribute if you would accept the PR.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions