Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to listen to onInitialized event even if it occurred before my code ran #304

Open
bepetersn opened this issue Apr 1, 2019 · 2 comments

Comments

@bepetersn
Copy link

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

@bepetersn
Copy link
Author

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.

@jamuhl
Copy link
Member

jamuhl commented Apr 2, 2019

in react-i18next our check looks like this for called loadNamespace: https://github.com/i18next/react-i18next/blob/master/src/utils.js#L24

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants