Can't determine if i18next has been initialized post initialization.

See original GitHub issue

I am currently trying to determine if i18next has been initialized asynchronously prior to requesting translations.

For example:

i18next.init();

setTimeout(function () {
    i18next.on('initialized', function () {
        console.log('may not run?');
    }
}, 500);

This is had originally been implemented in #380, but was removed during the 2.0.0 rewrite.

Is there a way to detect if i18next is already initialized?

Personally I would prefer if the callback in i18next.on('initialized', callback) was run immediately if i18next has already been initialized.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

16reactions
bepetersncommented, Apr 19, 2019

I ended up doing something like this:

if(!i18next.isInitialized) {
    // wait for initalization
    i18next.on('initialized', mycodefunc);
} else {
    mycode();
}
0reactions
jamuhlcommented, Apr 2, 2019

the options can be found on i18next.options

// second init i like to be sure is done:
i18next.init({ second: true });

// check
i18next.on('initialized', () => {
  if (i18next.options && i18next.options.second) {
    // seems 2nd init was done
  }
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

i18next - initialization
If language is not set explicitly i18next tries to detect the user language by: ... Set language after init: i18n.setLng('en-US', function(err, ...
Read more >
Configuration Options - i18next documentation
Set it to false if your backend loads resources synchronously - that way, calling i18next.t() after init() is possible without relying on the...
Read more >
How to use the i18next.isInitialized function in i18next - Snyk
isInitialized) i18n.init(options) // a simple helper to getInitialProps passed on loaded i18n data i18n.getInitialProps = (req, namespaces) => { if ...
Read more >
You will need to pass in an i18next instance by using ...
init () inside beforeEach hook? And i18n should be the instance of your instantiated i18n instance. The only difference that in my case...
Read more >
Beginning JavaScript I18n with i18next and Moment.js | Phrase
We'll want a default locale to use when we can't find ... i18next has its own init function that accepts an options object...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found