Context: We use babel-plugin-i18next-extract with react-i18next and react.
The translations from Trans components get extracted into default namespace even when t function from useTranslation('myNamespace') is provided in props. It should get extracted into myNamespace, not the default one.
How to reproduce
We want to extract a translation string from Trans component into a namespace provided by t function which we passed to Trans via props.
import React from 'react';
import { Trans, useTranslation } from 'react-i18next'
function MyComponent() {
const { t } = useTranslation('myNamespace');
// we provide namespace 'myNamespace' to Trans component
// by passing t function as prop
return <Trans t={t}>Hello World</Trans>;
}
Expected behavior
The translation string is extracted to the namespace provided by t (i.e. to public/locales/en/myNamespace.json)
What actually happens
The translation string is extracted to the default namespace (i.e. to public/locales/en/translation.json)
A workaround
The following works correctly: <Trans ns="myNamespace">Hello World</Trans>.
Hi, thanks for opening an issue. Yeah, trans component extraction doesn't parse "t" function at the moment. Don't think it's that easy to tackle though. It parses tOptions prop though if that's of help.
Describe the bug
Context: We use
babel-plugin-i18next-extract
withreact-i18next
andreact
.The translations from
Trans
components get extracted into default namespace even whent
function fromuseTranslation('myNamespace')
is provided in props. It should get extracted intomyNamespace
, not the default one.How to reproduce
We want to extract a translation string from
Trans
component into a namespace provided byt
function which we passed toTrans
via props.Babel configuration:
babel.config.js
Reproduction:
The following example is based on documentation. More info is in related issue.
Expected behavior
The translation string is extracted to the namespace provided by
t
(i.e. topublic/locales/en/myNamespace.json
)What actually happens
The translation string is extracted to the default namespace (i.e. to
public/locales/en/translation.json
)A workaround
The following works correctly:
<Trans ns="myNamespace">Hello World</Trans>
.Your environment