use-intl 2.11.0-alpha.2 → 2.11.0-useFormatter-alpha.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/CHANGELOG.md +19 -0
- package/README.md +32 -20
- package/dist/core/createFormatter.d.ts +17 -0
- package/dist/core/createIntl.d.ts +5 -15
- package/dist/core/index.d.ts +1 -0
- package/dist/core/use-intl.esm.js +38 -41
- package/dist/core/use-intl.esm.js.map +1 -1
- package/dist/core/use-intl.esm10.js +34 -0
- package/dist/core/use-intl.esm10.js.map +1 -0
- package/dist/core/use-intl.esm2.js +151 -35
- package/dist/core/use-intl.esm2.js.map +1 -1
- package/dist/core/use-intl.esm3.js +27 -140
- package/dist/core/use-intl.esm3.js.map +1 -1
- package/dist/core/use-intl.esm4.js +9 -53
- package/dist/core/use-intl.esm4.js.map +1 -1
- package/dist/core/use-intl.esm5.js +28 -11
- package/dist/core/use-intl.esm5.js.map +1 -1
- package/dist/core/use-intl.esm6.js +11 -209
- package/dist/core/use-intl.esm6.js.map +1 -1
- package/dist/core/use-intl.esm7.js +56 -7
- package/dist/core/use-intl.esm7.js.map +1 -1
- package/dist/core/use-intl.esm8.js +200 -19
- package/dist/core/use-intl.esm8.js.map +1 -1
- package/dist/core/use-intl.esm9.js +5 -29
- package/dist/core/use-intl.esm9.js.map +1 -1
- package/dist/react/IntlContext.d.ts +19 -2
- package/dist/react/IntlProvider.d.ts +16 -2
- package/dist/react/index.d.ts +2 -1
- package/dist/react/use-intl.esm.js +26 -7
- package/dist/react/use-intl.esm.js.map +1 -1
- package/dist/react/use-intl.esm10.js +2 -2
- package/dist/react/use-intl.esm2.js +3 -20
- package/dist/react/use-intl.esm2.js.map +1 -1
- package/dist/react/use-intl.esm3.js +40 -16
- package/dist/react/use-intl.esm3.js.map +1 -1
- package/dist/react/use-intl.esm4.js +21 -3
- package/dist/react/use-intl.esm4.js.map +1 -1
- package/dist/react/use-intl.esm5.js +20 -3
- package/dist/react/use-intl.esm5.js.map +1 -1
- package/dist/react/use-intl.esm6.js +24 -41
- package/dist/react/use-intl.esm6.js.map +1 -1
- package/dist/react/use-intl.esm7.js +5 -3
- package/dist/react/use-intl.esm7.js.map +1 -1
- package/dist/react/use-intl.esm8.js +3 -30
- package/dist/react/use-intl.esm8.js.map +1 -1
- package/dist/react/use-intl.esm9.js +1 -1
- package/dist/react/useFormatter.d.ts +5 -0
- package/dist/react/useIntl.d.ts +1 -0
- package/dist/react/useIntlContext.d.ts +1 -1
- package/dist/src/core/createBaseTranslator.js +10 -8
- package/dist/src/core/createBaseTranslator.js.map +1 -1
- package/dist/src/core/createFormatter.d.ts +17 -0
- package/dist/src/core/createFormatter.js +126 -0
- package/dist/src/core/createFormatter.js.map +1 -0
- package/dist/src/core/createIntl.d.ts +5 -15
- package/dist/src/core/createIntl.js +9 -124
- package/dist/src/core/createIntl.js.map +1 -1
- package/dist/src/core/index.d.ts +1 -0
- package/dist/src/core/index.js +2 -0
- package/dist/src/core/index.js.map +1 -1
- package/dist/src/react/IntlContext.d.ts +19 -2
- package/dist/src/react/IntlContext.js.map +1 -1
- package/dist/src/react/IntlProvider.d.ts +16 -2
- package/dist/src/react/IntlProvider.js +13 -4
- package/dist/src/react/IntlProvider.js.map +1 -1
- package/dist/src/react/index.d.ts +2 -1
- package/dist/src/react/index.js +3 -1
- package/dist/src/react/index.js.map +1 -1
- package/dist/src/react/useFormatter.d.ts +5 -0
- package/dist/src/react/useFormatter.js +14 -0
- package/dist/src/react/useFormatter.js.map +1 -0
- package/dist/src/react/useIntl.d.ts +1 -0
- package/dist/src/react/useIntl.js +6 -0
- package/dist/src/react/useIntl.js.map +1 -1
- package/dist/src/react/useIntlContext.d.ts +1 -1
- package/dist/use-intl.cjs.development.js +99 -68
- package/dist/use-intl.cjs.development.js.map +1 -1
- package/dist/use-intl.cjs.production.min.js +1 -1
- package/dist/use-intl.cjs.production.min.js.map +1 -1
- package/dist/use-intl.esm.js +10 -8
- package/dist/use-intl.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/core/createBaseTranslator.tsx +14 -12
- package/src/core/createFormatter.tsx +181 -0
- package/src/core/createIntl.tsx +12 -180
- package/src/core/index.tsx +3 -0
- package/src/react/IntlContext.tsx +20 -2
- package/src/react/IntlProvider.tsx +36 -5
- package/src/react/index.tsx +4 -1
- package/src/react/useFormatter.tsx +19 -0
- package/src/react/useIntl.tsx +10 -0
- package/dist/react/IntlContextValue.d.ts +0 -19
- package/dist/react/IntlProviderProps.d.ts +0 -15
- package/dist/react/getIntlContextValue.d.ts +0 -18
- package/dist/src/react/IntlContextValue.d.ts +0 -19
- package/dist/src/react/IntlContextValue.js +0 -2
- package/dist/src/react/IntlContextValue.js.map +0 -1
- package/dist/src/react/IntlProviderProps.d.ts +0 -15
- package/dist/src/react/IntlProviderProps.js +0 -2
- package/dist/src/react/IntlProviderProps.js.map +0 -1
- package/dist/src/react/getIntlContextValue.d.ts +0 -18
- package/dist/src/react/getIntlContextValue.js +0 -21
- package/dist/src/react/getIntlContextValue.js.map +0 -1
- package/src/react/IntlContextValue.tsx +0 -21
- package/src/react/IntlProviderProps.tsx +0 -17
- package/src/react/getIntlContextValue.tsx +0 -30
|
@@ -1,155 +1,42 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import IntlError, { IntlErrorCode } from './use-intl.esm.js';
|
|
3
|
-
import { defaultOnError } from './use-intl.esm5.js';
|
|
1
|
+
import { inheritsLoose as _inheritsLoose, wrapNativeSuper as _wrapNativeSuper } from '../_virtual/use-intl.esm.js';
|
|
4
2
|
|
|
5
|
-
var
|
|
6
|
-
var HOUR = MINUTE * 60;
|
|
7
|
-
var DAY = HOUR * 24;
|
|
8
|
-
var WEEK = DAY * 7;
|
|
9
|
-
var MONTH = DAY * (365 / 12); // Approximation
|
|
3
|
+
var IntlErrorCode;
|
|
10
4
|
|
|
11
|
-
|
|
5
|
+
(function (IntlErrorCode) {
|
|
6
|
+
IntlErrorCode["MISSING_MESSAGE"] = "MISSING_MESSAGE";
|
|
7
|
+
IntlErrorCode["MISSING_FORMAT"] = "MISSING_FORMAT";
|
|
8
|
+
IntlErrorCode["INSUFFICIENT_PATH"] = "INSUFFICIENT_PATH";
|
|
9
|
+
IntlErrorCode["INVALID_MESSAGE"] = "INVALID_MESSAGE";
|
|
10
|
+
IntlErrorCode["INVALID_KEY"] = "INVALID_KEY";
|
|
11
|
+
IntlErrorCode["FORMATTING_ERROR"] = "FORMATTING_ERROR";
|
|
12
|
+
})(IntlErrorCode || (IntlErrorCode = {}));
|
|
12
13
|
|
|
13
|
-
function
|
|
14
|
-
|
|
15
|
-
var value, unit; // We have to round the resulting values, as `Intl.RelativeTimeFormat`
|
|
16
|
-
// will include fractions like '2.1 hours ago'.
|
|
14
|
+
var IntlError = /*#__PURE__*/function (_Error) {
|
|
15
|
+
_inheritsLoose(IntlError, _Error);
|
|
17
16
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
value = Math.round(seconds);
|
|
21
|
-
} else if (absValue < HOUR) {
|
|
22
|
-
unit = 'minute';
|
|
23
|
-
value = Math.round(seconds / MINUTE);
|
|
24
|
-
} else if (absValue < DAY) {
|
|
25
|
-
unit = 'hour';
|
|
26
|
-
value = Math.round(seconds / HOUR);
|
|
27
|
-
} else if (absValue < WEEK) {
|
|
28
|
-
unit = 'day';
|
|
29
|
-
value = Math.round(seconds / DAY);
|
|
30
|
-
} else if (absValue < MONTH) {
|
|
31
|
-
unit = 'week';
|
|
32
|
-
value = Math.round(seconds / WEEK);
|
|
33
|
-
} else if (absValue < YEAR) {
|
|
34
|
-
unit = 'month';
|
|
35
|
-
value = Math.round(seconds / MONTH);
|
|
36
|
-
} else {
|
|
37
|
-
unit = 'year';
|
|
38
|
-
value = Math.round(seconds / YEAR);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return {
|
|
42
|
-
value: value,
|
|
43
|
-
unit: unit
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function createIntl(_ref) {
|
|
48
|
-
var formats = _ref.formats,
|
|
49
|
-
locale = _ref.locale,
|
|
50
|
-
globalNow = _ref.now,
|
|
51
|
-
_ref$onError = _ref.onError,
|
|
52
|
-
onError = _ref$onError === void 0 ? defaultOnError : _ref$onError,
|
|
53
|
-
timeZone = _ref.timeZone;
|
|
17
|
+
function IntlError(code, originalMessage) {
|
|
18
|
+
var _this;
|
|
54
19
|
|
|
55
|
-
|
|
56
|
-
var options;
|
|
20
|
+
var message = code;
|
|
57
21
|
|
|
58
|
-
if (
|
|
59
|
-
|
|
60
|
-
options = typeFormats == null ? void 0 : typeFormats[formatName];
|
|
61
|
-
|
|
62
|
-
if (!options) {
|
|
63
|
-
var error = new IntlError(IntlErrorCode.MISSING_FORMAT, process.env.NODE_ENV !== 'production' ? "Format `" + formatName + "` is not available. You can configure it on the provider or provide custom options." : undefined);
|
|
64
|
-
onError(error);
|
|
65
|
-
throw error;
|
|
66
|
-
}
|
|
67
|
-
} else {
|
|
68
|
-
options = formatOrOptions;
|
|
22
|
+
if (originalMessage) {
|
|
23
|
+
message += ': ' + originalMessage;
|
|
69
24
|
}
|
|
70
25
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
var options;
|
|
76
|
-
|
|
77
|
-
try {
|
|
78
|
-
options = resolveFormatOrOptions(typeFormats, formatOrOptions);
|
|
79
|
-
} catch (error) {
|
|
80
|
-
return String(value);
|
|
81
|
-
}
|
|
26
|
+
_this = _Error.call(this, message) || this;
|
|
27
|
+
_this.code = void 0;
|
|
28
|
+
_this.originalMessage = void 0;
|
|
29
|
+
_this.code = code;
|
|
82
30
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
} catch (error) {
|
|
86
|
-
onError(new IntlError(IntlErrorCode.FORMATTING_ERROR, error.message));
|
|
87
|
-
return String(value);
|
|
31
|
+
if (originalMessage) {
|
|
32
|
+
_this.originalMessage = originalMessage;
|
|
88
33
|
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function formatDateTime(
|
|
92
|
-
/** If a number is supplied, this is interpreted as a UTC timestamp. */
|
|
93
|
-
value,
|
|
94
|
-
/** If a time zone is supplied, the `value` is converted to that time zone.
|
|
95
|
-
* Otherwise the user time zone will be used. */
|
|
96
|
-
formatOrOptions) {
|
|
97
|
-
return getFormattedValue(value, formatOrOptions, formats == null ? void 0 : formats.dateTime, function (options) {
|
|
98
|
-
var _options;
|
|
99
34
|
|
|
100
|
-
|
|
101
|
-
options = _extends({}, options, {
|
|
102
|
-
timeZone: timeZone
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
return new Intl.DateTimeFormat(locale, options).format(value);
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
function formatNumber(value, formatOrOptions) {
|
|
111
|
-
return getFormattedValue(value, formatOrOptions, formats == null ? void 0 : formats.number, function (options) {
|
|
112
|
-
return new Intl.NumberFormat(locale, options).format(value);
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
function formatRelativeTime(
|
|
117
|
-
/** The date time that needs to be formatted. */
|
|
118
|
-
date,
|
|
119
|
-
/** The reference point in time to which `date` will be formatted in relation to. */
|
|
120
|
-
now) {
|
|
121
|
-
try {
|
|
122
|
-
if (!now) {
|
|
123
|
-
if (globalNow) {
|
|
124
|
-
now = globalNow;
|
|
125
|
-
} else {
|
|
126
|
-
throw new Error(process.env.NODE_ENV !== 'production' ? "The `now` parameter wasn't provided to `formatRelativeTime` and there was no global fallback configured on the provider." : undefined);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
var dateDate = date instanceof Date ? date : new Date(date);
|
|
131
|
-
var nowDate = now instanceof Date ? now : new Date(now);
|
|
132
|
-
var seconds = (dateDate.getTime() - nowDate.getTime()) / 1000;
|
|
133
|
-
|
|
134
|
-
var _getRelativeTimeForma = getRelativeTimeFormatConfig(seconds),
|
|
135
|
-
unit = _getRelativeTimeForma.unit,
|
|
136
|
-
value = _getRelativeTimeForma.value;
|
|
137
|
-
|
|
138
|
-
return new Intl.RelativeTimeFormat(locale, {
|
|
139
|
-
numeric: 'auto'
|
|
140
|
-
}).format(value, unit);
|
|
141
|
-
} catch (error) {
|
|
142
|
-
onError(new IntlError(IntlErrorCode.FORMATTING_ERROR, error.message));
|
|
143
|
-
return String(date);
|
|
144
|
-
}
|
|
35
|
+
return _this;
|
|
145
36
|
}
|
|
146
37
|
|
|
147
|
-
return
|
|
148
|
-
|
|
149
|
-
formatNumber: formatNumber,
|
|
150
|
-
formatRelativeTime: formatRelativeTime
|
|
151
|
-
};
|
|
152
|
-
}
|
|
38
|
+
return IntlError;
|
|
39
|
+
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
153
40
|
|
|
154
|
-
export {
|
|
41
|
+
export { IntlErrorCode, IntlError as default };
|
|
155
42
|
//# sourceMappingURL=use-intl.esm3.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-intl.esm3.js","sources":["../../src/core/createIntl.tsx"],"sourcesContent":["import DateTimeFormatOptions from './DateTimeFormatOptions';\nimport Formats from './Formats';\nimport IntlError, {IntlErrorCode} from './IntlError';\nimport NumberFormatOptions from './NumberFormatOptions';\nimport {defaultOnError} from './defaults';\n\nconst MINUTE = 60;\nconst HOUR = MINUTE * 60;\nconst DAY = HOUR * 24;\nconst WEEK = DAY * 7;\nconst MONTH = DAY * (365 / 12); // Approximation\nconst YEAR = DAY * 365;\n\nfunction getRelativeTimeFormatConfig(seconds: number) {\n const absValue = Math.abs(seconds);\n let value, unit: Intl.RelativeTimeFormatUnit;\n\n // We have to round the resulting values, as `Intl.RelativeTimeFormat`\n // will include fractions like '2.1 hours ago'.\n\n if (absValue < MINUTE) {\n unit = 'second';\n value = Math.round(seconds);\n } else if (absValue < HOUR) {\n unit = 'minute';\n value = Math.round(seconds / MINUTE);\n } else if (absValue < DAY) {\n unit = 'hour';\n value = Math.round(seconds / HOUR);\n } else if (absValue < WEEK) {\n unit = 'day';\n value = Math.round(seconds / DAY);\n } else if (absValue < MONTH) {\n unit = 'week';\n value = Math.round(seconds / WEEK);\n } else if (absValue < YEAR) {\n unit = 'month';\n value = Math.round(seconds / MONTH);\n } else {\n unit = 'year';\n value = Math.round(seconds / YEAR);\n }\n\n return {value, unit};\n}\n\ntype Props = {\n locale: string;\n timeZone?: string;\n onError?(error: IntlError): void;\n formats?: Partial<Formats>;\n now?: Date;\n};\n\nexport default function createIntl({\n formats,\n locale,\n now: globalNow,\n onError = defaultOnError,\n timeZone\n}: Props) {\n function resolveFormatOrOptions<Options>(\n typeFormats: Record<string, Options> | undefined,\n formatOrOptions?: string | Options\n ) {\n let options;\n if (typeof formatOrOptions === 'string') {\n const formatName = formatOrOptions;\n options = typeFormats?.[formatName];\n\n if (!options) {\n const error = new IntlError(\n IntlErrorCode.MISSING_FORMAT,\n process.env.NODE_ENV !== 'production'\n ? `Format \\`${formatName}\\` is not available. You can configure it on the provider or provide custom options.`\n : undefined\n );\n onError(error);\n throw error;\n }\n } else {\n options = formatOrOptions;\n }\n\n return options;\n }\n\n function getFormattedValue<Value, Options>(\n value: Value,\n formatOrOptions: string | Options | undefined,\n typeFormats: Record<string, Options> | undefined,\n formatter: (options?: Options) => string\n ) {\n let options;\n try {\n options = resolveFormatOrOptions(typeFormats, formatOrOptions);\n } catch (error) {\n return String(value);\n }\n\n try {\n return formatter(options);\n } catch (error) {\n onError(\n new IntlError(IntlErrorCode.FORMATTING_ERROR, (error as Error).message)\n );\n return String(value);\n }\n }\n\n function formatDateTime(\n /** If a number is supplied, this is interpreted as a UTC timestamp. */\n value: Date | number,\n /** If a time zone is supplied, the `value` is converted to that time zone.\n * Otherwise the user time zone will be used. */\n formatOrOptions?: string | DateTimeFormatOptions\n ) {\n return getFormattedValue(\n value,\n formatOrOptions,\n formats?.dateTime,\n (options) => {\n if (timeZone && !options?.timeZone) {\n options = {...options, timeZone};\n }\n\n return new Intl.DateTimeFormat(locale, options).format(value);\n }\n );\n }\n\n function formatNumber(\n value: number,\n formatOrOptions?: string | NumberFormatOptions\n ) {\n return getFormattedValue(\n value,\n formatOrOptions,\n formats?.number,\n (options) => new Intl.NumberFormat(locale, options).format(value)\n );\n }\n\n function formatRelativeTime(\n /** The date time that needs to be formatted. */\n date: number | Date,\n /** The reference point in time to which `date` will be formatted in relation to. */\n now?: number | Date\n ) {\n try {\n if (!now) {\n if (globalNow) {\n now = globalNow;\n } else {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? `The \\`now\\` parameter wasn't provided to \\`formatRelativeTime\\` and there was no global fallback configured on the provider.`\n : undefined\n );\n }\n }\n\n const dateDate = date instanceof Date ? date : new Date(date);\n const nowDate = now instanceof Date ? now : new Date(now);\n\n const seconds = (dateDate.getTime() - nowDate.getTime()) / 1000;\n const {unit, value} = getRelativeTimeFormatConfig(seconds);\n\n return new Intl.RelativeTimeFormat(locale, {\n numeric: 'auto'\n }).format(value, unit);\n } catch (error) {\n onError(\n new IntlError(IntlErrorCode.FORMATTING_ERROR, (error as Error).message)\n );\n return String(date);\n }\n }\n\n return {formatDateTime, formatNumber, formatRelativeTime};\n}\n"],"names":["MINUTE","HOUR","DAY","WEEK","MONTH","YEAR","getRelativeTimeFormatConfig","seconds","absValue","Math","abs","value","unit","round","createIntl","formats","locale","globalNow","now","onError","defaultOnError","timeZone","resolveFormatOrOptions","typeFormats","formatOrOptions","options","formatName","error","IntlError","IntlErrorCode","MISSING_FORMAT","process","env","NODE_ENV","undefined","getFormattedValue","formatter","String","FORMATTING_ERROR","message","formatDateTime","dateTime","Intl","DateTimeFormat","format","formatNumber","number","NumberFormat","formatRelativeTime","date","Error","dateDate","Date","nowDate","getTime","RelativeTimeFormat","numeric"],"mappings":";;;;AAMA,IAAMA,MAAM,GAAG,EAAf,CAAA;AACA,IAAMC,IAAI,GAAGD,MAAM,GAAG,EAAtB,CAAA;AACA,IAAME,GAAG,GAAGD,IAAI,GAAG,EAAnB,CAAA;AAC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2C,IAA3D,CAAA;;AACA,MAAsBhD,IAAAA,qBAAAA,GAAAA,2BAA2B,CAACC,OAAD,CAAjD;AAAA,UAAOK,IAAP,yBAAOA,IAAP;AAAA,UAAaD,KAAb,yBAAaA,KAAb,CAAA;;AAEA,MAAA,OAAO,IAAI+B,IAAI,CAACa,kBAAT,CAA4BvC,MAA5B,EAAoC;AACzCwC,QAAAA,OAAO,EAAE,MAAA;AADgC,OAApC,EAEJZ,MAFI,CAEGjC,KAFH,EAEUC,IAFV,CAAP,CAAA;AAGD,KAtBD,CAsBE,OAAOe,KAAP,EAAc;AACdR,MAAAA,OAAO,CACL,IAAIS,SAAJ,CAAcC,aAAa,CAACS,gBAA5B,EAA+CX,KAAe,CAACY,OAA/D,CADK,CAAP,CAAA;AAGA,MAAOF,OAAAA,MAAM,CAACY,IAAD,CAAb,CAAA;AACD,KAAA;AACF,GAAA;;AAED,EAAO,OAAA;AAACT,IAAAA,cAAc,EAAdA,cAAD;AAAiBK,IAAAA,YAAY,EAAZA,YAAjB;AAA+BG,IAAAA,kBAAkB,EAAlBA,kBAAAA;AAA/B,GAAP,CAAA;AACD;;;;"}
|
|
1
|
+
{"version":3,"file":"use-intl.esm3.js","sources":["../../src/core/IntlError.tsx"],"sourcesContent":["export enum IntlErrorCode {\n MISSING_MESSAGE = 'MISSING_MESSAGE',\n MISSING_FORMAT = 'MISSING_FORMAT',\n INSUFFICIENT_PATH = 'INSUFFICIENT_PATH',\n INVALID_MESSAGE = 'INVALID_MESSAGE',\n INVALID_KEY = 'INVALID_KEY',\n FORMATTING_ERROR = 'FORMATTING_ERROR'\n}\n\nexport default class IntlError extends Error {\n public readonly code: IntlErrorCode;\n public readonly originalMessage: string | undefined;\n\n constructor(code: IntlErrorCode, originalMessage?: string) {\n let message: string = code;\n if (originalMessage) {\n message += ': ' + originalMessage;\n }\n super(message);\n\n this.code = code;\n if (originalMessage) {\n this.originalMessage = originalMessage;\n }\n }\n}\n"],"names":["IntlErrorCode","IntlError","code","origin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rorCode } from './use-intl.esm.js';
|
|
3
|
-
import createBaseTranslator, { getMessagesOrError } from './use-intl.esm6.js';
|
|
4
|
-
import resolveNamespace from './use-intl.esm7.js';
|
|
1
|
+
import createFormatter from './use-intl.esm2.js';
|
|
5
2
|
|
|
6
|
-
|
|
7
|
-
function createTranslatorImpl(_ref, namespacePrefix) {
|
|
8
|
-
var getMessageFallback = _ref.getMessageFallback,
|
|
9
|
-
messages = _ref.messages,
|
|
10
|
-
namespace = _ref.namespace,
|
|
11
|
-
onError = _ref.onError,
|
|
12
|
-
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
3
|
+
/** @deprecated Switch to `createFormatter` */
|
|
13
4
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
getMessageFallback: getMessageFallback,
|
|
21
|
-
messagesOrError: getMessagesOrError({
|
|
22
|
-
messages: messages,
|
|
23
|
-
namespace: namespace,
|
|
24
|
-
onError: onError
|
|
25
|
-
})
|
|
26
|
-
}));
|
|
27
|
-
var originalRich = translator.rich;
|
|
28
|
-
|
|
29
|
-
function base() {
|
|
30
|
-
return translator.apply(void 0, arguments);
|
|
31
|
-
} // Augment `t.rich` to return plain strings
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
base.rich = function (key,
|
|
35
|
-
/** Key value pairs for values to interpolate into the message. */
|
|
36
|
-
values, formats) {
|
|
37
|
-
// `chunks` is returned as a string when no React element
|
|
38
|
-
// is used, therefore it's safe to cast this type.
|
|
39
|
-
var result = originalRich(key, values, formats); // When only string chunks are provided to the parser, only strings should be returned here.
|
|
40
|
-
|
|
41
|
-
if (typeof result !== 'string') {
|
|
42
|
-
var error = new IntlError(IntlErrorCode.FORMATTING_ERROR, process.env.NODE_ENV !== 'production' ? "`createTranslator` only accepts functions for rich text formatting that receive and return strings.\n\nE.g. t.rich('rich', {b: (chunks) => `<b>${chunks}</b>`})" : undefined);
|
|
43
|
-
onError(error);
|
|
44
|
-
return getMessageFallback({
|
|
45
|
-
error: error,
|
|
46
|
-
key: key,
|
|
47
|
-
namespace: namespace
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return result;
|
|
5
|
+
function createIntl() {
|
|
6
|
+
var formatter = createFormatter.apply(void 0, arguments);
|
|
7
|
+
return {
|
|
8
|
+
formatDateTime: formatter.dateTime,
|
|
9
|
+
formatNumber: formatter.number,
|
|
10
|
+
formatRelativeTime: formatter.relativeTime
|
|
52
11
|
};
|
|
53
|
-
|
|
54
|
-
base.raw = translator.raw;
|
|
55
|
-
return base;
|
|
56
12
|
}
|
|
57
13
|
|
|
58
|
-
export {
|
|
14
|
+
export { createIntl as default };
|
|
59
15
|
//# sourceMappingURL=use-intl.esm4.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-intl.esm4.js","sources":["../../src/core/
|
|
1
|
+
{"version":3,"file":"use-intl.esm4.js","sources":["../../src/core/createIntl.tsx"],"sourcesContent":["import createFormatter from './createFormatter';\n\n/** @deprecated Switch to `createFormatter` */\nexport default function createIntl(\n ...args: Parameters<typeof createFormatter>\n) {\n const formatter = createFormatter(...args);\n return {\n formatDateTime: formatter.dateTime,\n formatNumber: formatter.number,\n formatRelativeTime: formatter.relativeTime\n };\n}\n"],"names":["createIntl","formatter","createFormatter","formatDateTime","dateTime","formatNumber","number","formatRelativeTime","relativeTime"],"mappings":";;AAEA;;AACc,SAAUA,UAAV,GAC+B;AAE3C,EAAA,IAAMC,SAAS,GAAGC,eAAe,CAAA,KAAf,CAAlB,KAAA,CAAA,EAAA,SAAA,CAAA,CAAA;AACA,EAAO,OAAA;AACLC,IAAAA,cAAc,EAAEF,SAAS,CAACG,QADrB;AAELC,IAAAA,YAAY,EAAEJ,SAAS,CAACK,MAFnB;AAGLC,IAAAA,kBAAkB,EAAEN,SAAS,CAACO,YAAAA;AAHzB,GAAP,CAAA;AAKD;;;;"}
|
|
@@ -1,15 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import IntlError, { IntlErrorCode } from './use-intl.esm3.js';
|
|
2
|
+
|
|
3
|
+
function validateMessagesSegment(messages, invalidKeyLabels, parentPath) {
|
|
4
|
+
Object.entries(messages).forEach(function (_ref) {
|
|
5
|
+
var key = _ref[0],
|
|
6
|
+
messageOrMessages = _ref[1];
|
|
7
|
+
|
|
8
|
+
if (key.includes('.')) {
|
|
9
|
+
var keyLabel = key;
|
|
10
|
+
if (parentPath) keyLabel += " (at " + parentPath + ")";
|
|
11
|
+
invalidKeyLabels.push(keyLabel);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (messageOrMessages != null && typeof messageOrMessages === 'object') {
|
|
15
|
+
validateMessagesSegment(messageOrMessages, invalidKeyLabels, [parentPath, key].filter(function (part) {
|
|
16
|
+
return part != null;
|
|
17
|
+
}).join('.'));
|
|
18
|
+
}
|
|
19
|
+
});
|
|
9
20
|
}
|
|
10
|
-
|
|
11
|
-
|
|
21
|
+
|
|
22
|
+
function validateMessages(messages, onError) {
|
|
23
|
+
var invalidKeyLabels = [];
|
|
24
|
+
validateMessagesSegment(messages, invalidKeyLabels);
|
|
25
|
+
|
|
26
|
+
if (invalidKeyLabels.length > 0) {
|
|
27
|
+
onError(new IntlError(IntlErrorCode.INVALID_KEY, "Namespace keys can not contain the character \".\" as this is used to express nesting. Please remove it or replace it with another character.\n\nInvalid " + (invalidKeyLabels.length === 1 ? 'key' : 'keys') + ": " + invalidKeyLabels.join(', ')));
|
|
28
|
+
}
|
|
12
29
|
}
|
|
13
30
|
|
|
14
|
-
export {
|
|
31
|
+
export { validateMessages as default };
|
|
15
32
|
//# sourceMappingURL=use-intl.esm5.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-intl.esm5.js","sources":["../../src/core/
|
|
1
|
+
{"version":3,"file":"use-intl.esm5.js","sources":["../../src/core/validateMessages.tsx"],"sourcesContent":["import AbstractIntlMessages from './AbstractIntlMessages';\nimport IntlError, {IntlErrorCode} from './IntlError';\n\nfunction validateMessagesSegment(\n messages: AbstractIntlMessages,\n invalidKeyLabels: Array<string>,\n parentPath?: string\n) {\n Object.entries(messages).forEach(([key, messageOrMessages]) => {\n if (key.includes('.')) {\n let keyLabel = key;\n if (parentPath) keyLabel += ` (at ${parentPath})`;\n invalidKeyLabels.push(keyLabel);\n }\n\n if (messageOrMessages != null && typeof messageOrMessages === 'object') {\n validateMessagesSegment(\n messageOrMessages,\n invalidKeyLabels,\n [parentPath, key].filter((part) => part != null).join('.')\n );\n }\n });\n}\n\nexport default function validateMessages(\n messages: AbstractIntlMessages,\n onError: (error: IntlError) => void\n) {\n const invalidKeyLabels: Array<string> = [];\n validateMessagesSegment(messages, invalidKeyLabels);\n\n if (invalidKeyLabels.length > 0) {\n onError(\n new IntlError(\n IntlErrorCode.INVALID_KEY,\n `Namespace keys can not contain the character \".\" as this is used to express nesting. Please remove it or replace it with another character.\\n\\nInvalid ${\n invalidKeyLabels.length === 1 ? 'key' : 'keys'\n }: ${invalidKeyLabels.join(', ')}`\n )\n );\n }\n}\n"],"names":["validateMessagesSegment","messages","invalidKeyLabels","parentPath","Object","entries","forEach","key","messageOrMessages","includes","keyLabel","push","filter","part","join","validateMessages","onError","length","IntlError","IntlErrorCode","INVALID_KEY"],"mappings":";;AAGA,SAASA,uBAAT,CACEC,QADF,EAEEC,gBAFF,EAGEC,UAHF,EAGqB;AAEnBC,EAAAA,MAAM,CAACC,OAAP,CAAeJ,QAAf,CAAyBK,CAAAA,OAAzB,CAAiC,UAA6B,IAAA,EAAA;AAAA,IAAA,IAA3BC,GAA2B,GAAA,IAAA,CAAA,CAAA,CAAA;AAAA,QAAtBC,iBAAsB,GAAA,IAAA,CAAA,CAAA,CAAA,CAAA;;AAC5D,IAAA,IAAID,GAAG,CAACE,QAAJ,CAAa,GAAb,C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messages) {
|
|
10
|
-
throw new Error(process.env.NODE_ENV !== 'production' ? "No messages available at `" + namespace + "`." : undefined);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
var message = messages;
|
|
14
|
-
key.split('.').forEach(function (part) {
|
|
15
|
-
var next = message[part];
|
|
16
|
-
|
|
17
|
-
if (part == null || next == null) {
|
|
18
|
-
throw new Error(process.env.NODE_ENV !== 'production' ? "Could not resolve `" + key + "` in " + (namespace ? "`" + namespace + "`" : 'messages') + "." : undefined);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
message = next;
|
|
22
|
-
});
|
|
23
|
-
return message;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function prepareTranslationValues(values) {
|
|
27
|
-
if (Object.keys(values).length === 0) return undefined; // Workaround for https://github.com/formatjs/formatjs/issues/1467
|
|
28
|
-
|
|
29
|
-
var transformedValues = {};
|
|
30
|
-
Object.keys(values).forEach(function (key) {
|
|
31
|
-
var index = 0;
|
|
32
|
-
var value = values[key];
|
|
33
|
-
var transformed;
|
|
34
|
-
|
|
35
|
-
if (typeof value === 'function') {
|
|
36
|
-
transformed = function transformed(chunks) {
|
|
37
|
-
var result = value(chunks);
|
|
38
|
-
return isValidElement(result) ? cloneElement(result, {
|
|
39
|
-
key: key + index++
|
|
40
|
-
}) : result;
|
|
41
|
-
};
|
|
42
|
-
} else {
|
|
43
|
-
transformed = value;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
transformedValues[key] = transformed;
|
|
47
|
-
});
|
|
48
|
-
return transformedValues;
|
|
1
|
+
/**
|
|
2
|
+
* Contains defaults that are used for all entry points into the core.
|
|
3
|
+
* See also `InitializedIntlConfiguration`.
|
|
4
|
+
*/
|
|
5
|
+
function defaultGetMessageFallback(props) {
|
|
6
|
+
return [props.namespace, props.key].filter(function (part) {
|
|
7
|
+
return part != null;
|
|
8
|
+
}).join('.');
|
|
49
9
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
var messages = _ref.messages,
|
|
53
|
-
namespace = _ref.namespace,
|
|
54
|
-
_ref$onError = _ref.onError,
|
|
55
|
-
onError = _ref$onError === void 0 ? defaultOnError : _ref$onError;
|
|
56
|
-
|
|
57
|
-
try {
|
|
58
|
-
if (!messages) {
|
|
59
|
-
throw new Error(process.env.NODE_ENV !== 'production' ? "No messages were configured on the provider." : undefined);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
var retrievedMessages = namespace ? resolvePath(messages, namespace) : messages;
|
|
63
|
-
|
|
64
|
-
if (!retrievedMessages) {
|
|
65
|
-
throw new Error(process.env.NODE_ENV !== 'production' ? "No messages for namespace `" + namespace + "` found." : undefined);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return retrievedMessages;
|
|
69
|
-
} catch (error) {
|
|
70
|
-
var intlError = new IntlError(IntlErrorCode.MISSING_MESSAGE, error.message);
|
|
71
|
-
onError(intlError);
|
|
72
|
-
return intlError;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
function createBaseTranslator(_ref2) {
|
|
76
|
-
var cachedFormatsByLocale = _ref2.cachedFormatsByLocale,
|
|
77
|
-
defaultTranslationValues = _ref2.defaultTranslationValues,
|
|
78
|
-
globalFormats = _ref2.formats,
|
|
79
|
-
_ref2$getMessageFallb = _ref2.getMessageFallback,
|
|
80
|
-
getMessageFallback = _ref2$getMessageFallb === void 0 ? defaultGetMessageFallback : _ref2$getMessageFallb,
|
|
81
|
-
locale = _ref2.locale,
|
|
82
|
-
messagesOrError = _ref2.messagesOrError,
|
|
83
|
-
namespace = _ref2.namespace,
|
|
84
|
-
onError = _ref2.onError,
|
|
85
|
-
timeZone = _ref2.timeZone;
|
|
86
|
-
|
|
87
|
-
function getFallbackFromErrorAndNotify(key, code, message) {
|
|
88
|
-
var error = new IntlError(code, message);
|
|
89
|
-
onError(error);
|
|
90
|
-
return getMessageFallback({
|
|
91
|
-
error: error,
|
|
92
|
-
key: key,
|
|
93
|
-
namespace: namespace
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function translateBaseFn(
|
|
98
|
-
/** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */
|
|
99
|
-
key,
|
|
100
|
-
/** Key value pairs for values to interpolate into the message. */
|
|
101
|
-
values,
|
|
102
|
-
/** Provide custom formats for numbers, dates and times. */
|
|
103
|
-
formats) {
|
|
104
|
-
var _cachedFormatsByLocal;
|
|
105
|
-
|
|
106
|
-
if (messagesOrError instanceof IntlError) {
|
|
107
|
-
// We have already warned about this during render
|
|
108
|
-
return getMessageFallback({
|
|
109
|
-
error: messagesOrError,
|
|
110
|
-
key: key,
|
|
111
|
-
namespace: namespace
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
var messages = messagesOrError;
|
|
116
|
-
var cacheKey = [namespace, key].filter(function (part) {
|
|
117
|
-
return part != null;
|
|
118
|
-
}).join('.');
|
|
119
|
-
var messageFormat;
|
|
120
|
-
|
|
121
|
-
if (cachedFormatsByLocale != null && (_cachedFormatsByLocal = cachedFormatsByLocale[locale]) != null && _cachedFormatsByLocal[cacheKey]) {
|
|
122
|
-
messageFormat = cachedFormatsByLocale == null ? void 0 : cachedFormatsByLocale[locale][cacheKey];
|
|
123
|
-
} else {
|
|
124
|
-
var message;
|
|
125
|
-
|
|
126
|
-
try {
|
|
127
|
-
message = resolvePath(messages, key, namespace);
|
|
128
|
-
} catch (error) {
|
|
129
|
-
return getFallbackFromErrorAndNotify(key, IntlErrorCode.MISSING_MESSAGE, error.message);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
if (typeof message === 'object') {
|
|
133
|
-
return getFallbackFromErrorAndNotify(key, IntlErrorCode.INSUFFICIENT_PATH, process.env.NODE_ENV !== 'production' ? "Insufficient path specified for `" + key + "` in `" + (namespace ? "`" + namespace + "`" : 'messages') + "`." : undefined);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
try {
|
|
137
|
-
messageFormat = new IntlMessageFormat(message, locale, convertFormatsToIntlMessageFormat(_extends({}, globalFormats, formats), timeZone));
|
|
138
|
-
} catch (error) {
|
|
139
|
-
return getFallbackFromErrorAndNotify(key, IntlErrorCode.INVALID_MESSAGE, error.message);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
if (cachedFormatsByLocale) {
|
|
143
|
-
if (!cachedFormatsByLocale[locale]) {
|
|
144
|
-
cachedFormatsByLocale[locale] = {};
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
cachedFormatsByLocale[locale][cacheKey] = messageFormat;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
try {
|
|
152
|
-
var formattedMessage = messageFormat.format( // @ts-ignore `intl-messageformat` expects a different format
|
|
153
|
-
// for rich text elements since a recent minor update. This
|
|
154
|
-
// needs to be evaluated in detail, possibly also in regards
|
|
155
|
-
// to be able to format to parts.
|
|
156
|
-
prepareTranslationValues(_extends({}, defaultTranslationValues, values)));
|
|
157
|
-
|
|
158
|
-
if (formattedMessage == null) {
|
|
159
|
-
throw new Error(process.env.NODE_ENV !== 'production' ? "Unable to format `" + key + "` in " + (namespace ? "namespace `" + namespace + "`" : 'messages') : undefined);
|
|
160
|
-
} // Limit the function signature to return strings or React elements
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
return isValidElement(formattedMessage) || // Arrays of React elements
|
|
164
|
-
Array.isArray(formattedMessage) || typeof formattedMessage === 'string' ? formattedMessage : String(formattedMessage);
|
|
165
|
-
} catch (error) {
|
|
166
|
-
return getFallbackFromErrorAndNotify(key, IntlErrorCode.FORMATTING_ERROR, error.message);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
function translateFn(
|
|
171
|
-
/** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */
|
|
172
|
-
key,
|
|
173
|
-
/** Key value pairs for values to interpolate into the message. */
|
|
174
|
-
values,
|
|
175
|
-
/** Provide custom formats for numbers, dates and times. */
|
|
176
|
-
formats) {
|
|
177
|
-
var result = translateBaseFn(key, values, formats);
|
|
178
|
-
|
|
179
|
-
if (typeof result !== 'string') {
|
|
180
|
-
return getFallbackFromErrorAndNotify(key, IntlErrorCode.INVALID_MESSAGE, process.env.NODE_ENV !== 'production' ? "The message `" + key + "` in " + (namespace ? "namespace `" + namespace + "`" : 'messages') + " didn't resolve to a string. If you want to format rich text, use `t.rich` instead." : undefined);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
return result;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
translateFn.rich = translateBaseFn;
|
|
187
|
-
|
|
188
|
-
translateFn.raw = function (
|
|
189
|
-
/** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */
|
|
190
|
-
key) {
|
|
191
|
-
if (messagesOrError instanceof IntlError) {
|
|
192
|
-
// We have already warned about this during render
|
|
193
|
-
return getMessageFallback({
|
|
194
|
-
error: messagesOrError,
|
|
195
|
-
key: key,
|
|
196
|
-
namespace: namespace
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
var messages = messagesOrError;
|
|
201
|
-
|
|
202
|
-
try {
|
|
203
|
-
return resolvePath(messages, key, namespace);
|
|
204
|
-
} catch (error) {
|
|
205
|
-
return getFallbackFromErrorAndNotify(key, IntlErrorCode.MISSING_MESSAGE, error.message);
|
|
206
|
-
}
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
return translateFn;
|
|
10
|
+
function defaultOnError(error) {
|
|
11
|
+
console.error(error);
|
|
210
12
|
}
|
|
211
13
|
|
|
212
|
-
export {
|
|
14
|
+
export { defaultGetMessageFallback, defaultOnError };
|
|
213
15
|
//# sourceMappingURL=use-intl.esm6.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-intl.esm6.js","sources":["../../src/core/createBaseTranslator.tsx"],"sourcesContent":["import IntlMessageFormat from 'intl-messageformat';\nimport {\n cloneElement,\n isValidElement,\n ReactElement,\n ReactNode,\n ReactNodeArray\n} from 'react';\nimport AbstractIntlMessages from './AbstractIntlMessages';\nimport Formats from './Formats';\nimport {InitializedIntlConfiguration} from './IntlConfiguration';\nimport IntlError, {IntlErrorCode} from './IntlError';\nimport TranslationValues, {RichTranslationValues} from './TranslationValues';\nimport convertFormatsToIntlMessageFormat from './convertFormatsToIntlMessageFormat';\nimport {defaultGetMessageFallback, defaultOnError} from './defaults';\nimport MessageKeys from './utils/MessageKeys';\nimport NestedKeyOf from './utils/NestedKeyOf';\nimport NestedValueOf from './utils/NestedValueOf';\n\nfunction resolvePath(\n messages: AbstractIntlMessages | undefined,\n key: string,\n namespace?: string\n) {\n if (!messages) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? `No messages available at \\`${namespace}\\`.`\n : undefined\n );\n }\n\n let message = messages;\n\n key.split('.').forEach((part) => {\n const next = (message as any)[part];\n\n if (part == null || next == null) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? `Could not resolve \\`${key}\\` in ${\n namespace ? `\\`${namespace}\\`` : 'messages'\n }.`\n : undefined\n );\n }\n\n message = next;\n });\n\n return message;\n}\n\nfunction prepareTranslationValues(values: RichTranslationValues) {\n if (Object.keys(values).length === 0) return undefined;\n\n // Workaround for https://github.com/formatjs/formatjs/issues/1467\n const transformedValues: RichTranslationValues = {};\n Object.keys(values).forEach((key) => {\n let index = 0;\n const value = values[key];\n\n let transformed;\n if (typeof value === 'function') {\n transformed = (chunks: ReactNode) => {\n const result = value(chunks);\n\n return isValidElement(result)\n ? cloneElement(result, {key: key + index++})\n : result;\n };\n } else {\n transformed = value;\n }\n\n transformedValues[key] = transformed;\n });\n\n return transformedValues;\n}\n\nexport function getMessagesOrError<Messages extends AbstractIntlMessages>({\n messages,\n namespace,\n onError = defaultOnError\n}: {\n messages: Messages;\n namespace?: string;\n onError?(error: IntlError): void;\n}) {\n try {\n if (!messages) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? `No messages were configured on the provider.`\n : undefined\n );\n }\n\n const retrievedMessages = namespace\n ? resolvePath(messages, namespace)\n : messages;\n\n if (!retrievedMessages) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? `No messages for namespace \\`${namespace}\\` found.`\n : undefined\n );\n }\n\n return retrievedMessages;\n } catch (error) {\n const intlError = new IntlError(\n IntlErrorCode.MISSING_MESSAGE,\n (error as Error).message\n );\n onError(intlError);\n return intlError;\n }\n}\n\nexport type CreateBaseTranslatorProps<Messages> =\n InitializedIntlConfiguration & {\n cachedFormatsByLocale?: Record<string, Record<string, IntlMessageFormat>>;\n defaultTranslationValues?: RichTranslationValues;\n namespace?: string;\n messagesOrError: Messages | IntlError;\n };\n\nexport default function createBaseTranslator<\n Messages extends AbstractIntlMessages,\n NestedKey extends NestedKeyOf<Messages>\n>({\n cachedFormatsByLocale,\n defaultTranslationValues,\n formats: globalFormats,\n getMessageFallback = defaultGetMessageFallback,\n locale,\n messagesOrError,\n namespace,\n onError,\n timeZone\n}: CreateBaseTranslatorProps<Messages>) {\n function getFallbackFromErrorAndNotify(\n key: string,\n code: IntlErrorCode,\n message?: string\n ) {\n const error = new IntlError(code, message);\n onError(error);\n return getMessageFallback({error, key, namespace});\n }\n\n function translateBaseFn(\n /** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */\n key: string,\n /** Key value pairs for values to interpolate into the message. */\n values?: RichTranslationValues,\n /** Provide custom formats for numbers, dates and times. */\n formats?: Partial<Formats>\n ): string | ReactElement | ReactNodeArray {\n if (messagesOrError instanceof IntlError) {\n // We have already warned about this during render\n return getMessageFallback({\n error: messagesOrError,\n key,\n namespace\n });\n }\n const messages = messagesOrError;\n\n const cacheKey = [namespace, key].filter((part) => part != null).join('.');\n\n let messageFormat;\n if (cachedFormatsByLocale?.[locale]?.[cacheKey]) {\n messageFormat = cachedFormatsByLocale?.[locale][cacheKey];\n } else {\n let message;\n try {\n message = resolvePath(messages, key, namespace);\n } catch (error) {\n return getFallbackFromErrorAndNotify(\n key,\n IntlErrorCode.MISSING_MESSAGE,\n (error as Error).message\n );\n }\n\n if (typeof message === 'object') {\n return getFallbackFromErrorAndNotify(\n key,\n IntlErrorCode.INSUFFICIENT_PATH,\n process.env.NODE_ENV !== 'production'\n ? `Insufficient path specified for \\`${key}\\` in \\`${\n namespace ? `\\`${namespace}\\`` : 'messages'\n }\\`.`\n : undefined\n );\n }\n\n try {\n messageFormat = new IntlMessageFormat(\n message,\n locale,\n convertFormatsToIntlMessageFormat(\n {...globalFormats, ...formats},\n timeZone\n )\n );\n } catch (error) {\n return getFallbackFromErrorAndNotify(\n key,\n IntlErrorCode.INVALID_MESSAGE,\n (error as Error).message\n );\n }\n\n if (cachedFormatsByLocale) {\n if (!cachedFormatsByLocale[locale]) {\n cachedFormatsByLocale[locale] = {};\n }\n cachedFormatsByLocale[locale][cacheKey] = messageFormat;\n }\n }\n\n try {\n const formattedMessage = messageFormat.format(\n // @ts-ignore `intl-messageformat` expects a different format\n // for rich text elements since a recent minor update. This\n // needs to be evaluated in detail, possibly also in regards\n // to be able to format to parts.\n prepareTranslationValues({...defaultTranslationValues, ...values})\n );\n\n if (formattedMessage == null) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? `Unable to format \\`${key}\\` in ${\n namespace ? `namespace \\`${namespace}\\`` : 'messages'\n }`\n : undefined\n );\n }\n\n // Limit the function signature to return strings or React elements\n return isValidElement(formattedMessage) ||\n // Arrays of React elements\n Array.isArray(formattedMessage) ||\n typeof formattedMessage === 'string'\n ? formattedMessage\n : String(formattedMessage);\n } catch (error) {\n return getFallbackFromErrorAndNotify(\n key,\n IntlErrorCode.FORMATTING_ERROR,\n (error as Error).message\n );\n }\n }\n\n function translateFn<\n TargetKey extends MessageKeys<\n NestedValueOf<Messages, NestedKey>,\n NestedKeyOf<NestedValueOf<Messages, NestedKey>>\n >\n >(\n /** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */\n key: TargetKey,\n /** Key value pairs for values to interpolate into the message. */\n values?: TranslationValues,\n /** Provide custom formats for numbers, dates and times. */\n formats?: Partial<Formats>\n ): string {\n const result = translateBaseFn(key, values, formats);\n\n if (typeof result !== 'string') {\n return getFallbackFromErrorAndNotify(\n key,\n IntlErrorCode.INVALID_MESSAGE,\n process.env.NODE_ENV !== 'production'\n ? `The message \\`${key}\\` in ${\n namespace ? `namespace \\`${namespace}\\`` : 'messages'\n } didn't resolve to a string. If you want to format rich text, use \\`t.rich\\` instead.`\n : undefined\n );\n }\n\n return result;\n }\n\n translateFn.rich = translateBaseFn;\n\n translateFn.raw = (\n /** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */\n key: string\n ): any => {\n if (messagesOrError instanceof IntlError) {\n // We have already warned about this during render\n return getMessageFallback({\n error: messagesOrError,\n key,\n namespace\n });\n }\n const messages = messagesOrError;\n\n try {\n return resolvePath(messages, key, namespace);\n } catch (error) {\n return getFallbackFromErrorAndNotify(\n key,\n IntlErrorCode.MISSING_MESSAGE,\n (error as Error).message\n );\n }\n };\n\n return translateFn;\n}\n"],"names":["resolvePath","messages","key","namespace","Error","process","env","NODE_ENV","undefined","message","split","forEach","part","next","prepareTranslationValues","values","Object","keys","length","transformedValues","index","value","transformed","chunks","result","isValidElement","cloneElement","getMessagesOrError","onError","defaultOnError","retrievedMessages","error","intlError","IntlError","IntlErrorCode","MISSING_MESSAGE","createBaseTranslator","cachedFormatsByLocale","defaultTranslationValues","globalFormats","formats","getMessageFallback","defaultGetMessageFallback","locale","messagesOrError","timeZone","getFallbackFromErrorAndNotify","code","translateBaseFn","cacheKey","filter","join","messageFormat","INSUFFICIENT_PATH","IntlMessageFormat","convertFormatsToIntlMessageFormat","INVALID_MESSAGE","formattedMessage","format","Array","isArray","String","FORMATTING_ERROR","translateFn","rich","raw"],"mappings":";;;;;;;AAmBA,SAASA,WAAT,CACEC,QADF,EAEEC,GAFF,EAGEC,SAHF,EAGoB;AAElB,EAAI,IAAA,CAACF,QAAL,EAAe;AACb,IAAA,MAAM,IAAIG,KAAJ,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A/B,EAA0C;AACxC;AACA,MAAA,OAAOQ,kBAAkB,CAAC;AACxBV,QAAAA,KAAK,EAAEa,eADiB;AAExB1C,QAAAA,GAAG,EAAHA,GAFwB;AAGxBC,QAAAA,SAAS,EAATA,SAAAA;AAHwB,OAAD,CAAzB,CAAA;AAKD,KAAA;;AACD,IAAMF,IAAAA,QAAQ,GAAG2C,eAAjB,CAAA;;AAEA,IAAI,IAAA;AACF,MAAA,OAAO5C,WAAW,CAACC,QAAD,EAAWC,GAAX,EAAgBC,SAAhB,CAAlB,CAAA;AACD,KAFD,CAEE,OAAO4B,KAAP,EAAc;AACd,MAAOe,OAAAA,6BAA6B,CAClC5C,GADkC,EAElCgC,aAAa,CAACC,eAFoB,EAGjCJ,KAAe,CAACtB,OAHiB,CAApC,CAAA;AAKD,KAAA;AACF,GAvBD,CAAA;;AAyBA,EAAA,OAAOsD,WAAP,CAAA;AACD;;;;"}
|
|
1
|
+
{"version":3,"file":"use-intl.esm6.js","sources":["../../src/core/defaults.tsx"],"sourcesContent":["import IntlError from './IntlError';\n\n/**\n * Contains defaults that are used for all entry points into the core.\n * See also `InitializedIntlConfiguration`.\n */\n\nexport function defaultGetMessageFallback(props: {\n error: IntlError;\n key: string;\n namespace?: string;\n}) {\n return [props.namespace, props.key].filter((part) => part != null).join('.');\n}\n\nexport function defaultOnError(error: IntlError) {\n console.error(error);\n}\n"],"names":["defaultGetMessageFallback","props","namespace","key","filter","part","join","defaultOnError","error","console"],"mappings":"AAEA;;;AAGG;AAEG,SAAUA,yBAAV,CAAoCC,KAApC,EAIL;AACC,EAAA,OAAO,CAACA,KAAK,CAACC,SAAP,EAAkBD,KAAK,CAACE,GAAxB,CAA6BC,CAAAA,MAA7B,CAAoC,UAACC,IAAD,EAAA;AAAA,IAAUA,OAAAA,IAAI,IAAI,IAAlB,CAAA;AAAA,GAApC,CAA4DC,CAAAA,IAA5D,CAAiE,GAAjE,CAAP,CAAA;AACD,CAAA;AAEK,SAAUC,cAAV,CAAyBC,KAAzB,EAAyC;AAC7CC,EAAAA,OAAO,CAACD,KAAR,CAAcA,KAAd,CAAA,CAAA;AACD;;;;"}
|