1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | const DEFAULT_CONSTRUCTORS = [
|
7 | Intl.DateTimeFormat,
|
8 | Intl.NumberFormat,
|
9 | Intl.PluralRules
|
10 | ];
|
11 | export default function areIntlLocalesSupported(
|
12 | locales: string | string[],
|
13 | constructorsToCheck = DEFAULT_CONSTRUCTORS
|
14 | ): boolean {
|
15 | if (typeof Intl === 'undefined') {
|
16 | return false;
|
17 | }
|
18 |
|
19 | if (!locales) {
|
20 | throw new Error('locales must be supplied.');
|
21 | }
|
22 |
|
23 | if (!Array.isArray(locales)) {
|
24 | locales = [locales];
|
25 | }
|
26 |
|
27 | const intlConstructors = constructorsToCheck.filter(Boolean);
|
28 |
|
29 | if (intlConstructors.length === 0) {
|
30 | return false;
|
31 | }
|
32 |
|
33 | return intlConstructors.every(
|
34 | intlConstructor =>
|
35 | intlConstructor.supportedLocalesOf(locales).length === locales.length
|
36 | );
|
37 | }
|