Can't get Localize.on("initialize") to fire after initialization

Developer Forum

Ask a Question
Back to All

Can't get Localize.on("initialize") to fire after initialization

I'm trying to use the on initialize example that is mentioned in the docs: https://developers.localizejs.com/docs/library-api#initialize-1

Localize.on("initialize", function(data) {
  console.log("initialize: ");
  console.log(data);
});

Here's my full script:

(function(d, script) {
  script = d.createElement('script');
  script.type = 'text/javascript';
  script.async = true;
  script.onload = function(){
    !function(a){if(!a.Localize){a.Localize={};for(var e=["translate","untranslate","phrase","initialize","translatePage","setLanguage","getLanguage","detectLanguage","getAvailableLanguages","untranslatePage","bootstrap","prefetch","on","off","hideWidget","showWidget","getSourceLanguage"],t=0;t<e.length;t++)a.Localize[e[t]]=function(){}}}(window);

    Localize.initialize({
      key: 'xxx',
      rememberLanguage: true,
      saveNewPhrasesFromSource: true,
    });

    Localize.on("initialize", function(data) {
      console.log("initialize: ");
      console.log(data);
    });
  };
  script.src = 'https://global.localizecdn.com/localize.js';
  d.getElementsByTagName('head')[0].appendChild(script);
}(document));

Right now Localize.initialize works and I'm able to see the widget. The only thing not working is Localize.on("initialize", function(data) {. It never fires the console.logs.

Thanks.