-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Trans Component namespace #867
Comments
expected...there is no way to sync them...at least I got no idea how to do so |
@jamuhl Hey, thanks for the reply! I'm pretty sure that worked before, but I couldn't pinpoint the specific version. To clarify what is the expected behavior. When using Trans component like this: const [t] = useTranslation('my_namespace');
<Trans t={t} i18nKey="key1.key2">
Placeholder
</Trans> My Trans Component was parsed using string from const [t] = useTranslation('my_namespace');
t('key1.key2')
// Which is equivalent to calling
i18n.t('my_namespace:key1.key2') I've used this in many places in my project and yesterday after updating packages I found out that it doesn't work anymore. So I'm guessing some changes in recent versions of either i18next or react-i18next alternated Trans component behavior in that matter. So regarding your answer, it is not about synchronizing them it's about using |
like said...does not work anymore...not with hooks... used to work with HOCs doing some nasty double usage of context provider -> so as this does not work with hooks we decided we need to drop the behaviour... So like you showed either pass |
I also experience this issue. With |
@kachkaev more a design decision...v9 had a very ugly way of being a context consumer and provider the same time - so t get passed from the HOC to below Trans component... the useTranslation hook can't be a Provider so the only way is to be explicit on the Trans component or creating a own Wrapper |
In any case, there seems to be a breaking change between
// works in 10.10.0 and below
const { t } = useTranslation('my-namespace')
return <Trans t={t} i18nKey="blah" />
// works in any 10.*
return <Trans i18nKey="my-namespace:blah" /> |
@kachkaev you're right 10.11.0 introduced https://github.com/i18next/react-i18next/blob/v10.11.0/src/Trans.js#L216 which obviously is breaking the behaviour...will provide a fix later today. |
@kachkaev should be fixed in react-i18next@10.11.1 |
Trans component documentation should be updated to show t function being passed as a prop. I spent many hours trying to debug a missing namespace only to find all the examples in the documentation are wrong and there is no mention of having to pass the t prop for namespaces to work correctly. |
You only need to set namespace if not using default namespace...there is no need to pass |
I'm on latest version (10.11.4) and my |
It fixes by taking the passed in |
Describe the bug
When using Trans component in conjunction with useTranslation hook namespace set in hook is not used for translation inside component.
Deducting from debug info Trans component use
translation
namespace instead ofns
. When I explicitly specify namespace in key it works as intended (<Trans i18nKey="ns:some.key">...
) as well as when namespace is declared throughns="ns"
prop, but from what I can remember usingt
namespace worked before.Occurs in react-i18next version
v10.11.0
The text was updated successfully, but these errors were encountered: