UNPKG

1.11 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 (!areIntlLocalesSupported(localesMyAppSupports)) {
19 // `Intl` exists, but it doesn't have the data we need, so load the
20 // polyfill and replace the constructors we need with the polyfill's.
21 require('@formatjs/intl-pluralrules/polyfill');
22 require('@formatjs/intl-pluralrules/dist/locale-data/de'); // Load de
23
24 require('@formatjs/intl-relativetimeformat/polyfill');
25 require('@formatjs/intl-relativetimeformat/dist/locale-data/de'); // Load de
26}
27```