Code Monkey home page Code Monkey logo

Comments (10)

paulguz avatar paulguz commented on September 22, 2024

Yes, I see this too, intermittently. I think this is a knock-on from the fix for #48 and #52 made back in February which made loading of the properties files asynchronous at all times.

A workaround for now would be to set gAsyncResourceLoading to false to load the files synchronously. You'll get a "Synchronous XMLHttpRequest" warning in Chrome, but it's only a temporary measure until there's a fix for this.

from webl10n.

rhasan516 avatar rhasan516 commented on September 22, 2024

Thanks :) my team member told me this workaround works for now.

from webl10n.

paulguz avatar paulguz commented on September 22, 2024

SIlly me. On second thoughts, this isn't a bug.

Please see the comment above gAsyncResourceLoading in the source (which I didn't read before):

Synchronously loading l10n resources significantly minimizes flickering
from displaying the app with non-localized strings and then updating the
strings. Although this will block all script execution on this page, we
expect that the l10n resources are available locally on flash-storage.

As synchronous XHR is generally considered as a bad idea, we're still
loading l10n resources asynchronously -- but we keep this in a setting,
just in case... and applications using this library should hide their
content until the `localized' event happens.

So, start your application inside of an event handler for 'localized'. In my case, I have a Backbone application using require.js, so I start my application like so:

document.addEventListener('localized', function () {
    require(["app"], function (app) {
        Backbone.history.start();
    });
});

from webl10n.

Rob--W avatar Rob--W commented on September 22, 2024

Use .ready instead of the event. This ensures that the callback is called even if the event has already been triggered.

document.webL10n.ready(function() {
   require(['app'], function (app) { Backbone.history.start(); });
});

from webl10n.

paulguz avatar paulguz commented on September 22, 2024

Thanks Rob. That means this also works (which I prefer, as require is pretty fundamental to the operation of the application!)

    require(["app"], function (app) {
        document.webL10n.ready(function () { //wait until l10n has finished loading resources
            Backbone.history.start();
        });
    });

from webl10n.

paulguz avatar paulguz commented on September 22, 2024

Hmm, I thought webL10n.ready() was working, but it seems not - I'm still seeing the "undefined" warnings from time to time. I've reverted to using the localized event.

from webl10n.

Rob--W avatar Rob--W commented on September 22, 2024

@paulguz I've submitted a patch for your issue, could you check whether it solves your problem, and report back?

from webl10n.

paulguz avatar paulguz commented on September 22, 2024

@Rob--W Yes, that does seem to have made a difference. However, it only works if I put my require statement inside the ready() call; if I put the ready call inside the require(), I still see the warnings. So, this works:

document.webL10n.ready(function () { //wait until l10n has finished loading resources
      require(["app"], function (app) {
      Backbone.history.start();
    });
});

But this doesn't:

require(["app"], function (app) {
   document.webL10n.ready(function () { //wait until l10n has finished loading resources
        Backbone.history.start();
    });
});

Thanks.

from webl10n.

Rob--W avatar Rob--W commented on September 22, 2024

@paulguz I have added another commit to #70, assuming that you're loading additional localization files using loadLocale. If that does not solve your issue, could you share a minimal project that demonstrates your problem?

from webl10n.

paulguz avatar paulguz commented on September 22, 2024

Hello again, after a whole year. I've been sidetracked in that time, but found myself looking at this again recently after upgrading dependencies in my project.

It appears that the last commit by @Rob--W has reintroduced the console warnings.

For the record, I'm not using loadLocale.

Unfortunately I'm too busy right now to put together a sample project.

from webl10n.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.