UNPKG

1.16 kBMarkdownView Raw
1# intl-locales-supported
2
3Utility to help you determine if your runtime has modern Intl API & locales support. This specifically checks for `Intl.NumberFormat`, `Intl.PluralRules` & `Intl.RelativeTimeFormat` and is being used by `react-intl`.
4
5[![npm Version](https://badgen.net/npm/v/intl-locales-supported)](https://www.npmjs.org/package/intl-locales-supported)
6![size](https://badgen.net/bundlephobia/minzip/intl-locales-supported)
7
8## Usage
9
10```js
11const areIntlLocalesSupported = require('intl-locales-supported');
12
13const localesMyAppSupports = [
14 /* list locales here */
15];
16
17// Determine if the built-in `Intl` has the locale data we need.
18if (
19 !areIntlLocalesSupported(localesMyAppSupports, [
20 Intl.PluralRules,
21 Intl.RelativeTimeFormat,
22 ])
23) {
24 // `Intl` exists, but it doesn't have the data we need, so load the
25 // polyfill and replace the constructors we need with the polyfill's.
26 require('@formatjs/intl-pluralrules/polyfill');
27 require('@formatjs/intl-pluralrules/locale-data/de'); // Load de
28
29 require('@formatjs/intl-relativetimeformat/polyfill');
30 require('@formatjs/intl-relativetimeformat/locale-data/de'); // Load de
31}
32```