Skip to content

Commit d16dd06

Browse files
committed
fix(intl): add intl polyfill to support pt-BR locale
1 parent 54c68d6 commit d16dd06

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/index.js

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
'use strict'
88

9+
// Node.js i18n support
10+
require('./intl')
11+
912
// template render function
1013
const render = require('./lib/render')
1114

src/intl.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'use strict'
2+
3+
let areIntlLocalesSupported = require('intl-locales-supported')
4+
if (typeof areIntlLocalesSupported !== 'function' && areIntlLocalesSupported.default) {
5+
areIntlLocalesSupported = areIntlLocalesSupported.default
6+
}
7+
8+
const localesMyAppSupports = [
9+
'en',
10+
'pt-BR'
11+
]
12+
13+
if (global.Intl) {
14+
// Determine if the built-in `Intl` has the locale data we need.
15+
if (!areIntlLocalesSupported(localesMyAppSupports)) {
16+
// `Intl` exists, but it doesn't have the data we need, so load the
17+
// polyfill and patch the constructors we need with the polyfill's.
18+
const IntlPolyfill = require('intl')
19+
Intl.NumberFormat = IntlPolyfill.NumberFormat
20+
Intl.DateTimeFormat = IntlPolyfill.DateTimeFormat
21+
}
22+
} else {
23+
// No `Intl`, so use and load the polyfill.
24+
global.Intl = require('intl')
25+
}

0 commit comments

Comments
 (0)