@formatjs/intl 1.6.6 → 1.7.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.
- package/lib/src/create-intl.d.ts +2 -8
- package/lib/src/create-intl.d.ts.map +1 -1
- package/lib/src/create-intl.js +4 -14
- package/lib/src/dateTime.js +6 -6
- package/lib/src/displayName.js +2 -2
- package/lib/src/error.d.ts +1 -1
- package/lib/src/error.d.ts.map +1 -1
- package/lib/src/error.js +5 -5
- package/lib/src/list.js +2 -2
- package/lib/src/number.js +3 -3
- package/package.json +8 -8
- package/src/create-intl.d.ts +2 -8
- package/src/create-intl.d.ts.map +1 -1
- package/src/create-intl.js +4 -14
- package/src/dateTime.js +5 -5
- package/src/displayName.js +1 -1
- package/src/error.d.ts +1 -1
- package/src/error.d.ts.map +1 -1
- package/src/error.js +5 -5
- package/src/list.js +1 -1
- package/src/number.js +2 -2
package/lib/src/create-intl.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OptionalIntlConfig, IntlCache, IntlShape
|
|
1
|
+
import { OptionalIntlConfig, IntlCache, IntlShape } from './types';
|
|
2
2
|
export interface CreateIntlFn<T = string, C extends OptionalIntlConfig<T> = OptionalIntlConfig<T>, S extends IntlShape<T> = IntlShape<T>> {
|
|
3
3
|
(config: C, cache?: IntlCache): S;
|
|
4
4
|
}
|
|
@@ -7,11 +7,5 @@ export interface CreateIntlFn<T = string, C extends OptionalIntlConfig<T> = Opti
|
|
|
7
7
|
* @param config intl config
|
|
8
8
|
* @param cache cache for formatter instances to prevent memory leak
|
|
9
9
|
*/
|
|
10
|
-
export declare function createIntl<T = string>(config: OptionalIntlConfig<T>, cache?: IntlCache): IntlShape<T
|
|
11
|
-
/**
|
|
12
|
-
* This is not really public, primarily for ember-intl
|
|
13
|
-
* @param messages Additional messages
|
|
14
|
-
*/
|
|
15
|
-
__addMessages(messages: IntlConfig<T>['messages']): void;
|
|
16
|
-
};
|
|
10
|
+
export declare function createIntl<T = string>(config: OptionalIntlConfig<T>, cache?: IntlCache): IntlShape<T>;
|
|
17
11
|
//# sourceMappingURL=create-intl.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-intl.d.ts","sourceRoot":"","sources":["../../../../../../../packages/intl/src/create-intl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,kBAAkB,EAAE,SAAS,EAAE,SAAS,
|
|
1
|
+
{"version":3,"file":"create-intl.d.ts","sourceRoot":"","sources":["../../../../../../../packages/intl/src/create-intl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,kBAAkB,EAAE,SAAS,EAAE,SAAS,EAAC,MAAM,SAAS,CAAC;AAkBjE,MAAM,WAAW,YAAY,CAC3B,CAAC,GAAG,MAAM,EACV,CAAC,SAAS,kBAAkB,CAAC,CAAC,CAAC,GAAG,kBAAkB,CAAC,CAAC,CAAC,EACvD,CAAC,SAAS,SAAS,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC;IAErC,CAAC,MAAM,EAAE,CAAC,EAAE,KAAK,CAAC,EAAE,SAAS,GAAG,CAAC,CAAC;CACnC;AAuBD;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,CAAC,GAAG,MAAM,EACnC,MAAM,EAAE,kBAAkB,CAAC,CAAC,CAAC,EAC7B,KAAK,CAAC,EAAE,SAAS,GAChB,SAAS,CAAC,CAAC,CAAC,CAgGd"}
|
package/lib/src/create-intl.js
CHANGED
|
@@ -8,15 +8,15 @@ import { formatPlural } from './plural';
|
|
|
8
8
|
import { formatMessage } from './message';
|
|
9
9
|
import { formatList } from './list';
|
|
10
10
|
import { formatDisplayName } from './displayName';
|
|
11
|
-
function
|
|
11
|
+
function messagesContainString(messages) {
|
|
12
12
|
var firstMessage = messages
|
|
13
13
|
? messages[Object.keys(messages)[0]]
|
|
14
14
|
: undefined;
|
|
15
|
-
return typeof firstMessage === '
|
|
15
|
+
return typeof firstMessage === 'string';
|
|
16
16
|
}
|
|
17
17
|
function verifyConfigMessages(config) {
|
|
18
18
|
if (config.defaultRichTextElements &&
|
|
19
|
-
|
|
19
|
+
messagesContainString(config.messages || {})) {
|
|
20
20
|
console.warn("[@formatjs/intl] \"defaultRichTextElements\" was specified but \"message\" was not pre-compiled. \nPlease consider using \"@formatjs/cli\" to pre-compile your messages for performance.\nFor more details see https://formatjs.io/docs/getting-started/message-distribution");
|
|
21
21
|
}
|
|
22
22
|
}
|
|
@@ -48,15 +48,5 @@ export function createIntl(config, cache) {
|
|
|
48
48
|
onError(new MissingDataError("Missing locale data for locale: \"" + locale + "\" in Intl.DateTimeFormat. Using default locale: \"" + defaultLocale + "\" as fallback. See https://formatjs.io/docs/react-intl#runtime-requirements for more details"));
|
|
49
49
|
}
|
|
50
50
|
verifyConfigMessages(resolvedConfig);
|
|
51
|
-
return __assign(__assign({}, resolvedConfig), { formatters: 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), formatDateTimeRange: formatDateTimeRange.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), formatList: formatList.bind(null, resolvedConfig, formatters.getListFormat), formatDisplayName: formatDisplayName.bind(null, resolvedConfig, formatters.getDisplayNames)
|
|
52
|
-
var existingMessagesContainAst = messagesContainAst(resolvedConfig.messages);
|
|
53
|
-
var mergingMessagesContainAst = messagesContainAst(messages);
|
|
54
|
-
if (config.onError &&
|
|
55
|
-
((existingMessagesContainAst && !mergingMessagesContainAst) ||
|
|
56
|
-
(!existingMessagesContainAst && mergingMessagesContainAst))) {
|
|
57
|
-
config.onError(new InvalidConfigError("Cannot mix AST & non-AST messages for locale " + resolvedConfig.locale));
|
|
58
|
-
}
|
|
59
|
-
// @ts-expect-error this is fine
|
|
60
|
-
resolvedConfig.messages = __assign(__assign({}, resolvedConfig.messages), messages);
|
|
61
|
-
} });
|
|
51
|
+
return __assign(__assign({}, resolvedConfig), { formatters: 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), formatDateTimeRange: formatDateTimeRange.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), formatList: formatList.bind(null, resolvedConfig, formatters.getListFormat), formatDisplayName: formatDisplayName.bind(null, resolvedConfig, formatters.getDisplayNames) });
|
|
62
52
|
}
|
package/lib/src/dateTime.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __assign } from "tslib";
|
|
2
2
|
import { filterProps, getNamedFormat } from './utils';
|
|
3
|
-
import { IntlError } from './error';
|
|
3
|
+
import { IntlError, IntlErrorCode } from './error';
|
|
4
4
|
var DATE_TIME_FORMAT_OPTIONS = [
|
|
5
5
|
'localeMatcher',
|
|
6
6
|
'formatMatcher',
|
|
@@ -51,7 +51,7 @@ export function formatDate(config, getDateTimeFormat) {
|
|
|
51
51
|
return getFormatter(config, 'date', getDateTimeFormat, options).format(date);
|
|
52
52
|
}
|
|
53
53
|
catch (e) {
|
|
54
|
-
config.onError(new IntlError(
|
|
54
|
+
config.onError(new IntlError(IntlErrorCode.FORMAT_ERROR, 'Error formatting date.', e));
|
|
55
55
|
}
|
|
56
56
|
return String(date);
|
|
57
57
|
}
|
|
@@ -66,7 +66,7 @@ export function formatTime(config, getDateTimeFormat) {
|
|
|
66
66
|
return getFormatter(config, 'time', getDateTimeFormat, options).format(date);
|
|
67
67
|
}
|
|
68
68
|
catch (e) {
|
|
69
|
-
config.onError(new IntlError(
|
|
69
|
+
config.onError(new IntlError(IntlErrorCode.FORMAT_ERROR, 'Error formatting time.', e));
|
|
70
70
|
}
|
|
71
71
|
return String(date);
|
|
72
72
|
}
|
|
@@ -82,7 +82,7 @@ export function formatDateTimeRange(config, getDateTimeFormat) {
|
|
|
82
82
|
return getDateTimeFormat(locale, filteredOptions).formatRange(from, to);
|
|
83
83
|
}
|
|
84
84
|
catch (e) {
|
|
85
|
-
onError(new IntlError(
|
|
85
|
+
onError(new IntlError(IntlErrorCode.FORMAT_ERROR, 'Error formatting date time range.', e));
|
|
86
86
|
}
|
|
87
87
|
return String(from);
|
|
88
88
|
}
|
|
@@ -97,7 +97,7 @@ export function formatDateToParts(config, getDateTimeFormat) {
|
|
|
97
97
|
return getFormatter(config, 'date', getDateTimeFormat, options).formatToParts(date);
|
|
98
98
|
}
|
|
99
99
|
catch (e) {
|
|
100
|
-
config.onError(new IntlError(
|
|
100
|
+
config.onError(new IntlError(IntlErrorCode.FORMAT_ERROR, 'Error formatting date.', e));
|
|
101
101
|
}
|
|
102
102
|
return [];
|
|
103
103
|
}
|
|
@@ -112,7 +112,7 @@ export function formatTimeToParts(config, getDateTimeFormat) {
|
|
|
112
112
|
return getFormatter(config, 'time', getDateTimeFormat, options).formatToParts(date);
|
|
113
113
|
}
|
|
114
114
|
catch (e) {
|
|
115
|
-
config.onError(new IntlError(
|
|
115
|
+
config.onError(new IntlError(IntlErrorCode.FORMAT_ERROR, 'Error formatting time.', e));
|
|
116
116
|
}
|
|
117
117
|
return [];
|
|
118
118
|
}
|
package/lib/src/displayName.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { filterProps } from './utils';
|
|
2
2
|
import { FormatError } from 'intl-messageformat';
|
|
3
|
-
import { IntlError } from './error';
|
|
3
|
+
import { IntlErrorCode, IntlError } from './error';
|
|
4
4
|
var DISPLAY_NAMES_OPTONS = [
|
|
5
5
|
'localeMatcher',
|
|
6
6
|
'style',
|
|
@@ -18,6 +18,6 @@ export function formatDisplayName(_a, getDisplayNames, value, options) {
|
|
|
18
18
|
return getDisplayNames(locale, filteredOptions).of(value);
|
|
19
19
|
}
|
|
20
20
|
catch (e) {
|
|
21
|
-
onError(new IntlError(
|
|
21
|
+
onError(new IntlError(IntlErrorCode.FORMAT_ERROR, 'Error formatting display name.', e));
|
|
22
22
|
}
|
|
23
23
|
}
|
package/lib/src/error.d.ts
CHANGED
package/lib/src/error.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../../../../../../packages/intl/src/error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,iBAAiB,EAAC,MAAM,SAAS,CAAC;AAE1C,
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../../../../../../packages/intl/src/error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,iBAAiB,EAAC,MAAM,SAAS,CAAC;AAE1C,oBAAY,aAAa;IACvB,YAAY,iBAAiB;IAC7B,qBAAqB,0BAA0B;IAC/C,cAAc,mBAAmB;IACjC,YAAY,iBAAiB;IAC7B,mBAAmB,wBAAwB;CAC5C;AAED,qBAAa,SAAS,CACpB,CAAC,SAAS,aAAa,GAAG,aAAa,CAAC,YAAY,CACpD,SAAQ,KAAK;IACb,SAAgB,IAAI,EAAE,CAAC,CAAC;gBAEZ,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,KAAK;CAUxD;AAED,qBAAa,yBAA0B,SAAQ,SAAS,CAAC,aAAa,CAAC,qBAAqB,CAAC;gBAC/E,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,KAAK;CAG/C;AAED,qBAAa,kBAAmB,SAAQ,SAAS,CAAC,aAAa,CAAC,cAAc,CAAC;gBACjE,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,KAAK;CAG/C;AAED,qBAAa,gBAAiB,SAAQ,SAAS,CAAC,aAAa,CAAC,YAAY,CAAC;gBAC7D,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,KAAK;CAG/C;AAED,qBAAa,kBAAmB,SAAQ,SAAS,CAAC,aAAa,CAAC,YAAY,CAAC;IAC3E,SAAgB,UAAU,CAAC,EAAE,iBAAiB,CAAC;gBAE7C,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,UAAU,CAAC,EAAE,iBAAiB,EAC9B,SAAS,CAAC,EAAE,KAAK;CAcpB;AAED,qBAAa,uBAAwB,SAAQ,SAAS,CAAC,aAAa,CAAC,mBAAmB,CAAC;IACvF,SAAgB,UAAU,CAAC,EAAE,iBAAiB,CAAC;gBACnC,UAAU,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM;CAS1D"}
|
package/lib/src/error.js
CHANGED
|
@@ -23,7 +23,7 @@ export { IntlError };
|
|
|
23
23
|
var UnsupportedFormatterError = /** @class */ (function (_super) {
|
|
24
24
|
__extends(UnsupportedFormatterError, _super);
|
|
25
25
|
function UnsupportedFormatterError(message, exception) {
|
|
26
|
-
return _super.call(this,
|
|
26
|
+
return _super.call(this, IntlErrorCode.UNSUPPORTED_FORMATTER, message, exception) || this;
|
|
27
27
|
}
|
|
28
28
|
return UnsupportedFormatterError;
|
|
29
29
|
}(IntlError));
|
|
@@ -31,7 +31,7 @@ export { UnsupportedFormatterError };
|
|
|
31
31
|
var InvalidConfigError = /** @class */ (function (_super) {
|
|
32
32
|
__extends(InvalidConfigError, _super);
|
|
33
33
|
function InvalidConfigError(message, exception) {
|
|
34
|
-
return _super.call(this,
|
|
34
|
+
return _super.call(this, IntlErrorCode.INVALID_CONFIG, message, exception) || this;
|
|
35
35
|
}
|
|
36
36
|
return InvalidConfigError;
|
|
37
37
|
}(IntlError));
|
|
@@ -39,7 +39,7 @@ export { InvalidConfigError };
|
|
|
39
39
|
var MissingDataError = /** @class */ (function (_super) {
|
|
40
40
|
__extends(MissingDataError, _super);
|
|
41
41
|
function MissingDataError(message, exception) {
|
|
42
|
-
return _super.call(this,
|
|
42
|
+
return _super.call(this, IntlErrorCode.MISSING_DATA, message, exception) || this;
|
|
43
43
|
}
|
|
44
44
|
return MissingDataError;
|
|
45
45
|
}(IntlError));
|
|
@@ -47,7 +47,7 @@ export { MissingDataError };
|
|
|
47
47
|
var MessageFormatError = /** @class */ (function (_super) {
|
|
48
48
|
__extends(MessageFormatError, _super);
|
|
49
49
|
function MessageFormatError(message, locale, descriptor, exception) {
|
|
50
|
-
var _this = _super.call(this,
|
|
50
|
+
var _this = _super.call(this, IntlErrorCode.FORMAT_ERROR, message + " \nLocale: " + locale + "\nMessageID: " + (descriptor === null || descriptor === void 0 ? void 0 : descriptor.id) + "\nDefault Message: " + (descriptor === null || descriptor === void 0 ? void 0 : descriptor.defaultMessage) + "\nDescription: " + (descriptor === null || descriptor === void 0 ? void 0 : descriptor.description) + " \n", exception) || this;
|
|
51
51
|
_this.descriptor = descriptor;
|
|
52
52
|
return _this;
|
|
53
53
|
}
|
|
@@ -57,7 +57,7 @@ export { MessageFormatError };
|
|
|
57
57
|
var MissingTranslationError = /** @class */ (function (_super) {
|
|
58
58
|
__extends(MissingTranslationError, _super);
|
|
59
59
|
function MissingTranslationError(descriptor, locale) {
|
|
60
|
-
var _this = _super.call(this,
|
|
60
|
+
var _this = _super.call(this, IntlErrorCode.MISSING_TRANSLATION, "Missing message: \"" + descriptor.id + "\" for locale \"" + locale + "\", using " + (descriptor.defaultMessage ? 'default message' : 'id') + " as fallback.") || this;
|
|
61
61
|
_this.descriptor = descriptor;
|
|
62
62
|
return _this;
|
|
63
63
|
}
|
package/lib/src/list.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { filterProps } from './utils';
|
|
2
2
|
import { FormatError } from 'intl-messageformat';
|
|
3
|
-
import { IntlError } from './error';
|
|
3
|
+
import { IntlError, IntlErrorCode } from './error';
|
|
4
4
|
var LIST_FORMAT_OPTIONS = [
|
|
5
5
|
'localeMatcher',
|
|
6
6
|
'type',
|
|
@@ -47,7 +47,7 @@ export function formatList(_a, getListFormat, values, options) {
|
|
|
47
47
|
}, []);
|
|
48
48
|
}
|
|
49
49
|
catch (e) {
|
|
50
|
-
onError(new IntlError(
|
|
50
|
+
onError(new IntlError(IntlErrorCode.FORMAT_ERROR, 'Error formatting list.', e));
|
|
51
51
|
}
|
|
52
52
|
// @ts-ignore
|
|
53
53
|
return values;
|
package/lib/src/number.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getNamedFormat, filterProps } from './utils';
|
|
2
|
-
import { IntlError } from './error';
|
|
2
|
+
import { IntlError, IntlErrorCode } from './error';
|
|
3
3
|
var NUMBER_FORMAT_OPTIONS = [
|
|
4
4
|
'localeMatcher',
|
|
5
5
|
'style',
|
|
@@ -38,7 +38,7 @@ export function formatNumber(config, getNumberFormat, value, options) {
|
|
|
38
38
|
return getFormatter(config, getNumberFormat, options).format(value);
|
|
39
39
|
}
|
|
40
40
|
catch (e) {
|
|
41
|
-
config.onError(new IntlError(
|
|
41
|
+
config.onError(new IntlError(IntlErrorCode.FORMAT_ERROR, 'Error formatting number.', e));
|
|
42
42
|
}
|
|
43
43
|
return String(value);
|
|
44
44
|
}
|
|
@@ -48,7 +48,7 @@ export function formatNumberToParts(config, getNumberFormat, value, options) {
|
|
|
48
48
|
return getFormatter(config, getNumberFormat, options).formatToParts(value);
|
|
49
49
|
}
|
|
50
50
|
catch (e) {
|
|
51
|
-
config.onError(new IntlError(
|
|
51
|
+
config.onError(new IntlError(IntlErrorCode.FORMAT_ERROR, 'Error formatting number.', e));
|
|
52
52
|
}
|
|
53
53
|
return [];
|
|
54
54
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@formatjs/intl",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.1",
|
|
4
4
|
"description": "Internationalize JS apps. This library provides an API to format dates, numbers, and strings, including pluralization and handling translations.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"intl",
|
|
@@ -29,14 +29,14 @@
|
|
|
29
29
|
"module": "lib/index.js",
|
|
30
30
|
"sideEffects": false,
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@formatjs/ecma402-abstract": "1.5.
|
|
33
|
-
"@formatjs/intl-datetimeformat": "3.2.
|
|
34
|
-
"@formatjs/intl-displaynames": "4.0.
|
|
35
|
-
"@formatjs/intl-listformat": "5.0.
|
|
36
|
-
"@formatjs/intl-relativetimeformat": "8.0.
|
|
32
|
+
"@formatjs/ecma402-abstract": "1.5.4",
|
|
33
|
+
"@formatjs/intl-datetimeformat": "3.2.9",
|
|
34
|
+
"@formatjs/intl-displaynames": "4.0.7",
|
|
35
|
+
"@formatjs/intl-listformat": "5.0.7",
|
|
36
|
+
"@formatjs/intl-relativetimeformat": "8.0.6",
|
|
37
37
|
"fast-memoize": "^2.5.2",
|
|
38
|
-
"intl-messageformat": "9.4.
|
|
39
|
-
"intl-messageformat-parser": "6.3.
|
|
38
|
+
"intl-messageformat": "9.4.9",
|
|
39
|
+
"intl-messageformat-parser": "6.3.4",
|
|
40
40
|
"tslib": "^2.0.1"
|
|
41
41
|
}
|
|
42
42
|
}
|
package/src/create-intl.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OptionalIntlConfig, IntlCache, IntlShape
|
|
1
|
+
import { OptionalIntlConfig, IntlCache, IntlShape } from './types';
|
|
2
2
|
export interface CreateIntlFn<T = string, C extends OptionalIntlConfig<T> = OptionalIntlConfig<T>, S extends IntlShape<T> = IntlShape<T>> {
|
|
3
3
|
(config: C, cache?: IntlCache): S;
|
|
4
4
|
}
|
|
@@ -7,11 +7,5 @@ export interface CreateIntlFn<T = string, C extends OptionalIntlConfig<T> = Opti
|
|
|
7
7
|
* @param config intl config
|
|
8
8
|
* @param cache cache for formatter instances to prevent memory leak
|
|
9
9
|
*/
|
|
10
|
-
export declare function createIntl<T = string>(config: OptionalIntlConfig<T>, cache?: IntlCache): IntlShape<T
|
|
11
|
-
/**
|
|
12
|
-
* This is not really public, primarily for ember-intl
|
|
13
|
-
* @param messages Additional messages
|
|
14
|
-
*/
|
|
15
|
-
__addMessages(messages: IntlConfig<T>['messages']): void;
|
|
16
|
-
};
|
|
10
|
+
export declare function createIntl<T = string>(config: OptionalIntlConfig<T>, cache?: IntlCache): IntlShape<T>;
|
|
17
11
|
//# sourceMappingURL=create-intl.d.ts.map
|
package/src/create-intl.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-intl.d.ts","sourceRoot":"","sources":["../../../../../../packages/intl/src/create-intl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,kBAAkB,EAAE,SAAS,EAAE,SAAS,
|
|
1
|
+
{"version":3,"file":"create-intl.d.ts","sourceRoot":"","sources":["../../../../../../packages/intl/src/create-intl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,kBAAkB,EAAE,SAAS,EAAE,SAAS,EAAC,MAAM,SAAS,CAAC;AAkBjE,MAAM,WAAW,YAAY,CAC3B,CAAC,GAAG,MAAM,EACV,CAAC,SAAS,kBAAkB,CAAC,CAAC,CAAC,GAAG,kBAAkB,CAAC,CAAC,CAAC,EACvD,CAAC,SAAS,SAAS,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC;IAErC,CAAC,MAAM,EAAE,CAAC,EAAE,KAAK,CAAC,EAAE,SAAS,GAAG,CAAC,CAAC;CACnC;AAuBD;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,CAAC,GAAG,MAAM,EACnC,MAAM,EAAE,kBAAkB,CAAC,CAAC,CAAC,EAC7B,KAAK,CAAC,EAAE,SAAS,GAChB,SAAS,CAAC,CAAC,CAAC,CAgGd"}
|
package/src/create-intl.js
CHANGED
|
@@ -11,15 +11,15 @@ var plural_1 = require("./plural");
|
|
|
11
11
|
var message_1 = require("./message");
|
|
12
12
|
var list_1 = require("./list");
|
|
13
13
|
var displayName_1 = require("./displayName");
|
|
14
|
-
function
|
|
14
|
+
function messagesContainString(messages) {
|
|
15
15
|
var firstMessage = messages
|
|
16
16
|
? messages[Object.keys(messages)[0]]
|
|
17
17
|
: undefined;
|
|
18
|
-
return typeof firstMessage === '
|
|
18
|
+
return typeof firstMessage === 'string';
|
|
19
19
|
}
|
|
20
20
|
function verifyConfigMessages(config) {
|
|
21
21
|
if (config.defaultRichTextElements &&
|
|
22
|
-
|
|
22
|
+
messagesContainString(config.messages || {})) {
|
|
23
23
|
console.warn("[@formatjs/intl] \"defaultRichTextElements\" was specified but \"message\" was not pre-compiled. \nPlease consider using \"@formatjs/cli\" to pre-compile your messages for performance.\nFor more details see https://formatjs.io/docs/getting-started/message-distribution");
|
|
24
24
|
}
|
|
25
25
|
}
|
|
@@ -51,16 +51,6 @@ function createIntl(config, cache) {
|
|
|
51
51
|
onError(new error_1.MissingDataError("Missing locale data for locale: \"" + locale + "\" in Intl.DateTimeFormat. Using default locale: \"" + defaultLocale + "\" as fallback. See https://formatjs.io/docs/react-intl#runtime-requirements for more details"));
|
|
52
52
|
}
|
|
53
53
|
verifyConfigMessages(resolvedConfig);
|
|
54
|
-
return tslib_1.__assign(tslib_1.__assign({}, resolvedConfig), { formatters: formatters, formatNumber: number_1.formatNumber.bind(null, resolvedConfig, formatters.getNumberFormat), formatNumberToParts: number_1.formatNumberToParts.bind(null, resolvedConfig, formatters.getNumberFormat), formatRelativeTime: relativeTime_1.formatRelativeTime.bind(null, resolvedConfig, formatters.getRelativeTimeFormat), formatDate: dateTime_1.formatDate.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatDateToParts: dateTime_1.formatDateToParts.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatTime: dateTime_1.formatTime.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatDateTimeRange: dateTime_1.formatDateTimeRange.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatTimeToParts: dateTime_1.formatTimeToParts.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatPlural: plural_1.formatPlural.bind(null, resolvedConfig, formatters.getPluralRules), formatMessage: message_1.formatMessage.bind(null, resolvedConfig, formatters), formatList: list_1.formatList.bind(null, resolvedConfig, formatters.getListFormat), formatDisplayName: displayName_1.formatDisplayName.bind(null, resolvedConfig, formatters.getDisplayNames)
|
|
55
|
-
var existingMessagesContainAst = messagesContainAst(resolvedConfig.messages);
|
|
56
|
-
var mergingMessagesContainAst = messagesContainAst(messages);
|
|
57
|
-
if (config.onError &&
|
|
58
|
-
((existingMessagesContainAst && !mergingMessagesContainAst) ||
|
|
59
|
-
(!existingMessagesContainAst && mergingMessagesContainAst))) {
|
|
60
|
-
config.onError(new error_1.InvalidConfigError("Cannot mix AST & non-AST messages for locale " + resolvedConfig.locale));
|
|
61
|
-
}
|
|
62
|
-
// @ts-expect-error this is fine
|
|
63
|
-
resolvedConfig.messages = tslib_1.__assign(tslib_1.__assign({}, resolvedConfig.messages), messages);
|
|
64
|
-
} });
|
|
54
|
+
return tslib_1.__assign(tslib_1.__assign({}, resolvedConfig), { formatters: formatters, formatNumber: number_1.formatNumber.bind(null, resolvedConfig, formatters.getNumberFormat), formatNumberToParts: number_1.formatNumberToParts.bind(null, resolvedConfig, formatters.getNumberFormat), formatRelativeTime: relativeTime_1.formatRelativeTime.bind(null, resolvedConfig, formatters.getRelativeTimeFormat), formatDate: dateTime_1.formatDate.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatDateToParts: dateTime_1.formatDateToParts.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatTime: dateTime_1.formatTime.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatDateTimeRange: dateTime_1.formatDateTimeRange.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatTimeToParts: dateTime_1.formatTimeToParts.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatPlural: plural_1.formatPlural.bind(null, resolvedConfig, formatters.getPluralRules), formatMessage: message_1.formatMessage.bind(null, resolvedConfig, formatters), formatList: list_1.formatList.bind(null, resolvedConfig, formatters.getListFormat), formatDisplayName: displayName_1.formatDisplayName.bind(null, resolvedConfig, formatters.getDisplayNames) });
|
|
65
55
|
}
|
|
66
56
|
exports.createIntl = createIntl;
|
package/src/dateTime.js
CHANGED
|
@@ -55,7 +55,7 @@ function formatDate(config, getDateTimeFormat) {
|
|
|
55
55
|
return getFormatter(config, 'date', getDateTimeFormat, options).format(date);
|
|
56
56
|
}
|
|
57
57
|
catch (e) {
|
|
58
|
-
config.onError(new error_1.IntlError(
|
|
58
|
+
config.onError(new error_1.IntlError(error_1.IntlErrorCode.FORMAT_ERROR, 'Error formatting date.', e));
|
|
59
59
|
}
|
|
60
60
|
return String(date);
|
|
61
61
|
}
|
|
@@ -71,7 +71,7 @@ function formatTime(config, getDateTimeFormat) {
|
|
|
71
71
|
return getFormatter(config, 'time', getDateTimeFormat, options).format(date);
|
|
72
72
|
}
|
|
73
73
|
catch (e) {
|
|
74
|
-
config.onError(new error_1.IntlError(
|
|
74
|
+
config.onError(new error_1.IntlError(error_1.IntlErrorCode.FORMAT_ERROR, 'Error formatting time.', e));
|
|
75
75
|
}
|
|
76
76
|
return String(date);
|
|
77
77
|
}
|
|
@@ -88,7 +88,7 @@ function formatDateTimeRange(config, getDateTimeFormat) {
|
|
|
88
88
|
return getDateTimeFormat(locale, filteredOptions).formatRange(from, to);
|
|
89
89
|
}
|
|
90
90
|
catch (e) {
|
|
91
|
-
onError(new error_1.IntlError(
|
|
91
|
+
onError(new error_1.IntlError(error_1.IntlErrorCode.FORMAT_ERROR, 'Error formatting date time range.', e));
|
|
92
92
|
}
|
|
93
93
|
return String(from);
|
|
94
94
|
}
|
|
@@ -104,7 +104,7 @@ function formatDateToParts(config, getDateTimeFormat) {
|
|
|
104
104
|
return getFormatter(config, 'date', getDateTimeFormat, options).formatToParts(date);
|
|
105
105
|
}
|
|
106
106
|
catch (e) {
|
|
107
|
-
config.onError(new error_1.IntlError(
|
|
107
|
+
config.onError(new error_1.IntlError(error_1.IntlErrorCode.FORMAT_ERROR, 'Error formatting date.', e));
|
|
108
108
|
}
|
|
109
109
|
return [];
|
|
110
110
|
}
|
|
@@ -120,7 +120,7 @@ function formatTimeToParts(config, getDateTimeFormat) {
|
|
|
120
120
|
return getFormatter(config, 'time', getDateTimeFormat, options).formatToParts(date);
|
|
121
121
|
}
|
|
122
122
|
catch (e) {
|
|
123
|
-
config.onError(new error_1.IntlError(
|
|
123
|
+
config.onError(new error_1.IntlError(error_1.IntlErrorCode.FORMAT_ERROR, 'Error formatting time.', e));
|
|
124
124
|
}
|
|
125
125
|
return [];
|
|
126
126
|
}
|
package/src/displayName.js
CHANGED
|
@@ -21,7 +21,7 @@ function formatDisplayName(_a, getDisplayNames, value, options) {
|
|
|
21
21
|
return getDisplayNames(locale, filteredOptions).of(value);
|
|
22
22
|
}
|
|
23
23
|
catch (e) {
|
|
24
|
-
onError(new error_1.IntlError(
|
|
24
|
+
onError(new error_1.IntlError(error_1.IntlErrorCode.FORMAT_ERROR, 'Error formatting display name.', e));
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
exports.formatDisplayName = formatDisplayName;
|
package/src/error.d.ts
CHANGED
package/src/error.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../../../../../packages/intl/src/error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,iBAAiB,EAAC,MAAM,SAAS,CAAC;AAE1C,
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../../../../../packages/intl/src/error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,iBAAiB,EAAC,MAAM,SAAS,CAAC;AAE1C,oBAAY,aAAa;IACvB,YAAY,iBAAiB;IAC7B,qBAAqB,0BAA0B;IAC/C,cAAc,mBAAmB;IACjC,YAAY,iBAAiB;IAC7B,mBAAmB,wBAAwB;CAC5C;AAED,qBAAa,SAAS,CACpB,CAAC,SAAS,aAAa,GAAG,aAAa,CAAC,YAAY,CACpD,SAAQ,KAAK;IACb,SAAgB,IAAI,EAAE,CAAC,CAAC;gBAEZ,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,KAAK;CAUxD;AAED,qBAAa,yBAA0B,SAAQ,SAAS,CAAC,aAAa,CAAC,qBAAqB,CAAC;gBAC/E,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,KAAK;CAG/C;AAED,qBAAa,kBAAmB,SAAQ,SAAS,CAAC,aAAa,CAAC,cAAc,CAAC;gBACjE,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,KAAK;CAG/C;AAED,qBAAa,gBAAiB,SAAQ,SAAS,CAAC,aAAa,CAAC,YAAY,CAAC;gBAC7D,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,KAAK;CAG/C;AAED,qBAAa,kBAAmB,SAAQ,SAAS,CAAC,aAAa,CAAC,YAAY,CAAC;IAC3E,SAAgB,UAAU,CAAC,EAAE,iBAAiB,CAAC;gBAE7C,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,UAAU,CAAC,EAAE,iBAAiB,EAC9B,SAAS,CAAC,EAAE,KAAK;CAcpB;AAED,qBAAa,uBAAwB,SAAQ,SAAS,CAAC,aAAa,CAAC,mBAAmB,CAAC;IACvF,SAAgB,UAAU,CAAC,EAAE,iBAAiB,CAAC;gBACnC,UAAU,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM;CAS1D"}
|
package/src/error.js
CHANGED
|
@@ -26,7 +26,7 @@ exports.IntlError = IntlError;
|
|
|
26
26
|
var UnsupportedFormatterError = /** @class */ (function (_super) {
|
|
27
27
|
tslib_1.__extends(UnsupportedFormatterError, _super);
|
|
28
28
|
function UnsupportedFormatterError(message, exception) {
|
|
29
|
-
return _super.call(this,
|
|
29
|
+
return _super.call(this, IntlErrorCode.UNSUPPORTED_FORMATTER, message, exception) || this;
|
|
30
30
|
}
|
|
31
31
|
return UnsupportedFormatterError;
|
|
32
32
|
}(IntlError));
|
|
@@ -34,7 +34,7 @@ exports.UnsupportedFormatterError = UnsupportedFormatterError;
|
|
|
34
34
|
var InvalidConfigError = /** @class */ (function (_super) {
|
|
35
35
|
tslib_1.__extends(InvalidConfigError, _super);
|
|
36
36
|
function InvalidConfigError(message, exception) {
|
|
37
|
-
return _super.call(this,
|
|
37
|
+
return _super.call(this, IntlErrorCode.INVALID_CONFIG, message, exception) || this;
|
|
38
38
|
}
|
|
39
39
|
return InvalidConfigError;
|
|
40
40
|
}(IntlError));
|
|
@@ -42,7 +42,7 @@ exports.InvalidConfigError = InvalidConfigError;
|
|
|
42
42
|
var MissingDataError = /** @class */ (function (_super) {
|
|
43
43
|
tslib_1.__extends(MissingDataError, _super);
|
|
44
44
|
function MissingDataError(message, exception) {
|
|
45
|
-
return _super.call(this,
|
|
45
|
+
return _super.call(this, IntlErrorCode.MISSING_DATA, message, exception) || this;
|
|
46
46
|
}
|
|
47
47
|
return MissingDataError;
|
|
48
48
|
}(IntlError));
|
|
@@ -50,7 +50,7 @@ exports.MissingDataError = MissingDataError;
|
|
|
50
50
|
var MessageFormatError = /** @class */ (function (_super) {
|
|
51
51
|
tslib_1.__extends(MessageFormatError, _super);
|
|
52
52
|
function MessageFormatError(message, locale, descriptor, exception) {
|
|
53
|
-
var _this = _super.call(this,
|
|
53
|
+
var _this = _super.call(this, IntlErrorCode.FORMAT_ERROR, message + " \nLocale: " + locale + "\nMessageID: " + (descriptor === null || descriptor === void 0 ? void 0 : descriptor.id) + "\nDefault Message: " + (descriptor === null || descriptor === void 0 ? void 0 : descriptor.defaultMessage) + "\nDescription: " + (descriptor === null || descriptor === void 0 ? void 0 : descriptor.description) + " \n", exception) || this;
|
|
54
54
|
_this.descriptor = descriptor;
|
|
55
55
|
return _this;
|
|
56
56
|
}
|
|
@@ -60,7 +60,7 @@ exports.MessageFormatError = MessageFormatError;
|
|
|
60
60
|
var MissingTranslationError = /** @class */ (function (_super) {
|
|
61
61
|
tslib_1.__extends(MissingTranslationError, _super);
|
|
62
62
|
function MissingTranslationError(descriptor, locale) {
|
|
63
|
-
var _this = _super.call(this,
|
|
63
|
+
var _this = _super.call(this, IntlErrorCode.MISSING_TRANSLATION, "Missing message: \"" + descriptor.id + "\" for locale \"" + locale + "\", using " + (descriptor.defaultMessage ? 'default message' : 'id') + " as fallback.") || this;
|
|
64
64
|
_this.descriptor = descriptor;
|
|
65
65
|
return _this;
|
|
66
66
|
}
|
package/src/list.js
CHANGED
|
@@ -50,7 +50,7 @@ function formatList(_a, getListFormat, values, options) {
|
|
|
50
50
|
}, []);
|
|
51
51
|
}
|
|
52
52
|
catch (e) {
|
|
53
|
-
onError(new error_1.IntlError(
|
|
53
|
+
onError(new error_1.IntlError(error_1.IntlErrorCode.FORMAT_ERROR, 'Error formatting list.', e));
|
|
54
54
|
}
|
|
55
55
|
// @ts-ignore
|
|
56
56
|
return values;
|
package/src/number.js
CHANGED
|
@@ -42,7 +42,7 @@ function formatNumber(config, getNumberFormat, value, options) {
|
|
|
42
42
|
return getFormatter(config, getNumberFormat, options).format(value);
|
|
43
43
|
}
|
|
44
44
|
catch (e) {
|
|
45
|
-
config.onError(new error_1.IntlError(
|
|
45
|
+
config.onError(new error_1.IntlError(error_1.IntlErrorCode.FORMAT_ERROR, 'Error formatting number.', e));
|
|
46
46
|
}
|
|
47
47
|
return String(value);
|
|
48
48
|
}
|
|
@@ -53,7 +53,7 @@ function formatNumberToParts(config, getNumberFormat, value, options) {
|
|
|
53
53
|
return getFormatter(config, getNumberFormat, options).formatToParts(value);
|
|
54
54
|
}
|
|
55
55
|
catch (e) {
|
|
56
|
-
config.onError(new error_1.IntlError(
|
|
56
|
+
config.onError(new error_1.IntlError(error_1.IntlErrorCode.FORMAT_ERROR, 'Error formatting number.', e));
|
|
57
57
|
}
|
|
58
58
|
return [];
|
|
59
59
|
}
|