forked from kriasoft/react-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Intl polyfill for unsupported clients [closes kriasoft#639]
- Loading branch information
Showing
4 changed files
with
33 additions
and
4 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// default locale is the first one | ||
export const locales = ['en', 'cs']; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
import areIntlLocalesSupported from 'intl-locales-supported'; | ||
|
||
import { locales } from './clientConfig'; | ||
|
||
if (global.Intl) { | ||
// Determine if the built-in `Intl` has the locale data we need. | ||
if (!areIntlLocalesSupported(locales)) { | ||
// `Intl` exists, but it doesn't have the data we need, so load the | ||
// polyfill and replace the constructors with need with the polyfill's. | ||
require.ensure(['intl', './client'], require => { | ||
const IntlPolyfill = require('intl'); | ||
Intl.NumberFormat = IntlPolyfill.NumberFormat; | ||
Intl.DateTimeFormat = IntlPolyfill.DateTimeFormat; | ||
require('./client'); | ||
}); | ||
} else { | ||
require.ensure(['./client'], require => { | ||
require('./client'); | ||
}); | ||
} | ||
} else { | ||
// No `Intl`, so use and load the polyfill. | ||
require.ensure(['intl', './client'], require => { | ||
global.Intl = require('intl'); | ||
require('./client'); | ||
}); | ||
} |
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
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