File tree Expand file tree Collapse file tree 5 files changed +16
-12
lines changed Expand file tree Collapse file tree 5 files changed +16
-12
lines changed Original file line number Diff line number Diff line change 1
1
import 'core-js/stable' ;
2
2
import '@formatjs/intl-pluralrules/polyfill' ;
3
- import '@formatjs/intl-relativetimeformat/polyfill' ;
4
3
import * as React from 'react' ;
5
4
import * as ReactDOM from 'react-dom' ;
6
5
import Timezone from './TimeZone' ;
Original file line number Diff line number Diff line change 3
3
* Copyrights licensed under the New BSD License.
4
4
* See the accompanying LICENSE file for terms.
5
5
*/
6
-
6
+ import '@formatjs/intl-relativetimeformat/polyfill' ;
7
7
import * as React from 'react' ;
8
8
import { Context } from './injectIntl' ;
9
9
import { FormatRelativeTimeOptions } from '../types' ;
Original file line number Diff line number Diff line change @@ -12,6 +12,13 @@ export function formatPlural(
12
12
value : Parameters < IntlFormatters [ 'formatPlural' ] > [ 0 ] ,
13
13
options : Parameters < IntlFormatters [ 'formatPlural' ] > [ 1 ] = { }
14
14
) {
15
+ if ( ! Intl . PluralRules ) {
16
+ onError (
17
+ createError ( `Intl.PluralRules is not available in this environment.
18
+ Try polyfilling it using "@formatjs/intl-pluralrules"
19
+ ` )
20
+ ) ;
21
+ }
15
22
let filteredOptions = filterProps ( options , PLURAL_FORMAT_OPTIONS ) ;
16
23
17
24
try {
Original file line number Diff line number Diff line change @@ -39,6 +39,14 @@ export function formatRelativeTime(
39
39
if ( ! unit ) {
40
40
unit = 'second' ;
41
41
}
42
+ const RelativeTimeFormat = ( Intl as any ) . RelativeTimeFormat ;
43
+ if ( ! RelativeTimeFormat ) {
44
+ config . onError (
45
+ createError ( `Intl.RelativeTimeFormat is not available in this environment.
46
+ Try polyfilling it using "@formatjs/intl-relativetimeformat"
47
+ ` )
48
+ ) ;
49
+ }
42
50
try {
43
51
return getFormatter ( config , getRelativeTimeFormat , options ) . format (
44
52
value ,
Original file line number Diff line number Diff line change @@ -112,16 +112,6 @@ export function createIntlCache(): IntlCache {
112
112
*/
113
113
export function createFormatters ( cache : IntlCache = createIntlCache ( ) ) {
114
114
const RelativeTimeFormat = ( Intl as any ) . RelativeTimeFormat ;
115
- if ( ! RelativeTimeFormat ) {
116
- throw new Error ( `Intl.RelativeTimeFormat is not available in this environment.
117
- Try polyfilling it using "@formatjs/intl-relativetimeformat"
118
- ` ) ;
119
- }
120
- if ( ! Intl . PluralRules ) {
121
- throw new Error ( `Intl.PluralRules is not available in this environment.
122
- Try polyfilling it using "@formatjs/intl-pluralrules"
123
- ` ) ;
124
- }
125
115
return {
126
116
getDateTimeFormat : memoizeIntlConstructor (
127
117
Intl . DateTimeFormat ,
You can’t perform that action at this time.
0 commit comments