Created
August 4, 2017 20:13
-
-
Save rgalite/ff3d8726b77e7a18358fa376c33b18c1 to your computer and use it in GitHub Desktop.
Make node accept more locales
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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