i18next / react-i18next

Internationalization for react done right. Using the i18next i18n ecosystem.
https://react.i18next.com
MIT License
9.23k stars 1.02k forks source link

False warning about accessing t function before calling init #977

Closed Robloche closed 4 years ago

Robloche commented 4 years ago

Describe the bug I'm having a warning that I think is a false positive. I get the thousands of the following warning: i18next.js:27 i18next::translator: key "xxx" for namespace "translation" won't get resolved as namespace was not yet loaded This means something IS WRONG in your application setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!

I think it's a false positive for 3 reasons:

  1. I do call init() before calling ReactDOM.render().
  2. I was working until I updated to v10.12.4 (or maybe 10.12.5, not sure...).
  3. All my localized strings are correctly displayed in my app.

Before all the warnings, the console prints this:

i18next: languageChanged fr-FR
i18next: initialized {debug: true, initImmediate: true, ns: Array(1), defaultNS: "translation", fallbackLng: Array(1), …}

Occurs in following versions npm 6.12.0 react-i18next 10.13.2

OS (please complete the following information):

jamuhl commented 4 years ago

You set useSuspense: false and I'm sure you do not handle the ready flag given -> so you render before ready...https://react.i18next.com/latest/usetranslation-hook#not-using-suspense

adelchamas96 commented 3 years ago

adding this when i18next is initialized solved the issue :

i18n.on("initialized", () => {
    ReactDOM.render(<App />, document.getElementById('root'));
})
jamuhl commented 3 years ago

@andresilveirah ...just make sure you got useTranslation or withTranslation everywhere you use t -> what you're doing is just fixing the symptoms but not solving the underlying problem of having somewhere a access to t outside of the hook, HOC

sharifme04 commented 3 years ago

@tonix-tuft from where you got this method initNumberFormatting? In my case, it always comes undefined.