You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jul 30, 2018. It is now read-only.
There's a risk of flashing text when the target locale is dynamically set at application startup, causing widgets to render initially with the default bundle, then with the lazy-loaded bundle.
Preloading bundles may help, but there's need for a pattern to avoid this problem when preloading is not an option:
hard to determine which bundles to preload before rendering
preloading all bundles is overkill
@mwistrand Created issue as discussed. Let me know if I missed anything.
Context (gittr convo)
Hello. I have a widget + i18n question. Assuming an app allows setting the locale at startup, what's the recommended way to lazy-load NLS bundles without flashing text (default messages rendered before desired locale bundle loads)? I've modified the TodoMVC example to demonstrate this: https://jcfranco.github.io/examples/todo-mvc/?locale=es
@jcfranco If you are able to load the messages in advance, you can use the setLocaleMessages from @dojo/i18n/i18n module to preload locale-specific messages:
import { setLocaleMessages } from '@dojo/i18n/i18n';
import nlsBundle from './nls/main';
asyncLoadBundle().then(messages => {
setLocaleMessages(nlsBundle, messages, locale);
});
That associates the bundle with the messages for the specified locale, with the result that it uses those messages instead of trying to load them with the function in the locales object map.
is dynamic? Making it hard to determine which bundles to preload before rendering.
has more than one bundle (1 per widget)? preloading all bundles seems overkill.
Are there any patterns that would help with these scenarios?
@jcfranco At the moment, @dojo/widget-core blindly ignores anything that hasn’t been loaded yet and invalidates itself once the locale-specific messages have loaded.
However, we relatively recently updated how locale messages are loaded, so it’s now possible load them synchronously from within bundles themselves. Given that, off the top of my head I don’t see why we couldn’t check whether we receive promises or valid message objects back from the locale functions.
Would you mind opening an issue?
The text was updated successfully, but these errors were encountered:
There's a risk of flashing text when the target locale is dynamically set at application startup, causing widgets to render initially with the default bundle, then with the lazy-loaded bundle.
Preloading bundles may help, but there's need for a pattern to avoid this problem when preloading is not an option:
@mwistrand Created issue as discussed. Let me know if I missed anything.
Context (gittr convo)
The text was updated successfully, but these errors were encountered: