use-intl 3.0.0-beta.1 → 3.0.0-beta.3
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/_IntlProvider.d.ts +1 -0
- package/_useLocale.d.ts +1 -0
- package/core.d.ts +1 -1
- package/dist/_IntlProvider.js +7 -0
- package/dist/_useLocale.js +7 -0
- package/dist/core.js +3 -4
- package/dist/development/IntlContext-b5cc6be8.js +8 -0
- package/dist/development/_IntlProvider.js +27 -0
- package/dist/development/_useLocale-321e619f.js +19 -0
- package/dist/development/_useLocale.js +11 -0
- package/dist/development/core.js +92 -0
- package/dist/development/createIntl-dfba4462.js +421 -0
- package/dist/development/index.js +31 -0
- package/dist/development/initializeConfig-cde42612.js +119 -0
- package/dist/development/react.js +160 -0
- package/dist/esm/IntlContext-381f3ce4.js +1 -0
- package/dist/esm/_IntlProvider.js +1 -0
- package/dist/esm/_useLocale-89b32eb9.js +1 -0
- package/dist/esm/_useLocale.js +1 -0
- package/dist/esm/core.js +1 -0
- package/dist/esm/createIntl-164a7766.js +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/initializeConfig-c316f266.js +1 -0
- package/dist/esm/react.js +1 -0
- package/dist/index.js +3 -4
- package/dist/production/IntlContext-381f3ce4.js +1 -0
- package/dist/production/_IntlProvider.js +1 -0
- package/dist/production/_useLocale-8e23751a.js +1 -0
- package/dist/production/_useLocale.js +1 -0
- package/dist/production/core.js +1 -0
- package/dist/production/createIntl-e408cd5c.js +1 -0
- package/dist/production/index.js +1 -0
- package/dist/production/initializeConfig-984a566d.js +1 -0
- package/dist/production/react.js +1 -0
- package/dist/react.js +3 -4
- package/dist/types/src/_IntlProvider.d.ts +1 -0
- package/dist/types/src/_useLocale.d.ts +1 -0
- package/dist/{core → types/src/core}/AbstractIntlMessages.d.ts +9 -9
- package/dist/{core → types/src/core}/DateTimeFormatOptions.d.ts +73 -73
- package/dist/{core → types/src/core}/Formats.d.ts +8 -8
- package/dist/{core → types/src/core}/IntlConfig.d.ts +54 -54
- package/dist/{core → types/src/core}/IntlError.d.ts +13 -13
- package/dist/types/src/core/MessageFormatCache.d.ts +5 -0
- package/dist/{core → types/src/core}/NumberFormatOptions.d.ts +2 -2
- package/dist/{core → types/src/core}/TimeZone.d.ts +2 -2
- package/dist/{core → types/src/core}/TranslationValues.d.ts +6 -6
- package/dist/{core → types/src/core}/convertFormatsToIntlMessageFormat.d.ts +11 -11
- package/dist/{core → types/src/core}/createBaseTranslator.d.ts +21 -21
- package/dist/{core → types/src/core}/createFormatter.d.ts +19 -19
- package/dist/{core → types/src/core}/createIntl.d.ts +7 -7
- package/dist/{core → types/src/core}/createTranslator.d.ts +47 -47
- package/dist/{core → types/src/core}/createTranslatorImpl.d.ts +13 -13
- package/dist/{core → types/src/core}/defaults.d.ts +11 -11
- package/dist/{core → types/src/core}/index.d.ts +16 -16
- package/dist/{core → types/src/core}/initializeConfig.d.ts +14 -13
- package/dist/{core → types/src/core}/resolveNamespace.d.ts +5 -5
- package/dist/{core → types/src/core}/utils/MessageKeys.d.ts +5 -5
- package/dist/{core → types/src/core}/utils/NamespaceKeys.d.ts +5 -5
- package/dist/{core → types/src/core}/utils/NestedKeyOf.d.ts +4 -4
- package/dist/{core → types/src/core}/utils/NestedValueOf.d.ts +2 -2
- package/dist/{core → types/src/core}/validateMessages.d.ts +3 -3
- package/dist/{core.d.ts → types/src/core.d.ts} +1 -1
- package/dist/{index.d.ts → types/src/index.d.ts} +2 -2
- package/dist/types/src/react/IntlContext.d.ts +13 -0
- package/dist/{react → types/src/react}/IntlProvider.d.ts +7 -7
- package/dist/{react → types/src/react}/getInitializedConfig.d.ts +1 -1
- package/dist/{react → types/src/react}/index.d.ts +8 -8
- package/dist/{react → types/src/react}/useFormatter.d.ts +6 -6
- package/dist/{react → types/src/react}/useIntl.d.ts +6 -6
- package/dist/types/src/react/useIntlContext.d.ts +10 -0
- package/dist/{react → types/src/react}/useLocale.d.ts +1 -1
- package/dist/{react → types/src/react}/useMessages.d.ts +1 -1
- package/dist/{react → types/src/react}/useNow.d.ts +23 -23
- package/dist/{react → types/src/react}/useTimeZone.d.ts +1 -1
- package/dist/{react → types/src/react}/useTranslations.d.ts +44 -44
- package/dist/{react → types/src/react}/useTranslationsImpl.d.ts +8 -8
- package/dist/{react.d.ts → types/src/react.d.ts} +1 -1
- package/dist/types/test/core/createFormatter.test.d.ts +1 -0
- package/dist/types/test/core/createIntl.test.d.ts +1 -0
- package/dist/types/test/core/createTranslator.test.d.ts +1 -0
- package/dist/types/test/react/useFormatter.test.d.ts +1 -0
- package/dist/types/test/react/useIntl.test.d.ts +1 -0
- package/dist/types/test/react/useLocale.test.d.ts +1 -0
- package/dist/types/test/react/useMessages.test.d.ts +1 -0
- package/dist/types/test/react/useNow.test.d.ts +1 -0
- package/dist/types/test/react/useTimeZone.test.d.ts +1 -0
- package/dist/types/test/react/useTranslations.test.d.ts +1 -0
- package/dist/{test → types/test}/setup.d.ts +1 -1
- package/package.json +33 -21
- package/react.d.ts +1 -1
- package/dist/_virtual/_rollupPluginBabelHelpers.esm.js +0 -102
- package/dist/_virtual/_rollupPluginBabelHelpers.esm.js.map +0 -1
- package/dist/_virtual/use-intl.esm.js +0 -102
- package/dist/_virtual/use-intl.esm.js.map +0 -1
- package/dist/core/IntlError.esm.js +0 -33
- package/dist/core/IntlError.esm.js.map +0 -1
- package/dist/core/convertFormatsToIntlMessageFormat.esm.js +0 -32
- package/dist/core/convertFormatsToIntlMessageFormat.esm.js.map +0 -1
- package/dist/core/createBaseTranslator.esm.js +0 -201
- package/dist/core/createBaseTranslator.esm.js.map +0 -1
- package/dist/core/createFormatter.esm.js +0 -138
- package/dist/core/createFormatter.esm.js.map +0 -1
- package/dist/core/createIntl.esm.js +0 -14
- package/dist/core/createIntl.esm.js.map +0 -1
- package/dist/core/createTranslator.esm.js +0 -37
- package/dist/core/createTranslator.esm.js.map +0 -1
- package/dist/core/createTranslatorImpl.esm.js +0 -50
- package/dist/core/createTranslatorImpl.esm.js.map +0 -1
- package/dist/core/defaults.esm.js +0 -15
- package/dist/core/defaults.esm.js.map +0 -1
- package/dist/core/initializeConfig.esm.js +0 -29
- package/dist/core/initializeConfig.esm.js.map +0 -1
- package/dist/core/resolveNamespace.esm.js +0 -10
- package/dist/core/resolveNamespace.esm.js.map +0 -1
- package/dist/core/use-intl.esm.js +0 -37
- package/dist/core/use-intl.esm.js.map +0 -1
- package/dist/core/use-intl.esm10.js +0 -28
- package/dist/core/use-intl.esm10.js.map +0 -1
- package/dist/core/use-intl.esm11.js +0 -10
- package/dist/core/use-intl.esm11.js.map +0 -1
- package/dist/core/use-intl.esm2.js +0 -33
- package/dist/core/use-intl.esm2.js.map +0 -1
- package/dist/core/use-intl.esm3.js +0 -14
- package/dist/core/use-intl.esm3.js.map +0 -1
- package/dist/core/use-intl.esm4.js +0 -201
- package/dist/core/use-intl.esm4.js.map +0 -1
- package/dist/core/use-intl.esm5.js +0 -29
- package/dist/core/use-intl.esm5.js.map +0 -1
- package/dist/core/use-intl.esm6.js +0 -138
- package/dist/core/use-intl.esm6.js.map +0 -1
- package/dist/core/use-intl.esm7.js +0 -15
- package/dist/core/use-intl.esm7.js.map +0 -1
- package/dist/core/use-intl.esm8.js +0 -50
- package/dist/core/use-intl.esm8.js.map +0 -1
- package/dist/core/use-intl.esm9.js +0 -32
- package/dist/core/use-intl.esm9.js.map +0 -1
- package/dist/core/validateMessages.esm.js +0 -28
- package/dist/core/validateMessages.esm.js.map +0 -1
- package/dist/core.cjs.development.js +0 -93
- package/dist/core.cjs.development.js.map +0 -1
- package/dist/core.cjs.production.min.js +0 -2
- package/dist/core.cjs.production.min.js.map +0 -1
- package/dist/core.esm.js +0 -7
- package/dist/core.esm.js.map +0 -1
- package/dist/createIntl-8a2b87eb.js +0 -579
- package/dist/createIntl-8a2b87eb.js.map +0 -1
- package/dist/createIntl-f7979de1.js +0 -2
- package/dist/createIntl-f7979de1.js.map +0 -1
- package/dist/react/IntlContext.d.ts +0 -4
- package/dist/react/IntlContext.esm.js +0 -6
- package/dist/react/IntlContext.esm.js.map +0 -1
- package/dist/react/IntlProvider.esm.js +0 -16
- package/dist/react/IntlProvider.esm.js.map +0 -1
- package/dist/react/use-intl.esm.js +0 -26
- package/dist/react/use-intl.esm.js.map +0 -1
- package/dist/react/use-intl.esm10.js +0 -13
- package/dist/react/use-intl.esm10.js.map +0 -1
- package/dist/react/use-intl.esm11.js +0 -6
- package/dist/react/use-intl.esm11.js.map +0 -1
- package/dist/react/use-intl.esm2.js +0 -24
- package/dist/react/use-intl.esm2.js.map +0 -1
- package/dist/react/use-intl.esm3.js +0 -45
- package/dist/react/use-intl.esm3.js.map +0 -1
- package/dist/react/use-intl.esm4.js +0 -16
- package/dist/react/use-intl.esm4.js.map +0 -1
- package/dist/react/use-intl.esm5.js +0 -8
- package/dist/react/use-intl.esm5.js.map +0 -1
- package/dist/react/use-intl.esm6.js +0 -8
- package/dist/react/use-intl.esm6.js.map +0 -1
- package/dist/react/use-intl.esm7.js +0 -30
- package/dist/react/use-intl.esm7.js.map +0 -1
- package/dist/react/use-intl.esm8.js +0 -8
- package/dist/react/use-intl.esm8.js.map +0 -1
- package/dist/react/use-intl.esm9.js +0 -36
- package/dist/react/use-intl.esm9.js.map +0 -1
- package/dist/react/useFormatter.esm.js +0 -24
- package/dist/react/useFormatter.esm.js.map +0 -1
- package/dist/react/useIntl.esm.js +0 -30
- package/dist/react/useIntl.esm.js.map +0 -1
- package/dist/react/useIntlContext.d.ts +0 -1
- package/dist/react/useIntlContext.esm.js +0 -13
- package/dist/react/useIntlContext.esm.js.map +0 -1
- package/dist/react/useLocale.esm.js +0 -8
- package/dist/react/useLocale.esm.js.map +0 -1
- package/dist/react/useMessages.esm.js +0 -8
- package/dist/react/useMessages.esm.js.map +0 -1
- package/dist/react/useNow.esm.js +0 -45
- package/dist/react/useNow.esm.js.map +0 -1
- package/dist/react/useTimeZone.esm.js +0 -8
- package/dist/react/useTimeZone.esm.js.map +0 -1
- package/dist/react/useTranslations.esm.js +0 -26
- package/dist/react/useTranslations.esm.js.map +0 -1
- package/dist/react/useTranslationsImpl.esm.js +0 -36
- package/dist/react/useTranslationsImpl.esm.js.map +0 -1
- package/dist/react.cjs.development.js +0 -184
- package/dist/react.cjs.development.js.map +0 -1
- package/dist/react.cjs.production.min.js +0 -2
- package/dist/react.cjs.production.min.js.map +0 -1
- package/dist/react.esm.js +0 -9
- package/dist/react.esm.js.map +0 -1
- package/dist/use-intl.cjs.development.js +0 -823
- package/dist/use-intl.cjs.development.js.map +0 -1
- package/dist/use-intl.cjs.production.min.js +0 -2
- package/dist/use-intl.cjs.production.min.js.map +0 -1
- package/dist/use-intl.esm.js +0 -15
- package/dist/use-intl.esm.js.map +0 -1
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import { extends as _extends } from '../_virtual/use-intl.esm.js';
|
|
2
|
-
import IntlError, { IntlErrorCode } from './use-intl.esm2.js';
|
|
3
|
-
import { defaultOnError } from './use-intl.esm7.js';
|
|
4
|
-
|
|
5
|
-
var MINUTE = 60;
|
|
6
|
-
var HOUR = MINUTE * 60;
|
|
7
|
-
var DAY = HOUR * 24;
|
|
8
|
-
var WEEK = DAY * 7;
|
|
9
|
-
var MONTH = DAY * (365 / 12); // Approximation
|
|
10
|
-
var YEAR = DAY * 365;
|
|
11
|
-
function getRelativeTimeFormatConfig(seconds) {
|
|
12
|
-
var absValue = Math.abs(seconds);
|
|
13
|
-
var value, unit;
|
|
14
|
-
// We have to round the resulting values, as `Intl.RelativeTimeFormat`
|
|
15
|
-
// will include fractions like '2.1 hours ago'.
|
|
16
|
-
if (absValue < MINUTE) {
|
|
17
|
-
unit = 'second';
|
|
18
|
-
value = Math.round(seconds);
|
|
19
|
-
} else if (absValue < HOUR) {
|
|
20
|
-
unit = 'minute';
|
|
21
|
-
value = Math.round(seconds / MINUTE);
|
|
22
|
-
} else if (absValue < DAY) {
|
|
23
|
-
unit = 'hour';
|
|
24
|
-
value = Math.round(seconds / HOUR);
|
|
25
|
-
} else if (absValue < WEEK) {
|
|
26
|
-
unit = 'day';
|
|
27
|
-
value = Math.round(seconds / DAY);
|
|
28
|
-
} else if (absValue < MONTH) {
|
|
29
|
-
unit = 'week';
|
|
30
|
-
value = Math.round(seconds / WEEK);
|
|
31
|
-
} else if (absValue < YEAR) {
|
|
32
|
-
unit = 'month';
|
|
33
|
-
value = Math.round(seconds / MONTH);
|
|
34
|
-
} else {
|
|
35
|
-
unit = 'year';
|
|
36
|
-
value = Math.round(seconds / YEAR);
|
|
37
|
-
}
|
|
38
|
-
return {
|
|
39
|
-
value: value,
|
|
40
|
-
unit: unit
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
function createFormatter(_ref) {
|
|
44
|
-
var formats = _ref.formats,
|
|
45
|
-
locale = _ref.locale,
|
|
46
|
-
globalNow = _ref.now,
|
|
47
|
-
_ref$onError = _ref.onError,
|
|
48
|
-
onError = _ref$onError === void 0 ? defaultOnError : _ref$onError,
|
|
49
|
-
timeZone = _ref.timeZone;
|
|
50
|
-
function resolveFormatOrOptions(typeFormats, formatOrOptions) {
|
|
51
|
-
var options;
|
|
52
|
-
if (typeof formatOrOptions === 'string') {
|
|
53
|
-
var formatName = formatOrOptions;
|
|
54
|
-
options = typeFormats == null ? void 0 : typeFormats[formatName];
|
|
55
|
-
if (!options) {
|
|
56
|
-
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);
|
|
57
|
-
onError(error);
|
|
58
|
-
throw error;
|
|
59
|
-
}
|
|
60
|
-
} else {
|
|
61
|
-
options = formatOrOptions;
|
|
62
|
-
}
|
|
63
|
-
return options;
|
|
64
|
-
}
|
|
65
|
-
function getFormattedValue(value, formatOrOptions, typeFormats, formatter) {
|
|
66
|
-
var options;
|
|
67
|
-
try {
|
|
68
|
-
options = resolveFormatOrOptions(typeFormats, formatOrOptions);
|
|
69
|
-
} catch (error) {
|
|
70
|
-
return String(value);
|
|
71
|
-
}
|
|
72
|
-
try {
|
|
73
|
-
return formatter(options);
|
|
74
|
-
} catch (error) {
|
|
75
|
-
onError(new IntlError(IntlErrorCode.FORMATTING_ERROR, error.message));
|
|
76
|
-
return String(value);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
function dateTime( /** If a number is supplied, this is interpreted as a UTC timestamp. */
|
|
80
|
-
value,
|
|
81
|
-
/** If a time zone is supplied, the `value` is converted to that time zone.
|
|
82
|
-
* Otherwise the user time zone will be used. */
|
|
83
|
-
formatOrOptions) {
|
|
84
|
-
return getFormattedValue(value, formatOrOptions, formats == null ? void 0 : formats.dateTime, function (options) {
|
|
85
|
-
var _options;
|
|
86
|
-
if (timeZone && !((_options = options) != null && _options.timeZone)) {
|
|
87
|
-
options = _extends({}, options, {
|
|
88
|
-
timeZone: timeZone
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
return new Intl.DateTimeFormat(locale, options).format(value);
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
function number(value, formatOrOptions) {
|
|
95
|
-
return getFormattedValue(value, formatOrOptions, formats == null ? void 0 : formats.number, function (options) {
|
|
96
|
-
return new Intl.NumberFormat(locale, options).format(value);
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
function relativeTime( /** The date time that needs to be formatted. */
|
|
100
|
-
date, /** The reference point in time to which `date` will be formatted in relation to. */
|
|
101
|
-
now) {
|
|
102
|
-
try {
|
|
103
|
-
if (!now) {
|
|
104
|
-
if (globalNow) {
|
|
105
|
-
now = globalNow;
|
|
106
|
-
} else {
|
|
107
|
-
throw new Error(process.env.NODE_ENV !== 'production' ? "The `now` parameter wasn't provided and there was no global fallback configured on the provider." : undefined);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
var dateDate = date instanceof Date ? date : new Date(date);
|
|
111
|
-
var nowDate = now instanceof Date ? now : new Date(now);
|
|
112
|
-
var seconds = (dateDate.getTime() - nowDate.getTime()) / 1000;
|
|
113
|
-
var _getRelativeTimeForma = getRelativeTimeFormatConfig(seconds),
|
|
114
|
-
unit = _getRelativeTimeForma.unit,
|
|
115
|
-
value = _getRelativeTimeForma.value;
|
|
116
|
-
return new Intl.RelativeTimeFormat(locale, {
|
|
117
|
-
numeric: 'auto'
|
|
118
|
-
}).format(value, unit);
|
|
119
|
-
} catch (error) {
|
|
120
|
-
onError(new IntlError(IntlErrorCode.FORMATTING_ERROR, error.message));
|
|
121
|
-
return String(date);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
function list(value, formatOrOptions) {
|
|
125
|
-
return getFormattedValue(value, formatOrOptions, formats == null ? void 0 : formats.list, function (options) {
|
|
126
|
-
return new Intl.ListFormat(locale, options).format(value);
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
return {
|
|
130
|
-
dateTime: dateTime,
|
|
131
|
-
number: number,
|
|
132
|
-
relativeTime: relativeTime,
|
|
133
|
-
list: list
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
export { createFormatter as default };
|
|
138
|
-
//# sourceMappingURL=use-intl.esm6.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-intl.esm6.js","sources":["../../src/core/createFormatter.tsx"],"sourcesContent":["import DateTimeFormatOptions from './DateTimeFormatOptions';\nimport Formats from './Formats';\nimport IntlError, {IntlErrorCode} from './IntlError';\nimport NumberFormatOptions from './NumberFormatOptions';\nimport TimeZone from './TimeZone';\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?: TimeZone;\n onError?(error: IntlError): void;\n formats?: Partial<Formats>;\n now?: Date;\n};\n\nexport default function createFormatter({\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 dateTime(\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 number(\n value: number | bigint,\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 relativeTime(\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 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 function list(\n value: Iterable<string>,\n formatOrOptions?: string | Intl.ListFormatOptions\n ) {\n return getFormattedValue(value, formatOrOptions, formats?.list, (options) =>\n new Intl.ListFormat(locale, options).format(value)\n );\n }\n\n return {dateTime, number, relativeTime, list};\n}\n"],"names":["MINUTE","HOUR","DAY","WEEK","MONTH","YEAR","getRelativeTimeFormatConfig","seconds","absValue","Math","abs","value","unit","round","createFormatter","_ref","formats","locale","globalNow","now","_ref$onError","onError","defaultOnError","timeZone","resolveFormatOrOptions","typeFormats","formatOrOptions","options","formatName","error","IntlError","IntlErrorCode","MISSING_FORMAT","process","env","NODE_ENV","undefined","getFormattedValue","formatter","String","FORMATTING_ERROR","message","dateTime","_options","_extends","Intl","DateTimeFormat","format","number","NumberFormat","relativeTime","date","Error","dateDate","Date","nowDate","getTime","_getRelativeTimeForma","RelativeTimeFormat","numeric","list","ListFormat"],"mappings":";;;;AAOA,IAAMA,MAAM,GAAG,EAAE,CAAA;AACjB,IAAMC,IAAI,GAAGD,MAAM,GAAG,EAAE,CAAA;AACxB,IAAME,GAAG,GAAGD,IAAI,GAAG,EAAE,CAAA;AACrB,IAAME,IAAI,GAAGD,GAAG,GAAG,CAAC,CAAA;AACpB,IAAME,KAAK,GAAGF,GAAG,IAAI,GAAG,GAAG,EAAE,CAAC,CAAC;AAC/B,IAAMG,IAAI,GAAGH,GAAG,GAAG,GAAG,CAAA;AAEtB,SAASI,2BAA2BA,CAACC,OAAe,EAAA;AAClD,EAAA,IAAMC,QAAQ,GAAGC,IAAI,CAACC,GAAG,CAACH,OAAO,CAAC,CAAA;EAClC,IAAII,KAAK,EAAEC,IAAiC,CAAA;AAE5C;AACA;EAEA,IAAIJ,QAAQ,GAAGR,MAAM,EAAE;AACrBY,IAAAA,IAAI,GAAG,QAAQ,CAAA;AACfD,IAAAA,KAAK,GAAGF,IAAI,CAACI,KAAK,CAACN,OAAO,CAAC,CAAA;AAC5B,GAAA,MAAM,IAAIC,QAAQ,GAAGP,IAAI,EAAE;AAC1BW,IAAAA,IAAI,GAAG,QAAQ,CAAA;IACfD,KAAK,GAAGF,IAAI,CAACI,KAAK,CAACN,OAAO,GAAGP,MAAM,CAAC,CAAA;AACrC,GAAA,MAAM,IAAIQ,QAAQ,GAAGN,GAAG,EAAE;AACzBU,IAAAA,IAAI,GAAG,MAAM,CAAA;IACbD,KAAK,GAAGF,IAAI,CAACI,KAAK,CAACN,OAAO,GAAGN,IAAI,CAAC,CAAA;AACnC,GAAA,MAAM,IAAIO,QAAQ,GAAGL,IAAI,EAAE;AAC1BS,IAAAA,IAAI,GAAG,KAAK,CAAA;IACZD,KAAK,GAAGF,IAAI,CAACI,KAA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AC/C;;;;"}
|
|
@@ -1,15 +0,0 @@
|
|
|
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('.');
|
|
9
|
-
}
|
|
10
|
-
function defaultOnError(error) {
|
|
11
|
-
console.error(error);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export { defaultGetMessageFallback, defaultOnError };
|
|
15
|
-
//# sourceMappingURL=use-intl.esm7.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-intl.esm7.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,yBAAyBA,CAACC,KAIzC,EAAA;AACC,EAAA,OAAO,CAACA,KAAK,CAACC,SAAS,EAAED,KAAK,CAACE,GAAG,CAAC,CAACC,MAAM,CAAC,UAACC,IAAI,EAAA;IAAA,OAAKA,IAAI,IAAI,IAAI,CAAA;AAAA,GAAA,CAAC,CAACC,IAAI,CAAC,GAAG,CAAC,CAAA;AAC9E,CAAA;AAEM,SAAUC,cAAcA,CAACC,KAAgB,EAAA;AAC7CC,EAAAA,OAAO,CAACD,KAAK,CAACA,KAAK,CAAC,CAAA;AACtB;;;;"}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose, extends as _extends } from '../_virtual/use-intl.esm.js';
|
|
2
|
-
import IntlError, { IntlErrorCode } from './use-intl.esm2.js';
|
|
3
|
-
import createBaseTranslator from './use-intl.esm4.js';
|
|
4
|
-
import resolveNamespace from './use-intl.esm11.js';
|
|
5
|
-
|
|
6
|
-
var _excluded = ["getMessageFallback", "messages", "namespace", "onError"];
|
|
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);
|
|
13
|
-
// The `namespacePrefix` is part of the type system.
|
|
14
|
-
// See the comment in the function invocation.
|
|
15
|
-
messages = messages[namespacePrefix];
|
|
16
|
-
namespace = resolveNamespace(namespace, namespacePrefix);
|
|
17
|
-
var translator = createBaseTranslator(_extends({}, rest, {
|
|
18
|
-
onError: onError,
|
|
19
|
-
getMessageFallback: getMessageFallback,
|
|
20
|
-
messages: messages,
|
|
21
|
-
namespace: namespace
|
|
22
|
-
}));
|
|
23
|
-
var originalRich = translator.rich;
|
|
24
|
-
function base() {
|
|
25
|
-
return translator.apply(void 0, arguments);
|
|
26
|
-
}
|
|
27
|
-
// Augment `t.rich` to return plain strings
|
|
28
|
-
base.rich = function (key, /** Key value pairs for values to interpolate into the message. */
|
|
29
|
-
values, formats) {
|
|
30
|
-
// `chunks` is returned as a string when no React element
|
|
31
|
-
// is used, therefore it's safe to cast this type.
|
|
32
|
-
var result = originalRich(key, values, formats);
|
|
33
|
-
// When only string chunks are provided to the parser, only strings should be returned here.
|
|
34
|
-
if (typeof result !== 'string') {
|
|
35
|
-
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);
|
|
36
|
-
onError(error);
|
|
37
|
-
return getMessageFallback({
|
|
38
|
-
error: error,
|
|
39
|
-
key: key,
|
|
40
|
-
namespace: namespace
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
return result;
|
|
44
|
-
};
|
|
45
|
-
base.raw = translator.raw;
|
|
46
|
-
return base;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export { createTranslatorImpl as default };
|
|
50
|
-
//# sourceMappingURL=use-intl.esm8.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-intl.esm8.js","sources":["../../src/core/createTranslatorImpl.tsx"],"sourcesContent":["import AbstractIntlMessages from './AbstractIntlMessages';\nimport {InitializedIntlConfig} from './IntlConfig';\nimport IntlError, {IntlErrorCode} from './IntlError';\nimport {\n RichTranslationValues,\n RichTranslationValuesPlain\n} from './TranslationValues';\nimport createBaseTranslator from './createBaseTranslator';\nimport resolveNamespace from './resolveNamespace';\nimport NestedKeyOf from './utils/NestedKeyOf';\n\nexport type CreateTranslatorImplProps<Messages> = Omit<\n InitializedIntlConfig,\n 'messages'\n> & {\n namespace: string;\n messages: Messages;\n};\n\nexport default function createTranslatorImpl<\n Messages extends AbstractIntlMessages,\n NestedKey extends NestedKeyOf<Messages>\n>(\n {\n getMessageFallback,\n messages,\n namespace,\n onError,\n ...rest\n }: CreateTranslatorImplProps<Messages>,\n namespacePrefix: string\n) {\n // The `namespacePrefix` is part of the type system.\n // See the comment in the function invocation.\n messages = messages[namespacePrefix] as Messages;\n namespace = resolveNamespace(namespace, namespacePrefix) as NestedKey;\n\n const translator = createBaseTranslator<Messages, NestedKey>({\n ...rest,\n onError,\n getMessageFallback,\n messages,\n namespace\n });\n\n const originalRich = translator.rich;\n\n function base(...args: Parameters<typeof translator>) {\n return translator(...args);\n }\n\n // Augment `t.rich` to return plain strings\n base.rich = (\n key: Parameters<typeof originalRich>[0],\n /** Key value pairs for values to interpolate into the message. */\n values: RichTranslationValuesPlain,\n formats?: Parameters<typeof originalRich>[2]\n ): string => {\n // `chunks` is returned as a string when no React element\n // is used, therefore it's safe to cast this type.\n const result = originalRich(key, values as RichTranslationValues, formats);\n\n // When only string chunks are provided to the parser, only strings should be returned here.\n if (typeof result !== 'string') {\n const error = new IntlError(\n IntlErrorCode.FORMATTING_ERROR,\n process.env.NODE_ENV !== 'production'\n ? \"`createTranslator` only accepts functions for rich text formatting that receive and return strings.\\n\\nE.g. t.rich('rich', {b: (chunks) => `<b>${chunks}</b>`})\"\n : undefined\n );\n\n onError(error);\n return getMessageFallback({error, key, namespace});\n }\n\n return result;\n };\n\n base.raw = translator.raw;\n\n return base;\n}\n"],"names":["createTranslatorImpl","_ref","namespacePrefix","getMessageFallback","messages","namespace","onError","rest","_objectWithoutPropertiesLoose","_excluded","resolveNamespace","translator","createBaseTranslator","_extends","originalRich","rich","base","apply","arguments","key","values","formats","result","error","IntlError","IntlErrorCode","FORMATTING_ERROR","process","env","NODE_ENV","undefined","raw"],"mappings":";;;;;;AAmBc,SAAUA,oBAAoBA,CAAAC,IAAA,EAW1CC,eAAuB,EAAA;AAAA,EAAA,IANrBC,kBAAkB,GAAAF,IAAA,CAAlBE,kBAAkB;IAClBC,QAAQ,GAAAH,IAAA,CAARG,QAAQ;IACRC,SAAS,GAAAJ,IAAA,CAATI,SAAS;IACTC,OAAO,GAAAL,IAAA,CAAPK,OAAO;AACJC,IAAAA,IAAI,GAAAC,6BAAA,CAAAP,IAAA,EAAAQ,SAAA,CAAA,CAAA;AAIT;AACA;AACAL,EAAAA,QAAQ,GAAGA,QAAQ,CAACF,eAAe,CAAa,CAAA;AAChDG,EAAAA,SAAS,GAAGK,gBAAgB,CAACL,SAAS,EAAEH,eAAe,CAAc,CAAA;AAErE,EAAA,IAAMS,UAAU,GAAGC,oBAAoB,CAAAC,QAAA,KAClCN,IAAI,EAAA;AACPD,IAAAA,OAAO,EAAPA,OAAO;AACPH,IAAAA,kBAAkB,EAAlBA,kBAAkB;AAClBC,IAAAA,QAAQ,EAARA,QAAQ;AACRC,IAAAA,SAAS,EAATA,SAAAA;AAAS,GAAA,CACV,CAAC,CAAA;AAEF,EAAA,IAAMS,YAAY,GAAGH,UAAU,CAACI,IAAI,CAAA;EAEpC,SAASC,IAAIA,GAAuC;AAClD,IAAA,OAAOL,UAAU,CAAAM,KAAA,CAAA,KAAA,CAAA,EAAAC,SAAQ,CAAC,CAAA;AAC5B,GAAA;AAEA;AACAF,EAAAA,IAAI,CAACD,IAAI,GAAG,UACVI,GAAuC;EAEvCC,MAAkC,EAClCC,OAA4C,EAClC;AACV;AACA;IACA,IAAMC,MAAM,GAAGR,YAAY,CAACK,GAAG,EAAEC,MAA+B,EAAEC,OAAO,CAAC,CAAA;AAE1E;AACA,IAAA,IAAI,OAAOC,MAAM,KAAK,QAAQ,EAAE;MAC9B,IAAMC,KAAK,GAAG,IAAIC,SAAS,CACzBC,aAAa,CAACC,gBAAgB,EAC9BC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,GACjC,iKAAiK,GACjKC,SAAS,CACd,CAAA;MAEDxB,OAAO,CAACiB,KAAK,CAAC,CAAA;AACd,MAAA,OAAOpB,kBAAkB,CAAC;AAACoB,QAAAA,KAAK,EAALA,KAAK;AAAEJ,QAAAA,GAAG,EAAHA,GAAG;AAAEd,QAAAA,SAAS,EAATA,SAAAA;AAAU,OAAA,CAAC,CAAA;AACnD,KAAA;AAED,IAAA,OAAOiB,MAAM,CAAA;GACd,CAAA;AAEDN,EAAAA,IAAI,CAACe,GAAG,GAAGpB,UAAU,CAACoB,GAAG,CAAA;AAEzB,EAAA,OAAOf,IAAI,CAAA;AACb;;;;"}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { extends as _extends } from '../_virtual/use-intl.esm.js';
|
|
2
|
-
|
|
3
|
-
function setTimeZoneInFormats(formats, timeZone) {
|
|
4
|
-
if (!formats) return formats;
|
|
5
|
-
// The only way to set a time zone with `intl-messageformat` is to merge it into the formats
|
|
6
|
-
// https://github.com/formatjs/formatjs/blob/8256c5271505cf2606e48e3c97ecdd16ede4f1b5/packages/intl/src/message.ts#L15
|
|
7
|
-
return Object.keys(formats).reduce(function (acc, key) {
|
|
8
|
-
acc[key] = _extends({
|
|
9
|
-
timeZone: timeZone
|
|
10
|
-
}, formats[key]);
|
|
11
|
-
return acc;
|
|
12
|
-
}, {});
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* `intl-messageformat` uses separate keys for `date` and `time`, but there's
|
|
16
|
-
* only one native API: `Intl.DateTimeFormat`. Additionally you might want to
|
|
17
|
-
* include both a time and a date in a value, therefore the separation doesn't
|
|
18
|
-
* seem so useful. We offer a single `dateTime` namespace instead, but we have
|
|
19
|
-
* to convert the format before `intl-messageformat` can be used.
|
|
20
|
-
*/
|
|
21
|
-
function convertFormatsToIntlMessageFormat(formats, timeZone) {
|
|
22
|
-
var formatsWithTimeZone = timeZone ? _extends({}, formats, {
|
|
23
|
-
dateTime: setTimeZoneInFormats(formats.dateTime, timeZone)
|
|
24
|
-
}) : formats;
|
|
25
|
-
return _extends({}, formatsWithTimeZone, {
|
|
26
|
-
date: formatsWithTimeZone == null ? void 0 : formatsWithTimeZone.dateTime,
|
|
27
|
-
time: formatsWithTimeZone == null ? void 0 : formatsWithTimeZone.dateTime
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export { convertFormatsToIntlMessageFormat as default };
|
|
32
|
-
//# sourceMappingURL=use-intl.esm9.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-intl.esm9.js","sources":["../../src/core/convertFormatsToIntlMessageFormat.tsx"],"sourcesContent":["import {Formats as IntlFormats} from 'intl-messageformat';\nimport DateTimeFormatOptions from './DateTimeFormatOptions';\nimport Formats from './Formats';\nimport TimeZone from './TimeZone';\n\nfunction setTimeZoneInFormats(\n formats: Record<string, DateTimeFormatOptions> | undefined,\n timeZone: TimeZone\n) {\n if (!formats) return formats;\n\n // The only way to set a time zone with `intl-messageformat` is to merge it into the formats\n // https://github.com/formatjs/formatjs/blob/8256c5271505cf2606e48e3c97ecdd16ede4f1b5/packages/intl/src/message.ts#L15\n return Object.keys(formats).reduce(\n (acc: Record<string, DateTimeFormatOptions>, key) => {\n acc[key] = {\n timeZone,\n ...formats[key]\n };\n return acc;\n },\n {}\n );\n}\n\n/**\n * `intl-messageformat` uses separate keys for `date` and `time`, but there's\n * only one native API: `Intl.DateTimeFormat`. Additionally you might want to\n * include both a time and a date in a value, therefore the separation doesn't\n * seem so useful. We offer a single `dateTime` namespace instead, but we have\n * to convert the format before `intl-messageformat` can be used.\n */\nexport default function convertFormatsToIntlMessageFormat(\n formats: Partial<Formats>,\n timeZone?: TimeZone\n): Partial<IntlFormats> {\n const formatsWithTimeZone = timeZone\n ? {...formats, dateTime: setTimeZoneInFormats(formats.dateTime, timeZone)}\n : formats;\n\n return {\n ...formatsWithTimeZone,\n date: formatsWithTimeZone?.dateTime,\n time: formatsWithTimeZone?.dateTime\n };\n}\n"],"names":["setTimeZoneInFormats","formats","timeZone","Object","keys","reduce","acc","key","_extends","convertFormatsToIntlMessageFormat","formatsWithTimeZone","dateTime","date","time"],"mappings":";;AAKA,SAASA,oBAAoBA,CAC3BC,OAA0D,EAC1DC,QAAkB,EAAA;AAElB,EAAA,IAAI,CAACD,OAAO,EAAE,OAAOA,OAAO,CAAA;AAE5B;AACA;AACA,EAAA,OAAOE,MAAM,CAACC,IAAI,CAACH,OAAO,CAAC,CAACI,MAAM,CAChC,UAACC,GAA0C,EAAEC,GAAG,EAAI;AAClDD,IAAAA,GAAG,CAACC,GAAG,CAAC,GAAAC,QAAA,CAAA;AACNN,MAAAA,QAAQ,EAARA,QAAAA;AAAQ,KAAA,EACLD,OAAO,CAACM,GAAG,CAAC,CAChB,CAAA;AACD,IAAA,OAAOD,GAAG,CAAA;GACX,EACD,EAAE,CACH,CAAA;AACH,CAAA;AAEA;;;;;;AAMG;AACW,SAAUG,iCAAiCA,CACvDR,OAAyB,EACzBC,QAAmB,EAAA;AAEnB,EAAA,IAAMQ,mBAAmB,GAAGR,QAAQ,GAAAM,QAAA,KAC5BP,OAAO,EAAA;AAAEU,IAAAA,QAAQ,EAAEX,oBAAoB,CAACC,OAAO,CAACU,QAAQ,EAAET,QAAQ,CAAA;AAAC,GAAA,CAAA,GACvED,OAAO,CAAA;EAEX,OAAAO,QAAA,KACKE,mBAAmB,EAAA;AACtBE,IAAAA,IAAI,EAAEF,mBAAmB,IAAnBA,IAAAA,GAAAA,KAAAA,CAAAA,GAAAA,mBAAmB,CAAEC,QAAQ;AACnCE,IAAAA,IAAI,EAAEH,mBAAmB,IAAnBA,IAAAA,GAAAA,KAAAA,CAAAA,GAAAA,mBAAmB,CAAEC,QAAAA;AAAQ,GAAA,CAAA,CAAA;AAEvC;;;;"}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import IntlError, { IntlErrorCode } from './IntlError.esm.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
|
-
if (key.includes('.')) {
|
|
8
|
-
var keyLabel = key;
|
|
9
|
-
if (parentPath) keyLabel += " (at " + parentPath + ")";
|
|
10
|
-
invalidKeyLabels.push(keyLabel);
|
|
11
|
-
}
|
|
12
|
-
if (messageOrMessages != null && typeof messageOrMessages === 'object') {
|
|
13
|
-
validateMessagesSegment(messageOrMessages, invalidKeyLabels, [parentPath, key].filter(function (part) {
|
|
14
|
-
return part != null;
|
|
15
|
-
}).join('.'));
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
function validateMessages(messages, onError) {
|
|
20
|
-
var invalidKeyLabels = [];
|
|
21
|
-
validateMessagesSegment(messages, invalidKeyLabels);
|
|
22
|
-
if (invalidKeyLabels.length > 0) {
|
|
23
|
-
onError(new IntlError(IntlErrorCode.INVALID_KEY, process.env.NODE_ENV !== 'production' ? "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(', ') + "\n\nIf you're migrating from a flat structure, you can convert your messages as follows:\n\nimport {set} from \"lodash\";\n\nconst input = {\n \"one.one\": \"1.1\",\n \"one.two\": \"1.2\",\n \"two.one.one\": \"2.1.1\"\n};\n\nconst output = Object.entries(input).reduce(\n (acc, [key, value]) => set(acc, key, value),\n {}\n);\n\n// Output:\n//\n// {\n// \"one\": {\n// \"one\": \"1.1\",\n// \"two\": \"1.2\"\n// },\n// \"two\": {\n// \"one\": {\n// \"one\": \"2.1.1\"\n// }\n// }\n// }\n" : undefined));
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export { validateMessages as default };
|
|
28
|
-
//# sourceMappingURL=validateMessages.esm.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validateMessages.esm.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 process.env.NODE_ENV !== 'production'\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\nIf you're migrating from a flat structure, you can convert your messages as follows:\n\nimport {set} from \"lodash\";\n\nconst input = {\n \"one.one\": \"1.1\",\n \"one.two\": \"1.2\",\n \"two.one.one\": \"2.1.1\"\n};\n\nconst output = Object.entries(input).reduce(\n (acc, [key, value]) => set(acc, key, value),\n {}\n);\n\n// Output:\n//\n// {\n// \"one\": {\n// \"one\": \"1.1\",\n// \"two\": \"1.2\"\n// },\n// \"two\": {\n// \"one\": {\n// \"one\": \"2.1.1\"\n// }\n// }\n// }\n`\n : undefined\n )\n );\n }\n}\n"],"names":["validateMessagesSegment","messages","invalidKeyLabels","parentPath","Object","entries","forEach","_ref","key","messageOrMessages","includes","keyLabel","push","filter","part","join","validateMessages","onError","length","IntlError","IntlErrorCode","INVALID_KEY","process","env","NODE_ENV","undefined"],"mappings":";;AAGA,SAASA,uBAAuBA,CAC9BC,QAA8B,EAC9BC,gBAA+B,EAC/BC,UAAmB,EAAA;EAEnBC,MAAM,CAACC,OAAO,CAACJ,QAAQ,CAAC,CAACK,OAAO,CAAC,UAAAC,IAAA,EAA6B;IAAA,IAA3BC,GAAG,GAAAD,IAAA,CAAA,CAAA,CAAA;AAAEE,MAAAA,iBAAiB,GAAAF,IAAA,CAAA,CAAA,CAAA,CAAA;AACvD,IAAA,IAAIC,GAAG,CAACE,QAAQ,CAAC,GAAG,CAAC,EAAE;MACrB,IAAIC,QAAQ,GAAGH,GAAG,CAAA;AAClB,MAAA,IAAIL,UAAU,EAAEQ,QAAQ,IAAA,OAAA,GAAYR,UAAU,GAAG,GAAA,CAAA;AACjDD,MAAAA,gBAAgB,CAACU,IAAI,CAACD,QAAQ,CAAC,CAAA;AAChC,KAAA;IAED,IAAIF,iBAAiB,IAAI,IAAI,IAAI,OAAOA,iBAAiB,KAAK,QAAQ,EAAE;AACtET,MAAAA,uBAAuB,CACrBS,iBAAiB,EACjBP,gBAAgB,EAChB,CAACC,UAAU,EAAEK,GAAG,CAAC,CAACK,MAAM,CAAC,UAACC,IAAI,EAAA;QAAA,OAAKA,IAAI,IAAI,IAAI,CAAA;AAAA,OAAA,CAAC,CAACC,IAAI,CAAC,GAAG,CAAC,CAC3D,CAAA;AACF,KAAA;AACH,GAAC,CAAC,CAAA;AACJ,CAAA;AAEc,SAAUC,gBAAgBA,CACtCf,QAA8B,EAC9BgB,OAAmC,EAAA;EAEnC,IAAMf,gBAAgB,GAAkB,EAAE,CAAA;AAC1CF,EAAAA,uBAAuB,CAACC,QAAQ,EAAEC,gBAAgB,CAAC,CAAA;AAEnD,EAAA,IAAIA,gBAAgB,CAACgB,MAAM,GAAG,CAAC,EAAE;AAC/BD,IAAAA,OAAO,CACL,IAAIE,SAAS,CACXC,aAAa,CAACC,WAAW,EACzBC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,GAI/BtB,2JAAAA,IAAAA,gBAAgB,CAACgB,MAAM,KAAK,CAAC,GAAG,KAAK,GAAG,MAC1C,CAAKhB,GAAAA,IAAAA,GAAAA,gBAAgB,CAACa,IAAI,CAAC,IAAI,CAAC,GA+BhCU,4gBAAAA,GAAAA,SAAS,CACd,CACF,CAAA;AACF,GAAA;AACH;;;;"}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var createIntl = require('./createIntl-8a2b87eb.js');
|
|
6
|
-
require('intl-messageformat');
|
|
7
|
-
require('react');
|
|
8
|
-
|
|
9
|
-
var _excluded$1 = ["getMessageFallback", "messages", "namespace", "onError"];
|
|
10
|
-
function createTranslatorImpl(_ref, namespacePrefix) {
|
|
11
|
-
var getMessageFallback = _ref.getMessageFallback,
|
|
12
|
-
messages = _ref.messages,
|
|
13
|
-
namespace = _ref.namespace,
|
|
14
|
-
onError = _ref.onError,
|
|
15
|
-
rest = createIntl._objectWithoutPropertiesLoose(_ref, _excluded$1);
|
|
16
|
-
// The `namespacePrefix` is part of the type system.
|
|
17
|
-
// See the comment in the function invocation.
|
|
18
|
-
messages = messages[namespacePrefix];
|
|
19
|
-
namespace = createIntl.resolveNamespace(namespace, namespacePrefix);
|
|
20
|
-
var translator = createIntl.createBaseTranslator(createIntl._extends({}, rest, {
|
|
21
|
-
onError: onError,
|
|
22
|
-
getMessageFallback: getMessageFallback,
|
|
23
|
-
messages: messages,
|
|
24
|
-
namespace: namespace
|
|
25
|
-
}));
|
|
26
|
-
var originalRich = translator.rich;
|
|
27
|
-
function base() {
|
|
28
|
-
return translator.apply(void 0, arguments);
|
|
29
|
-
}
|
|
30
|
-
// Augment `t.rich` to return plain strings
|
|
31
|
-
base.rich = function (key, /** Key value pairs for values to interpolate into the message. */
|
|
32
|
-
values, formats) {
|
|
33
|
-
// `chunks` is returned as a string when no React element
|
|
34
|
-
// is used, therefore it's safe to cast this type.
|
|
35
|
-
var result = originalRich(key, values, formats);
|
|
36
|
-
// When only string chunks are provided to the parser, only strings should be returned here.
|
|
37
|
-
if (typeof result !== 'string') {
|
|
38
|
-
var error = new createIntl.IntlError(createIntl.IntlErrorCode.FORMATTING_ERROR, "`createTranslator` only accepts functions for rich text formatting that receive and return strings.\n\nE.g. t.rich('rich', {b: (chunks) => `<b>${chunks}</b>`})" );
|
|
39
|
-
onError(error);
|
|
40
|
-
return getMessageFallback({
|
|
41
|
-
error: error,
|
|
42
|
-
key: key,
|
|
43
|
-
namespace: namespace
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
return result;
|
|
47
|
-
};
|
|
48
|
-
base.raw = translator.raw;
|
|
49
|
-
return base;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
var _excluded = ["getMessageFallback", "messages", "namespace", "onError"];
|
|
53
|
-
/**
|
|
54
|
-
* Translates messages from the given namespace by using the ICU syntax.
|
|
55
|
-
* See https://formatjs.io/docs/core-concepts/icu-syntax.
|
|
56
|
-
*
|
|
57
|
-
* If no namespace is provided, all available messages are returned.
|
|
58
|
-
* The namespace can also indicate nesting by using a dot
|
|
59
|
-
* (e.g. `namespace.Component`).
|
|
60
|
-
*/
|
|
61
|
-
function createTranslator(_ref) {
|
|
62
|
-
var _ref$getMessageFallba = _ref.getMessageFallback,
|
|
63
|
-
getMessageFallback = _ref$getMessageFallba === void 0 ? createIntl.defaultGetMessageFallback : _ref$getMessageFallba,
|
|
64
|
-
messages = _ref.messages,
|
|
65
|
-
namespace = _ref.namespace,
|
|
66
|
-
_ref$onError = _ref.onError,
|
|
67
|
-
onError = _ref$onError === void 0 ? createIntl.defaultOnError : _ref$onError,
|
|
68
|
-
rest = createIntl._objectWithoutPropertiesLoose(_ref, _excluded);
|
|
69
|
-
// We have to wrap the actual function so the type inference for the optional
|
|
70
|
-
// namespace works correctly. See https://stackoverflow.com/a/71529575/343045
|
|
71
|
-
// The prefix ("!") is arbitrary.
|
|
72
|
-
return createTranslatorImpl(createIntl._extends({}, rest, {
|
|
73
|
-
onError: onError,
|
|
74
|
-
getMessageFallback: getMessageFallback,
|
|
75
|
-
messages: {
|
|
76
|
-
'!': messages
|
|
77
|
-
},
|
|
78
|
-
// @ts-ignore
|
|
79
|
-
namespace: namespace ? "!." + namespace : '!'
|
|
80
|
-
}), '!');
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
exports.IntlError = createIntl.IntlError;
|
|
84
|
-
Object.defineProperty(exports, 'IntlErrorCode', {
|
|
85
|
-
enumerable: true,
|
|
86
|
-
get: function () { return createIntl.IntlErrorCode; }
|
|
87
|
-
});
|
|
88
|
-
exports.createBaseTranslator = createIntl.createBaseTranslator;
|
|
89
|
-
exports.createFormatter = createIntl.createFormatter;
|
|
90
|
-
exports.createIntl = createIntl.createIntl;
|
|
91
|
-
exports.initializeConfig = createIntl.initializeConfig;
|
|
92
|
-
exports.createTranslator = createTranslator;
|
|
93
|
-
//# sourceMappingURL=core.cjs.development.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"core.cjs.development.js","sources":["../src/core/createTranslatorImpl.tsx","../src/core/createTranslator.tsx"],"sourcesContent":["import AbstractIntlMessages from './AbstractIntlMessages';\nimport {InitializedIntlConfig} from './IntlConfig';\nimport IntlError, {IntlErrorCode} from './IntlError';\nimport {\n RichTranslationValues,\n RichTranslationValuesPlain\n} from './TranslationValues';\nimport createBaseTranslator from './createBaseTranslator';\nimport resolveNamespace from './resolveNamespace';\nimport NestedKeyOf from './utils/NestedKeyOf';\n\nexport type CreateTranslatorImplProps<Messages> = Omit<\n InitializedIntlConfig,\n 'messages'\n> & {\n namespace: string;\n messages: Messages;\n};\n\nexport default function createTranslatorImpl<\n Messages extends AbstractIntlMessages,\n NestedKey extends NestedKeyOf<Messages>\n>(\n {\n getMessageFallback,\n messages,\n namespace,\n onError,\n ...rest\n }: CreateTranslatorImplProps<Messages>,\n namespacePrefix: string\n) {\n // The `namespacePrefix` is part of the type system.\n // See the comment in the function invocation.\n messages = messages[namespacePrefix] as Messages;\n namespace = resolveNamespace(namespace, namespacePrefix) as NestedKey;\n\n const translator = createBaseTranslator<Messages, NestedKey>({\n ...rest,\n onError,\n getMessageFallback,\n messages,\n namespace\n });\n\n const originalRich = translator.rich;\n\n function base(...args: Parameters<typeof translator>) {\n return translator(...args);\n }\n\n // Augment `t.rich` to return plain strings\n base.rich = (\n key: Parameters<typeof originalRich>[0],\n /** Key value pairs for values to interpolate into the message. */\n values: RichTranslationValuesPlain,\n formats?: Parameters<typeof originalRich>[2]\n ): string => {\n // `chunks` is returned as a string when no React element\n // is used, therefore it's safe to cast this type.\n const result = originalRich(key, values as RichTranslationValues, formats);\n\n // When only string chunks are provided to the parser, only strings should be returned here.\n if (typeof result !== 'string') {\n const error = new IntlError(\n IntlErrorCode.FORMATTING_ERROR,\n process.env.NODE_ENV !== 'production'\n ? \"`createTranslator` only accepts functions for rich text formatting that receive and return strings.\\n\\nE.g. t.rich('rich', {b: (chunks) => `<b>${chunks}</b>`})\"\n : undefined\n );\n\n onError(error);\n return getMessageFallback({error, key, namespace});\n }\n\n return result;\n };\n\n base.raw = translator.raw;\n\n return base;\n}\n","import Formats from './Formats';\nimport IntlConfig from './IntlConfig';\nimport TranslationValues, {\n RichTranslationValuesPlain\n} from './TranslationValues';\nimport createTranslatorImpl from './createTranslatorImpl';\nimport {defaultGetMessageFallback, defaultOnError} from './defaults';\nimport MessageKeys from './utils/MessageKeys';\nimport NamespaceKeys from './utils/NamespaceKeys';\nimport NestedKeyOf from './utils/NestedKeyOf';\nimport NestedValueOf from './utils/NestedValueOf';\n\n/**\n * Translates messages from the given namespace by using the ICU syntax.\n * See https://formatjs.io/docs/core-concepts/icu-syntax.\n *\n * If no namespace is provided, all available messages are returned.\n * The namespace can also indicate nesting by using a dot\n * (e.g. `namespace.Component`).\n */\nexport default function createTranslator<\n NestedKey extends NamespaceKeys<\n IntlMessages,\n NestedKeyOf<IntlMessages>\n > = never\n>({\n getMessageFallback = defaultGetMessageFallback,\n messages,\n namespace,\n onError = defaultOnError,\n ...rest\n}: Omit<IntlConfig<IntlMessages>, 'defaultTranslationValues' | 'messages'> & {\n messages: NonNullable<IntlConfig<IntlMessages>['messages']>;\n namespace?: NestedKey;\n}): // Explicitly defining the return type is necessary as TypeScript would get it wrong\n{\n // Default invocation\n <\n TargetKey extends MessageKeys<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >\n >\n >\n >(\n key: TargetKey,\n values?: TranslationValues,\n formats?: Partial<Formats>\n ): string;\n\n // `rich`\n rich<\n TargetKey extends MessageKeys<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >\n >\n >\n >(\n key: TargetKey,\n values?: RichTranslationValuesPlain,\n formats?: Partial<Formats>\n ): string;\n\n // `raw`\n raw<\n TargetKey extends MessageKeys<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >\n >\n >\n >(\n key: TargetKey\n ): any;\n} {\n // We have to wrap the actual function so the type inference for the optional\n // namespace works correctly. See https://stackoverflow.com/a/71529575/343045\n // The prefix (\"!\") is arbitrary.\n return createTranslatorImpl<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >(\n {\n ...rest,\n onError,\n getMessageFallback,\n messages: {'!': messages},\n // @ts-ignore\n namespace: namespace ? `!.${namespace}` : '!'\n },\n '!'\n );\n}\n"],"names":["createTranslatorImpl","_ref","namespacePrefix","getMessageFallback","messages","namespace","onError","rest","_objectWithoutPropertiesLoose","_excluded","resolveNamespace","translator","createBaseTranslator","_extends","originalRich","rich","base","apply","arguments","key","values","formats","result","error","IntlError","IntlErrorCode","FORMATTING_ERROR","raw","createTranslator","_ref$getMessageFallba","defaultGetMessageFallback","_ref$onError","defaultOnError"],"mappings":";;;;;;;;;AAmBc,SAAUA,oBAAoBA,CAAAC,IAAA,EAW1CC,eAAuB,EAAA;AAAA,EAAA,IANrBC,kBAAkB,GAAAF,IAAA,CAAlBE,kBAAkB;IAClBC,QAAQ,GAAAH,IAAA,CAARG,QAAQ;IACRC,SAAS,GAAAJ,IAAA,CAATI,SAAS;IACTC,OAAO,GAAAL,IAAA,CAAPK,OAAO;AACJC,IAAAA,IAAI,GAAAC,wCAAA,CAAAP,IAAA,EAAA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CAACgB,GAAG,CAAA;AAEzB,EAAA,OAAOX,IAAI,CAAA;AACb;;;ACrEA;;;;;;;AAOG;AACqB,SAAAY,gBAAgBA,CAAA3B,IAAA,EAcvC;AAAA,EAAA,IAAA4B,qBAAA,GAAA5B,IAAA,CARCE,kBAAkB;AAAlBA,IAAAA,kBAAkB,GAAA0B,qBAAA,KAAGC,KAAAA,CAAAA,GAAAA,oCAAyB,GAAAD,qBAAA;IAC9CzB,QAAQ,GAAAH,IAAA,CAARG,QAAQ;IACRC,SAAS,GAAAJ,IAAA,CAATI,SAAS;IAAA0B,YAAA,GAAA9B,IAAA,CACTK,OAAO;AAAPA,IAAAA,OAAO,GAAAyB,YAAA,KAAGC,KAAAA,CAAAA,GAAAA,yBAAc,GAAAD,YAAA;AACrBxB,IAAAA,IAAI,GAAAC,wCAAA,CAAAP,IAAA,EAAAQ,SAAA,CAAA,CAAA;AAgEP;AACA;AACA;AACA,EAAA,OAAOT,oBAAoB,CAAAa,mBAAA,CAAA,EAAA,EAKpBN,IAAI,EAAA;AACPD,IAAAA,OAAO,EAAPA,OAAO;AACPH,IAAAA,kBAAkB,EAAlBA,kBAAkB;AAClBC,IAAAA,QAAQ,EAAE;AAAC,MAAA,GAAG,EAAEA,QAAAA;KAAS;AACzB;AACAC,IAAAA,SAAS,EAAEA,SAAS,GAAQA,IAAAA,GAAAA,SAAS,GAAK,GAAA;AAAG,GAAA,CAAA,EAE/C,GAAG,CACJ,CAAA;AACH;;;;;;;;;;;;;"}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./createIntl-f7979de1.js");require("intl-messageformat"),require("react");var r=["getMessageFallback","messages","namespace","onError"],a=["getMessageFallback","messages","namespace","onError"];exports.IntlError=e.IntlError,Object.defineProperty(exports,"IntlErrorCode",{enumerable:!0,get:function(){return e.IntlErrorCode}}),exports.createBaseTranslator=e.createBaseTranslator,exports.createFormatter=e.createFormatter,exports.createIntl=e.createIntl,exports.initializeConfig=e.initializeConfig,exports.createTranslator=function(t){var s=t.getMessageFallback,o=void 0===s?e.defaultGetMessageFallback:s,n=t.messages,c=t.namespace,l=t.onError,i=void 0===l?e.defaultOnError:l,g=e._objectWithoutPropertiesLoose(t,a);return function(a,t){var s=a.getMessageFallback,o=a.messages,n=a.namespace,c=a.onError,l=e._objectWithoutPropertiesLoose(a,r);o=o["!"],n=e.resolveNamespace(n,"!");var i=e.createBaseTranslator(e._extends({},l,{onError:c,getMessageFallback:s,messages:o,namespace:n})),g=i.rich;function p(){return i.apply(void 0,arguments)}return p.rich=function(r,a,t){var o=g(r,a,t);if("string"!=typeof o){var l=new e.IntlError(e.IntlErrorCode.FORMATTING_ERROR,void 0);return c(l),s({error:l,key:r,namespace:n})}return o},p.raw=i.raw,p}(e._extends({},g,{onError:i,getMessageFallback:o,messages:{"!":n},namespace:c?"!."+c:"!"}))};
|
|
2
|
-
//# sourceMappingURL=core.cjs.production.min.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"core.cjs.production.min.js","sources":["../src/core/createTranslator.tsx","../src/core/createTranslatorImpl.tsx"],"sourcesContent":["import Formats from './Formats';\nimport IntlConfig from './IntlConfig';\nimport TranslationValues, {\n RichTranslationValuesPlain\n} from './TranslationValues';\nimport createTranslatorImpl from './createTranslatorImpl';\nimport {defaultGetMessageFallback, defaultOnError} from './defaults';\nimport MessageKeys from './utils/MessageKeys';\nimport NamespaceKeys from './utils/NamespaceKeys';\nimport NestedKeyOf from './utils/NestedKeyOf';\nimport NestedValueOf from './utils/NestedValueOf';\n\n/**\n * Translates messages from the given namespace by using the ICU syntax.\n * See https://formatjs.io/docs/core-concepts/icu-syntax.\n *\n * If no namespace is provided, all available messages are returned.\n * The namespace can also indicate nesting by using a dot\n * (e.g. `namespace.Component`).\n */\nexport default function createTranslator<\n NestedKey extends NamespaceKeys<\n IntlMessages,\n NestedKeyOf<IntlMessages>\n > = never\n>({\n getMessageFallback = defaultGetMessageFallback,\n messages,\n namespace,\n onError = defaultOnError,\n ...rest\n}: Omit<IntlConfig<IntlMessages>, 'defaultTranslationValues' | 'messages'> & {\n messages: NonNullable<IntlConfig<IntlMessages>['messages']>;\n namespace?: NestedKey;\n}): // Explicitly defining the return type is necessary as TypeScript would get it wrong\n{\n // Default invocation\n <\n TargetKey extends MessageKeys<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >\n >\n >\n >(\n key: TargetKey,\n values?: TranslationValues,\n formats?: Partial<Formats>\n ): string;\n\n // `rich`\n rich<\n TargetKey extends MessageKeys<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >\n >\n >\n >(\n key: TargetKey,\n values?: RichTranslationValuesPlain,\n formats?: Partial<Formats>\n ): string;\n\n // `raw`\n raw<\n TargetKey extends MessageKeys<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >\n >\n >\n >(\n key: TargetKey\n ): any;\n} {\n // We have to wrap the actual function so the type inference for the optional\n // namespace works correctly. See https://stackoverflow.com/a/71529575/343045\n // The prefix (\"!\") is arbitrary.\n return createTranslatorImpl<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >(\n {\n ...rest,\n onError,\n getMessageFallback,\n messages: {'!': messages},\n // @ts-ignore\n namespace: namespace ? `!.${namespace}` : '!'\n },\n '!'\n );\n}\n","import AbstractIntlMessages from './AbstractIntlMessages';\nimport {InitializedIntlConfig} from './IntlConfig';\nimport IntlError, {IntlErrorCode} from './IntlError';\nimport {\n RichTranslationValues,\n RichTranslationValuesPlain\n} from './TranslationValues';\nimport createBaseTranslator from './createBaseTranslator';\nimport resolveNamespace from './resolveNamespace';\nimport NestedKeyOf from './utils/NestedKeyOf';\n\nexport type CreateTranslatorImplProps<Messages> = Omit<\n InitializedIntlConfig,\n 'messages'\n> & {\n namespace: string;\n messages: Messages;\n};\n\nexport default function createTranslatorImpl<\n Messages extends AbstractIntlMessages,\n NestedKey extends NestedKeyOf<Messages>\n>(\n {\n getMessageFallback,\n messages,\n namespace,\n onError,\n ...rest\n }: CreateTranslatorImplProps<Messages>,\n namespacePrefix: string\n) {\n // The `namespacePrefix` is part of the type system.\n // See the comment in the function invocation.\n messages = messages[namespacePrefix] as Messages;\n namespace = resolveNamespace(namespace, namespacePrefix) as NestedKey;\n\n const translator = createBaseTranslator<Messages, NestedKey>({\n ...rest,\n onError,\n getMessageFallback,\n messages,\n namespace\n });\n\n const originalRich = translator.rich;\n\n function base(...args: Parameters<typeof translator>) {\n return translator(...args);\n }\n\n // Augment `t.rich` to return plain strings\n base.rich = (\n key: Parameters<typeof originalRich>[0],\n /** Key value pairs for values to interpolate into the message. */\n values: RichTranslationValuesPlain,\n formats?: Parameters<typeof originalRich>[2]\n ): string => {\n // `chunks` is returned as a string when no React element\n // is used, therefore it's safe to cast this type.\n const result = originalRich(key, values as RichTranslationValues, formats);\n\n // When only string chunks are provided to the parser, only strings should be returned here.\n if (typeof result !== 'string') {\n const error = new IntlError(\n IntlErrorCode.FORMATTING_ERROR,\n process.env.NODE_ENV !== 'production'\n ? \"`createTranslator` only accepts functions for rich text formatting that receive and return strings.\\n\\nE.g. t.rich('rich', {b: (chunks) => `<b>${chunks}</b>`})\"\n : undefined\n );\n\n onError(error);\n return getMessageFallback({error, key, namespace});\n }\n\n return result;\n };\n\n base.raw = translator.raw;\n\n return base;\n}\n"],"names":["_ref","_ref$getMessageFallba","getMessageFallback","defaultGetMessageFallback","messages","namespace","_ref$onError","onError","defaultOnError","rest","_objectWithoutPropertiesLoose","_excluded","namespacePrefix","resolveNamespace","translator","createBaseTranslator","_extends","originalRich","rich","base","apply","arguments","key","values","formats","result","error","IntlError","IntlErrorCode","FORMATTING_ERROR","undefined","raw","createTranslatorImpl"],"mappings":"4lBAoBwB,SAAgBA,GAcvC,IAAAC,EAAAD,EARCE,mBAAAA,OAAqBC,IAAHF,EAAGE,EAAyBA,0BAAAF,EAC9CG,EAAQJ,EAARI,SACAC,EAASL,EAATK,UAASC,EAAAN,EACTO,QAAAA,OAAUC,IAAHF,EAAGE,EAAcA,eAAAF,EACrBG,EAAIC,EAAAA,8BAAAV,EAAAW,GAmEP,OC9EY,SAA8BX,EAW1CY,GAAuB,IANrBV,EAAkBF,EAAlBE,mBACAE,EAAQJ,EAARI,SACAC,EAASL,EAATK,UACAE,EAAOP,EAAPO,QACGE,EAAIC,EAAAA,8BAAAV,EAAAW,GAMTP,EAAWA,ED2ET,KC1EFC,EAAYQ,EAAgBA,iBAACR,ED0E3B,KCxEF,IAAMS,EAAaC,EAAoBA,qBAAAC,cAClCP,EAAI,CACPF,QAAAA,EACAL,mBAAAA,EACAE,SAAAA,EACAC,UAAAA,KAGIY,EAAeH,EAAWI,KAEhC,SAASC,IACP,OAAOL,EAAUM,WAAA,EAAAC,UACnB,CA+BA,OA5BAF,EAAKD,KAAO,SACVI,EAEAC,EACAC,GAIA,IAAMC,EAASR,EAAaK,EAAKC,EAAiCC,GAGlE,GAAsB,iBAAXC,EAAqB,CAC9B,IAAMC,EAAQ,IAAIC,EAASA,UACzBC,EAAaA,cAACC,sBAGVC,GAIN,OADAvB,EAAQmB,GACDxB,EAAmB,CAACwB,MAAAA,EAAOJ,IAAAA,EAAKjB,UAAAA,GACxC,CAED,OAAOoB,GAGTN,EAAKY,IAAMjB,EAAWiB,IAEfZ,CACT,CDgBSa,CAAoBhB,EAAAA,SAAA,CAAA,EAKpBP,EAAI,CACPF,QAAAA,EACAL,mBAAAA,EACAE,SAAU,CAAC,IAAKA,GAEhBC,UAAWA,EAAiBA,KAAAA,EAAc,MAIhD"}
|
package/dist/core.esm.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export { default as IntlError, IntlErrorCode } from './core/IntlError.esm.js';
|
|
2
|
-
export { default as createTranslator } from './core/createTranslator.esm.js';
|
|
3
|
-
export { default as createBaseTranslator } from './core/createBaseTranslator.esm.js';
|
|
4
|
-
export { default as createFormatter } from './core/createFormatter.esm.js';
|
|
5
|
-
export { default as initializeConfig } from './core/initializeConfig.esm.js';
|
|
6
|
-
export { default as createIntl } from './core/createIntl.esm.js';
|
|
7
|
-
//# sourceMappingURL=core.esm.js.map
|
package/dist/core.esm.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"core.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;"}
|