【问题标题】:Is there any way to return an entire namespace via the translate function in i18next?有没有办法通过 i18next 中的 translate 函数返回整个命名空间?
【发布时间】:2020-11-02 08:49:12
【问题描述】:

在我的情况下,我需要将整个命名空间作为一个对象,有没有可以做到这一点? 我试过这段代码,但只是返回 undefined。

 // the bookingPage is a namespace
t('bookingPage',{ returnObjects: true })

【问题讨论】:

    标签: i18next react-i18next


    【解决方案1】:

    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>;
    };
    
    

    【讨论】:

    • 如果这个答案对你有帮助,请标记为:]
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-13
    • 2020-02-23
    相关资源
    最近更新 更多