Our powerful JS Calendar component


Post by jq123 »

Hi,

We are noticing that in very rare cases the localizations do not get applied. Do we need to wait for the LocaleHelper.applyLocale() promise to resolve?

In the docs, it does not look like we need wait for the promise to resolve. If we don't wait for the Promise to resolve, I'm concerned that the page can be loaded before LocaleHelper.applyLocale finishes applying the localization.

    useEffect(() => {
        LocaleHelper.publishLocale(myLocale);
        LocaleManager.applyLocale(myLocaleName);
    }, []);

Post by marcio »

Hey jq123,

applyLocale returns a Promise, as you can see in the documentation available here https://bryntum.com/products/calendar/docs/api/Core/localization/LocaleManager#function-applyLocale

So yes, you'll need to wait for the function to be resolved to load the page with the correct translation.

Best regards,
Márcio


Post by jq123 »

Hey marcio,

Thanks for the feedback. To resolve the applyLocale Promise, I tried adding a then() in the Promise chain to have some logic that handles when the Promise is resolved. However, I am encountering an error whenever I apply the .then() block. In the sample below, I added a console.log to inspect the resolved value of LocaleManager.applyLocale, but I only receive an error.

Any ideas why? How should we resolve the LocaleHelper.applyLocale Promise?

    useEffect(() => {
        LocaleHelper.publishLocale(myLocale);
        LocaleManager.applyLocale(myLocaleName).then(console.log);
    }, []);

react-dom.production.min.js:189 TypeError: _bryntum_calendar__WEBPACK_IMPORTED_MODULE_1__.LocaleManager.applyLocale(...).then is not a function
    at myPage.js:59:48
    at ic (react-dom.production.min.js:244:332)
    at Ou (react-dom.production.min.js:286:111)
    at uu (react-dom.production.min.js:273:185)
    at ji (react-dom.production.min.js:127:105)
    at react-dom.production.min.js:283:470
    at zu (react-dom.production.min.js:281:398)
    at ou (react-dom.production.min.js:270:269)
    at z (scheduler.production.min.js:13:203)
    at E (scheduler.production.min.js:14:128)

Post by jq123 »

Alternatively, could we do the following? I'm not sure why the .then() does not work.

 useEffect(() => {
        (async () => {
            LocaleHelper.publishLocale(myLocale);
            await LocaleManager.applyLocale(myLocaleName);
        })();
    }, [mergedLocale]);


Post by tasnim »

Hey jq123,

Alternatively, could we do the following?

If this is working for you (it should), then yes, please.

I'm not sure why the .then() does not work.

Can't say without debugging, If you could provide a runnable test case where we could reproduce and debug it?


Post Reply