Skip to content

Instantly share code, notes, and snippets.

@rgalite
Created August 4, 2017 20:13
Show Gist options
  • Select an option

  • Save rgalite/ff3d8726b77e7a18358fa376c33b18c1 to your computer and use it in GitHub Desktop.

Select an option

Save rgalite/ff3d8726b77e7a18358fa376c33b18c1 to your computer and use it in GitHub Desktop.

Revisions

  1. Rudth-Mael Galite created this gist Aug 4, 2017.
    20 changes: 20 additions & 0 deletions i18n.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    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');
    }