import { shouldPolyfill as shouldPolyfillLocale } from '@formatjs/intl-locale/should-polyfill' ; import { shouldPolyfill as shouldPolyfillNumberFormat } from '@formatjs/intl-numberformat/should-polyfill' ; import { shouldPolyfill as shouldPolyfillDatetimeFormat } from '@formatjs/intl-datetimeformat/should-polyfill' ; import areIntlLocalesSupported from 'intl-locales-supported' ; import { Locale } from '@island.is/shared/types' ; interface PolyfilledIntl { NumberFormat : { polyfilled ? : boolean ; } ; DateTimeFormat : { polyfilled ? : boolean ; } ; } const localeDataModules = { numberFormat : { is : ( ) => import ( '@formatjs/intl-numberformat/locale-data/is' ) , en : ( ) => import ( '@formatjs/intl-numberformat/locale-data/en' ) , } , dateTimeFormat : { is : ( ) => import ( '@formatjs/intl-datetimeformat/locale-data/is' ) , en : ( ) => import ( '@formatjs/intl-datetimeformat/locale-data/en' ) , } , } ; const maybePolyfillLocale = async ( locale ) => { if ( ! areIntlLocalesSupported ( locale ) || shouldPolyfillLocale ( ) ) { return await import ( '@formatjs/intl-locale/polyfill-force' ) ; } } ; const maybePolyfillNumberFormat = async ( locale ) => { if ( ! areIntlLocalesSupported ( locale ) || shouldPolyfillNumberFormat ( ) ) { return await import ( '@formatjs/intl-numberformat/polyfill-force' ) ; } } ; const maybePolyfillDateTimeFormat = async ( locale ) => { if ( ! areIntlLocalesSupported ( locale ) || shouldPolyfillDatetimeFormat ( ) ) { return await import ( '@formatjs/intl-datetimeformat/polyfill-force' ) ; } } ; export async function polyfill ( locale ) { await Promise . all ( [ maybePolyfillLocale ( locale ) , maybePolyfillNumberFormat ( locale ) , maybePolyfillDateTimeFormat ( locale ) , ] ) ; const dataPolyfills = [ ] ; if ( ( Intl as PolyfilledIntl ) . NumberFormat . polyfilled ) { dataPolyfills . push ( localeDataModules . numberFormat [ locale ] ( ) ) ; } if ( ( Intl as PolyfilledIntl ) . DateTimeFormat . polyfilled ) { dataPolyfills . push ( import ( '@formatjs/intl-datetimeformat/add-all-tz' ) ) ; dataPolyfills . push ( localeDataModules . dateTimeFormat [ locale ] ( ) ) ; } await Promise . all ( dataPolyfills ) ; }