2021-08-05 12:11:45 -04:00
|
|
|
// this file should only be `required` in the format-time
|
|
|
|
// when Intl.RelativeTimeFormat is not available (Safari < 14), but
|
|
|
|
// we're not currently able to do the code splitting in www, and it
|
|
|
|
// is always included. To reduce the amount of data that's loaded limit
|
|
|
|
// the number of languages loaded to just the top few that are still using
|
|
|
|
// safari <14. These seven account for most uses.
|
|
|
|
// relativetimeformat depends on locale which also needs to be polyfilled in
|
|
|
|
// safari <14
|
|
|
|
// The plural rules is required for safari 12.
|
|
|
|
import {shouldPolyfill as shouldPolyfillLocale} from '@formatjs/intl-locale/should-polyfill';
|
2021-08-05 17:56:32 -04:00
|
|
|
import {shouldPolyfill as shouldPolyfillRelativeTimeFormat} from '@formatjs/intl-relativetimeformat/should-polyfill';
|
2021-08-05 12:11:45 -04:00
|
|
|
import {shouldPolyfill as shouldPolyfillPluralRules} from '@formatjs/intl-pluralrules/should-polyfill';
|
2021-08-05 17:56:32 -04:00
|
|
|
/**
|
|
|
|
* polyfill all the parts needed from intl
|
|
|
|
* @param {string} locale currently selected locale
|
|
|
|
* @return {Promise} returns a promise that resolves when everything is loaded
|
|
|
|
*/
|
|
|
|
const intlPolyfill = async function (locale) {
|
|
|
|
if (!(shouldPolyfillLocale() ||
|
|
|
|
shouldPolyfillPluralRules(locale) ||
|
|
|
|
shouldPolyfillRelativeTimeFormat(locale))) {
|
|
|
|
console.log('NOT polyfilling');
|
|
|
|
return;
|
|
|
|
}
|
2021-08-05 12:11:45 -04:00
|
|
|
|
2021-08-05 17:56:32 -04:00
|
|
|
if (shouldPolyfillRelativeTimeFormat(locale)) {
|
|
|
|
await import('@formatjs/intl-relativetimeformat/polyfill');
|
|
|
|
}
|
2021-08-05 12:11:45 -04:00
|
|
|
|
2021-08-05 17:56:32 -04:00
|
|
|
if (shouldPolyfillPluralRules(locale)) {
|
|
|
|
await import('@formatjs/intl-pluralrules/polyfill');
|
|
|
|
}
|
2021-08-05 12:11:45 -04:00
|
|
|
|
2021-08-05 17:56:32 -04:00
|
|
|
if (shouldPolyfillLocale(locale)) {
|
|
|
|
await import('@formatjs/intl-locale/polyfill');
|
|
|
|
}
|
2021-08-05 12:11:45 -04:00
|
|
|
|
2021-08-05 17:56:32 -04:00
|
|
|
switch (locale) {
|
2021-08-05 12:11:45 -04:00
|
|
|
case 'ar':
|
2021-08-05 17:56:32 -04:00
|
|
|
await import('@formatjs/intl-relativetimeformat/locale-data/ar');
|
|
|
|
await import('@formatjs/intl-pluralrules/locale-data/ar');
|
|
|
|
break;
|
2021-08-05 12:11:45 -04:00
|
|
|
case 'es':
|
|
|
|
case 'es-419':
|
2021-08-05 17:56:32 -04:00
|
|
|
await import('@formatjs/intl-relativetimeformat/locale-data/es');
|
|
|
|
await import('@formatjs/intl-pluralrules/locale-data/es');
|
|
|
|
break;
|
2021-08-05 12:11:45 -04:00
|
|
|
case 'fr':
|
2021-08-05 17:56:32 -04:00
|
|
|
await import('@formatjs/intl-relativetimeformat/locale-data/fr');
|
|
|
|
await import('@formatjs/intl-pluralrules/locale-data/fr');
|
|
|
|
break;
|
2021-08-05 12:11:45 -04:00
|
|
|
case 'ja':
|
2021-08-05 17:56:32 -04:00
|
|
|
await import('@formatjs/intl-relativetimeformat/locale-data/ja');
|
|
|
|
await import('@formatjs/intl-pluralrules/locale-data/ja');
|
|
|
|
break;
|
2021-08-05 12:11:45 -04:00
|
|
|
case 'tr':
|
2021-08-05 17:56:32 -04:00
|
|
|
await import('@formatjs/intl-relativetimeformat/locale-data/tr');
|
|
|
|
await import('@formatjs/intl-pluralrules/locale-data/tr');
|
|
|
|
break;
|
2021-08-05 12:11:45 -04:00
|
|
|
case 'zh':
|
|
|
|
case 'zh-CN':
|
|
|
|
case 'zh-TW':
|
2021-08-05 17:56:32 -04:00
|
|
|
await import('@formatjs/intl-relativetimeformat/locale-data/zh');
|
|
|
|
await import('@formatjs/intl-pluralrules/locale-data/zh');
|
|
|
|
break;
|
2021-08-05 12:11:45 -04:00
|
|
|
default:
|
2021-08-05 17:56:32 -04:00
|
|
|
await import('@formatjs/intl-relativetimeformat/locale-data/en');
|
|
|
|
await import('@formatjs/intl-pluralrules/locale-data/en');
|
|
|
|
break;
|
2021-08-05 12:11:45 -04:00
|
|
|
}
|
2021-08-05 17:56:32 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
export default intlPolyfill;
|