react-intl 3.12.0 → 3.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,7 +11,7 @@ interface Props extends FormatPluralOptions {
11
11
  many?: React.ReactNode;
12
12
  children?(value: React.ReactNode): React.ReactElement | null;
13
13
  }
14
- declare const _default: React.ForwardRefExoticComponent<Pick<Props, "children" | "other" | "zero" | "one" | "two" | "few" | "many" | "format" | "localeMatcher" | "type" | "value"> & {
14
+ declare const _default: React.ForwardRefExoticComponent<Pick<Props, "children" | "other" | "zero" | "one" | "two" | "few" | "many" | "localeMatcher" | "format" | "type" | "value"> & {
15
15
  forwardedRef?: ((instance: any) => void) | React.RefObject<any> | null | undefined;
16
16
  } & React.RefAttributes<any>> & {
17
17
  WrappedComponent: React.ComponentType<Props>;
@@ -6,7 +6,6 @@
6
6
  import * as React from 'react';
7
7
  import { Provider } from './injectIntl';
8
8
  import { createError, DEFAULT_INTL_CONFIG, createFormatters, invariantIntlContext, createIntlCache, } from '../utils';
9
- import areIntlLocalesSupported from 'intl-locales-supported';
10
9
  import { formatNumber, formatNumberToParts } from '../formatters/number';
11
10
  import { formatRelativeTime } from '../formatters/relativeTime';
12
11
  import { formatDate, formatTime, formatDateToParts, formatTimeToParts, } from '../formatters/dateTime';
@@ -36,12 +35,10 @@ function processIntlConfig(config) {
36
35
  export function createIntl(config, cache) {
37
36
  const formatters = createFormatters(cache);
38
37
  const resolvedConfig = Object.assign(Object.assign({}, DEFAULT_INTL_CONFIG), config);
39
- if (!resolvedConfig.locale ||
40
- !areIntlLocalesSupported(resolvedConfig.locale)) {
41
- const { locale, defaultLocale, onError } = resolvedConfig;
42
- if (typeof onError === 'function') {
43
- onError(createError(`Missing locale data for locale: "${locale}". ` +
44
- `Using default locale: "${defaultLocale}" as fallback.`));
38
+ const { locale, defaultLocale, onError } = resolvedConfig;
39
+ if (!locale) {
40
+ if (onError) {
41
+ onError(createError(`"locale" was not configured, using "${defaultLocale}" as fallback. See https://github.com/formatjs/react-intl/blob/master/docs/API.md#intlshape for more details`));
45
42
  }
46
43
  // Since there's no registered locale data for `locale`, this will
47
44
  // fallback to the `defaultLocale` to make sure things can render.
@@ -50,6 +47,13 @@ export function createIntl(config, cache) {
50
47
  // each <FormattedMessage> contains a `defaultMessage` prop.
51
48
  resolvedConfig.locale = resolvedConfig.defaultLocale || 'en';
52
49
  }
50
+ else if (!Intl.NumberFormat.supportedLocalesOf(locale).length && onError) {
51
+ onError(createError(`Missing locale data for locale: "${locale}" in Intl.NumberFormat. Using default locale: "${defaultLocale}" as fallback. See https://github.com/formatjs/react-intl/blob/master/docs/Getting-Started.md#runtime-requirements for more details`));
52
+ }
53
+ else if (!Intl.DateTimeFormat.supportedLocalesOf(locale).length &&
54
+ onError) {
55
+ onError(createError(`Missing locale data for locale: "${locale}" in Intl.DateTimeFormat. Using default locale: "${defaultLocale}" as fallback. See https://github.com/formatjs/react-intl/blob/master/docs/Getting-Started.md#runtime-requirements for more details`));
56
+ }
53
57
  return Object.assign(Object.assign({}, resolvedConfig), { formatters, formatNumber: formatNumber.bind(null, resolvedConfig, formatters.getNumberFormat), formatNumberToParts: formatNumberToParts.bind(null, resolvedConfig, formatters.getNumberFormat), formatRelativeTime: formatRelativeTime.bind(null, resolvedConfig, formatters.getRelativeTimeFormat), formatDate: formatDate.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatDateToParts: formatDateToParts.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatTime: formatTime.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatTimeToParts: formatTimeToParts.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatPlural: formatPlural.bind(null, resolvedConfig, formatters.getPluralRules), formatMessage: formatMessage.bind(null, resolvedConfig, formatters), formatHTMLMessage: formatHTMLMessage.bind(null, resolvedConfig, formatters), formatList: formatList.bind(null, resolvedConfig, formatters.getListFormat), formatDisplayName: formatDisplayName.bind(null, resolvedConfig, formatters.getDisplayNames) });
54
58
  }
55
59
  export default class IntlProvider extends React.PureComponent {
package/lib/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
2
  export * from './types';
3
- export { defineMessages } from '@formatjs/macro';
3
+ export declare function defineMessages<T, U extends Record<string, T>>(msgs: U): U;
4
4
  import { CustomFormatConfig } from './types';
5
5
  import { UnifiedNumberFormatOptions } from '@formatjs/intl-unified-numberformat';
6
6
  import { IntlListFormatOptions } from '@formatjs/intl-listformat';
package/lib/index.js CHANGED
@@ -1,4 +1,6 @@
1
- export { defineMessages } from '@formatjs/macro';
1
+ export function defineMessages(msgs) {
2
+ return msgs;
3
+ }
2
4
  import { createFormattedComponent, createFormattedDateTimePartsComponent, } from './components/createFormattedComponent';
3
5
  export { default as injectIntl, Provider as RawIntlProvider, Context as IntlContext, } from './components/injectIntl';
4
6
  export { default as useIntl } from './components/useIntl';
@@ -1,4 +1,3 @@
1
- import { defineMessages } from '@formatjs/macro';
2
1
  import { DisplayNames } from '@formatjs/intl-displaynames';
3
2
  import { DisplayNamesOptions } from '@formatjs/intl-displaynames';
4
3
  import { DisplayNamesOptions as DisplayNamesOptions_2 } from '@formatjs/intl-displaynames/lib';
@@ -33,7 +32,8 @@ export declare interface CustomFormats extends Partial<Formats> {
33
32
  }
34
33
 
35
34
  declare const DEFAULT_INTL_CONFIG: Pick<IntlConfig, 'formats' | 'messages' | 'timeZone' | 'textComponent' | 'defaultLocale' | 'defaultFormats' | 'onError'>;
36
- export { defineMessages }
35
+
36
+ export declare function defineMessages<T, U extends Record<string, T>>(msgs: U): U;
37
37
 
38
38
  export declare type FormatDateOptions = Exclude<Intl.DateTimeFormatOptions, 'localeMatcher'> & CustomFormatConfig;
39
39
 
@@ -91,7 +91,7 @@ export declare const FormattedNumberParts: React.FC<Formatter['formatNumber'] &
91
91
  children(val: Intl.NumberFormatPart[]): React.ReactElement | null;
92
92
  }>;
93
93
 
94
- export declare const FormattedPlural: React.ForwardRefExoticComponent<Pick<Props_2, "children" | "other" | "zero" | "one" | "two" | "few" | "many" | "format" | "localeMatcher" | "type" | "value"> & {
94
+ export declare const FormattedPlural: React.ForwardRefExoticComponent<Pick<Props_2, "children" | "other" | "zero" | "one" | "two" | "few" | "many" | "localeMatcher" | "format" | "type" | "value"> & {
95
95
  forwardedRef?: ((instance: any) => void) | React.RefObject<any> | null | undefined;
96
96
  } & React.RefAttributes<any>> & {
97
97
  WrappedComponent: React.ComponentType<Props_2>;
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.7.1"
8
+ "packageVersion": "7.7.8"
9
9
  }
10
10
  ]
11
11
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-intl",
3
- "version": "3.12.0",
3
+ "version": "3.12.1",
4
4
  "description": "Internationalize React apps. This library provides React components and an API to format dates, numbers, and strings, including pluralization and handling translations.",
5
5
  "keywords": [
6
6
  "intl",
@@ -132,50 +132,48 @@
132
132
  "sideEffects": false,
133
133
  "dependencies": {
134
134
  "@formatjs/intl-displaynames": "^1.2.0",
135
- "@formatjs/intl-listformat": "^1.3.7",
136
- "@formatjs/intl-relativetimeformat": "^4.5.7",
137
- "@formatjs/intl-unified-numberformat": "^3.0.4",
138
- "@formatjs/intl-utils": "^2.0.4",
139
- "@formatjs/macro": "^0.2.6",
135
+ "@formatjs/intl-listformat": "^1.4.1",
136
+ "@formatjs/intl-relativetimeformat": "^4.5.9",
137
+ "@formatjs/intl-unified-numberformat": "^3.2.0",
138
+ "@formatjs/intl-utils": "^2.2.0",
140
139
  "@types/hoist-non-react-statics": "^3.3.1",
141
140
  "@types/invariant": "^2.2.31",
142
- "hoist-non-react-statics": "^3.3.1",
143
- "intl-format-cache": "^4.2.19",
144
- "intl-locales-supported": "^1.8.4",
145
- "intl-messageformat": "^7.8.2",
146
- "intl-messageformat-parser": "^3.6.2",
141
+ "hoist-non-react-statics": "^3.3.2",
142
+ "intl-format-cache": "^4.2.21",
143
+ "intl-messageformat": "^7.8.4",
144
+ "intl-messageformat-parser": "^3.6.4",
147
145
  "shallow-equal": "^1.2.1"
148
146
  },
149
147
  "peerDependencies": {
150
148
  "react": "^16.3.0"
151
149
  },
152
150
  "devDependencies": {
153
- "@babel/core": "^7.7.7",
154
- "@babel/node": "^7.7.7",
155
- "@babel/plugin-proposal-class-properties": "^7.7.4",
156
- "@babel/plugin-transform-modules-commonjs": "^7.7.5",
157
- "@babel/preset-env": "^7.7.7",
158
- "@babel/preset-react": "^7.7.4",
159
- "@formatjs/intl-pluralrules": "^1.5.0",
160
- "@microsoft/api-documenter": "^7.7.3",
161
- "@microsoft/api-extractor": "^7.7.1",
151
+ "@babel/core": "^7.8.4",
152
+ "@babel/node": "^7.8.4",
153
+ "@babel/plugin-proposal-class-properties": "^7.8.3",
154
+ "@babel/plugin-transform-modules-commonjs": "^7.8.3",
155
+ "@babel/preset-env": "^7.8.4",
156
+ "@babel/preset-react": "^7.8.3",
157
+ "@formatjs/intl-pluralrules": "^1.5.2",
158
+ "@microsoft/api-documenter": "^7.7.12",
159
+ "@microsoft/api-extractor": "^7.7.8",
162
160
  "@types/benchmark": "^1.0.31",
163
161
  "@types/enzyme": "^3.10.4",
164
- "@types/jest": "^24.0.25",
162
+ "@types/jest": "^24.9.1",
165
163
  "@types/prop-types": "^15.7.3",
166
- "@types/react": "^16.9.17",
167
- "@types/react-dom": "^16.9.4",
168
- "@typescript-eslint/eslint-plugin": "^2.15.0",
169
- "@typescript-eslint/parser": "^2.15.0",
164
+ "@types/react": "^16.9.19",
165
+ "@types/react-dom": "^16.9.5",
166
+ "@typescript-eslint/eslint-plugin": "^2.19.0",
167
+ "@typescript-eslint/parser": "^2.19.0",
170
168
  "babel-jest": "^24.9.0",
171
169
  "benchmark": "^2.1.0",
172
- "core-js": "^3.6.2",
170
+ "core-js": "^3.6.4",
173
171
  "cross-env": "^6.0.3",
174
172
  "enzyme": "^3.11.0",
175
173
  "enzyme-adapter-react-16": "^1.15.2",
176
- "enzyme-to-json": "^3.4.3",
174
+ "enzyme-to-json": "^3.4.4",
177
175
  "eslint": "^6.8.0",
178
- "eslint-plugin-react": "^7.17.0",
176
+ "eslint-plugin-react": "^7.18.3",
179
177
  "fs-extra": "^8.1.0",
180
178
  "full-icu": "^1.3.0",
181
179
  "glob": "^7.1.6",
@@ -187,19 +185,19 @@
187
185
  "prettier": "^1.19.1",
188
186
  "react": "^16.12.0",
189
187
  "react-dom": "^16.12.0",
190
- "rimraf": "^3.0.0",
191
- "rollup": "^1.29.0",
188
+ "rimraf": "^3.0.1",
189
+ "rollup": "^1.31.0",
192
190
  "rollup-plugin-babel": "^4.3.3",
193
191
  "rollup-plugin-commonjs": "^10.1.0",
194
192
  "rollup-plugin-node-resolve": "^5.2.0",
195
193
  "rollup-plugin-replace": "^2.0.0",
196
194
  "rollup-plugin-typescript2": "^0.25.3",
197
195
  "rollup-plugin-uglify": "^6.0.4",
198
- "standard-version": "^7.0.1",
196
+ "standard-version": "^7.1.0",
199
197
  "ts-jest": "^24.3.0",
200
- "ts-node": "^8.5.4",
198
+ "ts-node": "^8.6.2",
201
199
  "tslib": "^1.9.3",
202
- "typescript": "^3.7.0"
200
+ "typescript": "^3.7.5"
203
201
  },
204
202
  "scripts": {
205
203
  "benchmark": "cross-env NODE_ENV=production TS_NODE_PROJECT=./tsconfig.cjs.json ts-node test/perf/index.tsx",
@@ -14,7 +14,6 @@ import {
14
14
  createIntlCache,
15
15
  } from '../utils';
16
16
  import {IntlConfig, IntlShape, Omit, IntlCache} from '../types';
17
- import areIntlLocalesSupported from 'intl-locales-supported';
18
17
  import {formatNumber, formatNumberToParts} from '../formatters/number';
19
18
  import {formatRelativeTime} from '../formatters/relativeTime';
20
19
  import {
@@ -80,26 +79,36 @@ export function createIntl(
80
79
  ): IntlShape {
81
80
  const formatters = createFormatters(cache);
82
81
  const resolvedConfig = {...DEFAULT_INTL_CONFIG, ...config};
83
- if (
84
- !resolvedConfig.locale ||
85
- !areIntlLocalesSupported(resolvedConfig.locale)
86
- ) {
87
- const {locale, defaultLocale, onError} = resolvedConfig;
88
- if (typeof onError === 'function') {
82
+ const {locale, defaultLocale, onError} = resolvedConfig;
83
+ if (!locale) {
84
+ if (onError) {
89
85
  onError(
90
86
  createError(
91
- `Missing locale data for locale: "${locale}". ` +
92
- `Using default locale: "${defaultLocale}" as fallback.`
87
+ `"locale" was not configured, using "${defaultLocale}" as fallback. See https://github.com/formatjs/react-intl/blob/master/docs/API.md#intlshape for more details`
93
88
  )
94
89
  );
95
90
  }
96
-
97
91
  // Since there's no registered locale data for `locale`, this will
98
92
  // fallback to the `defaultLocale` to make sure things can render.
99
93
  // The `messages` are overridden to the `defaultProps` empty object
100
94
  // to maintain referential equality across re-renders. It's assumed
101
95
  // each <FormattedMessage> contains a `defaultMessage` prop.
102
96
  resolvedConfig.locale = resolvedConfig.defaultLocale || 'en';
97
+ } else if (!Intl.NumberFormat.supportedLocalesOf(locale).length && onError) {
98
+ onError(
99
+ createError(
100
+ `Missing locale data for locale: "${locale}" in Intl.NumberFormat. Using default locale: "${defaultLocale}" as fallback. See https://github.com/formatjs/react-intl/blob/master/docs/Getting-Started.md#runtime-requirements for more details`
101
+ )
102
+ );
103
+ } else if (
104
+ !Intl.DateTimeFormat.supportedLocalesOf(locale).length &&
105
+ onError
106
+ ) {
107
+ onError(
108
+ createError(
109
+ `Missing locale data for locale: "${locale}" in Intl.DateTimeFormat. Using default locale: "${defaultLocale}" as fallback. See https://github.com/formatjs/react-intl/blob/master/docs/Getting-Started.md#runtime-requirements for more details`
110
+ )
111
+ );
103
112
  }
104
113
  return {
105
114
  ...resolvedConfig,
package/src/index.ts CHANGED
@@ -5,7 +5,9 @@
5
5
  */
6
6
  import * as React from 'react';
7
7
  export * from './types';
8
- export {defineMessages} from '@formatjs/macro';
8
+ export function defineMessages<T, U extends Record<string, T>>(msgs: U): U {
9
+ return msgs;
10
+ }
9
11
  import {
10
12
  createFormattedComponent,
11
13
  createFormattedDateTimePartsComponent,