【发布时间】:2020-11-02 08:49:12
【问题描述】:
在我的情况下,我需要将整个命名空间作为一个对象,有没有可以做到这一点? 我试过这段代码,但只是返回 undefined。
// the bookingPage is a namespace
t('bookingPage',{ returnObjects: true })
【问题讨论】:
标签: i18next react-i18next
在我的情况下,我需要将整个命名空间作为一个对象,有没有可以做到这一点? 我试过这段代码,但只是返回 undefined。
// the bookingPage is a namespace
t('bookingPage',{ returnObjects: true })
【问题讨论】:
标签: i18next react-i18next
t 函数不可能,t 函数返回一个字符串。
您可以访问整个 i18n 对象,该对象具有此方法。
// your-component.jsx
const YourComp = () => {
const { i18n } = useTranslation();
console.log(i18n.store.getResourceBundle('en', 'bookingPage')); //<-- will return the entire namespace
return <div>Bla</div>;
};
【讨论】: