From e023d60be7a92d78b21cfab01491a725594bac19 Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Thu, 30 Sep 2021 16:43:46 +0200 Subject: [PATCH] exclude a bunch of polyfill locales (#10111) --- src/common/translations/localize.ts | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/common/translations/localize.ts b/src/common/translations/localize.ts index 49f7e1d1bc..c6efe3ea6b 100644 --- a/src/common/translations/localize.ts +++ b/src/common/translations/localize.ts @@ -15,8 +15,6 @@ export interface FormatsType { time: FormatType; } -let loadedPolyfillLocale: Set | undefined; - const polyfillPluralRules = shouldPolyfillPluralRules(); const polyfillRelativeTime = shouldPolyfillRelativeTime(); const polyfillDateTime = shouldPolyfillDateTime(); @@ -41,7 +39,6 @@ let polyfillLoaded = polyfills.length === 0; export const polyfillsLoaded = polyfillLoaded ? undefined : Promise.all(polyfills).then(() => { - loadedPolyfillLocale = new Set(); polyfillLoaded = true; // Load English so it becomes the default return loadPolyfillLocales("en"); @@ -132,19 +129,28 @@ export const computeLocalize = async ( }; export const loadPolyfillLocales = async (language: string) => { - if (!loadedPolyfillLocale || loadedPolyfillLocale.has(language)) { + if (!polyfillsLoaded) { return; } - loadedPolyfillLocale.add(language); + await polyfillsLoaded; try { if (polyfillPluralRules) { - await import(`@formatjs/intl-pluralrules/locale-data/${language}`); + await import( + /* webpackExclude: /.+-.+\.js$/ */ + `@formatjs/intl-pluralrules/locale-data/${language}` + ); } if (polyfillRelativeTime) { - await import(`@formatjs/intl-relativetimeformat/locale-data/${language}`); + await import( + /* webpackExclude: /.+-.+\.js$/ */ + `@formatjs/intl-relativetimeformat/locale-data/${language}` + ); } if (polyfillDateTime) { - await import(`@formatjs/intl-datetimeformat/locale-data/${language}`); + await import( + /* webpackExclude: /.+-.+\.js$/ */ + `@formatjs/intl-datetimeformat/locale-data/${language}` + ); } } catch (_e) { // Ignore