How to know if polyfill locale data exists or needs to be trimmed to base? #3248
-
Hello, I'm dynamically importing the polyfill for Let's say users locale is 'en-US' or 'ru-RU', how do I know that I need to trim them down to 'en' or 'ru' respectively when importing a file from the locale-data folder, but do not trim 'en-GB'? If I don't trim certain locales then the following code will error out, but manually listing locales for all the available files in the switch statement is not feasible. if ((await import('@formatjs/intl-displaynames/should-polyfill')).shouldPolyfill(locale)) {
try {
await import(
// webpackChunkName: "intlpolyfill-display"
'@formatjs/intl-displaynames/polyfill'
);
// How to load en in case of locale="en-US"?
await import(
// webpackChunkName: "intlpolyfill-display-[request]"
`@formatjs/intl-displaynames/locale-data/${locale}.js`
);
} catch (error) {
console.error('Failed to load intl-displaynames polyfill', error);
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Thanks for reporting! We'll take a look asap. Created #3255 |
Beta Was this translation helpful? Give feedback.
Thanks for reporting! We'll take a look asap.
As a workaround we do have https://formatjs.io/docs/polyfills/intl-localematcher that handles locale negotiation which would work in this scenario.
Created #3255