aurelia/i18n

Translations trying to solve keys before json is loaded

bellstrand opened this issue · 12 comments

After updating to v0.5.0, the plugin tries to solve translation keys before the translation files have been loaded when bundling the application.

i18next::translator: missingKey en translation xxx xxx

before we solved the problem with "getAsync: false;" (which now has been removed).
how can we let the translations wait untill our files are loaded with i18next v2?

The problem only occurs when bundling.

Could fix a repo showing the problem if that would help?

I also noticed the same problem yesterday, only when bundling and exporting. What should be bundled and what should be added in the export as static files. What about i18next-xhr-backend?

Untill we find a proper solution i made it work with a temporary fix like this:

import XHR from 'i18next-xhr-backend';

export function configure(aurelia) {
    aurelia.use
        .standardConfiguration()
        .plugin('aurelia-i18n', instance => {
            instance.i18next.use(XHR);
            instance.setup({
                backend: {
                    loadPath: '/locale/{{lng}}/{{ns}}.json'
                },
                ns: ['translation'],
                lng: 'en',
                attributes: ['t', 'i18n'],
                fallbackLng: 'en',
                debug: false
            }).then(() => {
                aurelia.setupI18NFinished = true;
                setRoot(aurelia);
            });
        });

    aurelia.start().then(() => {
        aurelia.setupAureliaFinished = true;
        setRoot(aurelia)
    });
}

function setRoot(aurelia) {
    if(aurelia.setupAureliaFinished && aurelia.setupI18NFinished) {
        aurelia.setRoot();
    }
}

It adds a 5-10ms delay before aurelia.setRoot() gets called for me (running on a remote host on the local network), so i can live with it for now, but would be nice if we had a proper way to address this.

Looks like the problem I have, though the workaround proposed didn't work for me.

I clearly see it call setRoot twice, only the second time succeeding, but still get the missing keys...

when running unbundled, I see the xhr backend initialisation in the console, not so when bundled...

The workaround mentioned in #85 Namespace issues, solved my issue.

Makes sense it is related to bundling. I was not seeing this on my dev laptop, but started seeing it when I deployed to my server. Well at least it shows me text I was too lazy to externalize!

Note: refreshing the page seems to resolve it (likely caching of the files by the browser). I will implement the workarounds.

i18n-messedup

I think I have the same issue with 0.5.0. I found a workaround: downgrade i18next 2.4.x to 2.3.5. From what I understand, 2.4.0 introduced a 10ms timeout before actually loading the resources that prevented aurelia-i18n to work properly.

I fixed my issue with PR #92

@bellstrand can you check whether the latest version has fixed this?

@zewa666 my problems are gone since 0.5.1! 👍

@zewa666 I don't understand but I'm having this same issue with 0.5.2

image

Any ideas?

@AdamWillden you should take a look here #93

@zewa666 Thank you! I had read that but when you pointed me to it I knew I must have missed something ...and this is the info that I was missing: 7cfb404#diff-04c6e90faac2675aa89e2176d2eec7d8

I wonder whether we can intercept that error/warning and add our custom message to inform the user about a potentially missing returned promise