i18next-xhr-backend
i18next-xhr-backend copied to clipboard
How to listen to onInitialized event even if it occurred before my code ran
Hi, I have noticed some annoying behavior which is as follows:
I listen for the initialized event (i18next.on('initialized')
) to make sure that everything is setup before my app's code runs -- I need to make sure my translations are there. However, if my code gets run at a point after the initialized event occurs, it never runs at all, because it is inside this check.
Is there an easy way to listen for the event to fire or if it has already fired, then do something? I read this is how addEventListener
functions and I wish I could just get the same behavior with on
.
Thanks
Solved this myself. I checked for isInitialized, and if it's not set, listen to onInitialized event, otherwise if it is set, everything should be fine, IF you only care about the fallbackLng being loaded. I didn't need to worry about the other possibility myself.
in react-i18next our check looks like this for called loadNamespace: https://github.com/i18next/react-i18next/blob/master/src/utils.js#L24