Skip to content

Commit b7c79f4

Browse files
committed
fix(Intl): dont when polyfill when Intl is present
1 parent 643de9e commit b7c79f4

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

Intl/setup.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,20 @@ import { addLocaleData } from 'react-intl';
1616

1717
// need Intl polyfill, Intl not supported in Safari
1818
import Intl from 'intl';
19-
global.Intl = Intl;
19+
import areIntlLocalesSupported from 'intl-locales-supported';
20+
21+
if (global.Intl) {
22+
// Determine if the built-in `Intl` has the locale data we need.
23+
if (!areIntlLocalesSupported(enabledLanguages)) {
24+
// `Intl` exists, but it doesn't have the data we need, so load the
25+
// polyfill and patch the constructors we need with the polyfill's.
26+
global.Intl.NumberFormat = Intl.NumberFormat;
27+
global.Intl.DateTimeFormat = Intl.DateTimeFormat;
28+
}
29+
} else {
30+
// No `Intl`, so use and load the polyfill.
31+
global.Intl = Intl;
32+
}
2033

2134
// use this to allow nested messages, taken from docs:
2235
// https://github.com/yahoo/react-intl/wiki/Upgrade-Guide#flatten-messages-object

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"cuid": "^1.3.8",
3939
"express": "^4.13.4",
4040
"intl": "^1.2.4",
41+
"intl-locales-supported": "^1.0.0",
4142
"isomorphic-fetch": "^2.2.1",
4243
"limax": "^1.3.0",
4344
"mongoose": "^4.4.20",

0 commit comments

Comments
 (0)