Skip to content

Instantly share code, notes, and snippets.

@rgalite
Created August 4, 2017 20:13
Show Gist options
  • Save rgalite/ff3d8726b77e7a18358fa376c33b18c1 to your computer and use it in GitHub Desktop.
Save rgalite/ff3d8726b77e7a18358fa376c33b18c1 to your computer and use it in GitHub Desktop.
Make node accept more locales
import areIntlLocalesSupported from 'intl-locales-supported'
const localesMyAppSupports = [
'fr',
'en',
]
if (global.Intl) {
// Determine if the built-in `Intl` has the locale data we need.
if (!areIntlLocalesSupported(localesMyAppSupports)) {
// `Intl` exists, but it doesn't have the data we need, so load the
// polyfill and patch the constructors we need with the polyfill's.
var IntlPolyfill = require('intl');
Intl.NumberFormat = IntlPolyfill.NumberFormat;
Intl.DateTimeFormat = IntlPolyfill.DateTimeFormat;
}
} else {
// No `Intl`, so use and load the polyfill.
global.Intl = require('intl');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment