when i use const { t, i18n } = useTranslation(['common', 'header']); for example, t functions don't work for the strings which is in second element of the array, if I switch places it works well. Btw both namespace is loaded in i18n.store.data object but don't work
I use
Home.getInitialProps = async () => ({
namespacesRequired: ['header', 'common'],
});
and t function as
{t('title')} // where title is in header.json file
_EDIT: (this is in fact working as intended, see my edit bellow)_
I am having a similar problem with .withTranslation([]) HOC. Only the first namespace is working.
For example:
const Foo = ({ t }) => <p>{t('fromTest1')} ; {t('fromTest2')}</p>
export default withTranslation(['test1', 'test2'])(Foo)
// Will output "<p>Translated Test 1 ; fromTest2</p>"
whereas
const Foo = ({ t }) => <p>{t('fromTest1')} ; {t('fromTest2')}</p>
export default withTranslation(['test2', 'test1'])(Foo)
// Will output "<p>fromTest1 ; Translated Test 2</p>"
EDIT After some research it appears that from the second namespace you should prefix using the namespace name like so: namespace:your.key
typescript
const Foo = ({ t }) => <p>{t('fromTest1')} ; {t('test2:fromTest2')}</p>
export default withTranslation(['test1', 'test2'])(Foo)
// Will output "<p>Translated Test 1 ; Translated Test 2</p>"
Please read the i18next documentation. You will need to denote the second (non default) namespace with a colon separator.
Most helpful comment
_EDIT: (this is in fact working as intended, see my edit bellow)_
I am having a similar problem with
.withTranslation([])HOC. Only the first namespace is working.For example:
whereas
EDIT After some research it appears that from the second namespace you should prefix using the namespace name like so:
namespace:your.keytypescript const Foo = ({ t }) => <p>{t('fromTest1')} ; {t('test2:fromTest2')}</p> export default withTranslation(['test1', 'test2'])(Foo) // Will output "<p>Translated Test 1 ; Translated Test 2</p>"