use-intl 2.7.2-alpha.1 → 2.7.2
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/dist/use-intl.esm.js +7 -7
- package/dist/use-intl.esm10.js +26 -9
- package/dist/use-intl.esm10.js.map +1 -1
- package/dist/use-intl.esm11.js +12 -3
- package/dist/use-intl.esm11.js.map +1 -1
- package/dist/use-intl.esm12.js +2 -2
- package/dist/use-intl.esm2.js +39 -146
- package/dist/use-intl.esm2.js.map +1 -1
- package/dist/use-intl.esm3.js +26 -40
- package/dist/use-intl.esm3.js.map +1 -1
- package/dist/use-intl.esm4.js +152 -31
- package/dist/use-intl.esm4.js.map +1 -1
- package/dist/use-intl.esm5.js +4 -46
- package/dist/use-intl.esm5.js.map +1 -1
- package/dist/use-intl.esm6.js +49 -41
- package/dist/use-intl.esm6.js.map +1 -1
- package/dist/use-intl.esm7.js +4 -4
- package/dist/use-intl.esm7.js.map +1 -1
- package/dist/use-intl.esm8.js +39 -5
- package/dist/use-intl.esm8.js.map +1 -1
- package/dist/use-intl.esm9.js +3 -29
- package/dist/use-intl.esm9.js.map +1 -1
- package/package.json +2 -2
package/dist/use-intl.esm.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export { default as IntlProvider } from './use-intl.
|
|
2
|
-
export { default as useTranslations } from './use-intl.
|
|
3
|
-
export { default as useIntl } from './use-intl.
|
|
4
|
-
export { default as useLocale } from './use-intl.
|
|
5
|
-
export { default as useNow } from './use-intl.
|
|
6
|
-
export { default as useTimeZone } from './use-intl.
|
|
7
|
-
export { default as IntlError, IntlErrorCode } from './use-intl.
|
|
1
|
+
export { default as IntlProvider } from './use-intl.esm2.js';
|
|
2
|
+
export { default as useTranslations } from './use-intl.esm3.js';
|
|
3
|
+
export { default as useIntl } from './use-intl.esm4.js';
|
|
4
|
+
export { default as useLocale } from './use-intl.esm5.js';
|
|
5
|
+
export { default as useNow } from './use-intl.esm6.js';
|
|
6
|
+
export { default as useTimeZone } from './use-intl.esm7.js';
|
|
7
|
+
export { default as IntlError, IntlErrorCode } from './use-intl.esm8.js';
|
|
8
8
|
//# sourceMappingURL=use-intl.esm.js.map
|
package/dist/use-intl.esm10.js
CHANGED
|
@@ -1,15 +1,32 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import IntlContext from './use-intl.esm11.js';
|
|
1
|
+
import IntlError, { IntlErrorCode } from './use-intl.esm8.js';
|
|
3
2
|
|
|
4
|
-
function
|
|
5
|
-
|
|
3
|
+
function validateMessagesSegment(messages, invalidKeyLabels, parentPath) {
|
|
4
|
+
Object.entries(messages).forEach(function (_ref) {
|
|
5
|
+
var key = _ref[0],
|
|
6
|
+
messageOrMessages = _ref[1];
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
+
});
|
|
20
|
+
}
|
|
10
21
|
|
|
11
|
-
|
|
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.esm10.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-intl.esm10.js","sources":["../src/
|
|
1
|
+
{"version":3,"file":"use-intl.esm10.js","sources":["../src/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,EAA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AP,CAAA;AAQD,GAAA;AACF;;;;"}
|
package/dist/use-intl.esm11.js
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useContext } from 'react';
|
|
2
|
+
import IntlContext from './use-intl.esm9.js';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
function useIntlContext() {
|
|
5
|
+
var context = useContext(IntlContext);
|
|
4
6
|
|
|
5
|
-
|
|
7
|
+
if (!context) {
|
|
8
|
+
throw new Error(process.env.NODE_ENV !== "production" ? 'No intl context found. Have you configured the provider?' : undefined);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return context;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { useIntlContext as default };
|
|
6
15
|
//# sourceMappingURL=use-intl.esm11.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-intl.esm11.js","sources":["../src/
|
|
1
|
+
{"version":3,"file":"use-intl.esm11.js","sources":["../src/useIntlContext.tsx"],"sourcesContent":["import {useContext} from 'react';\nimport IntlContext from './IntlContext';\n\nexport default function useIntlContext() {\n const context = useContext(IntlContext);\n\n if (!context) {\n throw new Error(\n __DEV__\n ? 'No intl context found. Have you configured the provider?'\n : undefined\n );\n }\n\n return context;\n}\n"],"names":["useIntlContext","context","useContext","IntlContext","Error","undefined"],"mappings":";;;AAGc,SAAUA,cAAV,GAAwB;AACpC,EAAA,IAAMC,OAAO,GAAGC,UAAU,CAACC,WAAD,CAA1B,CAAA;;AAEA,EAAI,IAAA,CAACF,OAAL,EAAc;AACZ,IAAA,MAAM,IAAIG,KAAJ,CACJ,wCACI,0DADJ,GAEIC,SAHA,CAAN,CAAA;AAKD,GAAA;;AAED,EAAA,OAAOJ,OAAP,CAAA;AACD;;;;"}
|
package/dist/use-intl.esm12.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { extends as _extends } from './_virtual/use-intl.esm.js';
|
|
2
2
|
import { IntlMessageFormat } from 'intl-messageformat';
|
|
3
3
|
import { useRef, useMemo, isValidElement, cloneElement } from 'react';
|
|
4
|
-
import IntlError, { IntlErrorCode } from './use-intl.
|
|
4
|
+
import IntlError, { IntlErrorCode } from './use-intl.esm8.js';
|
|
5
5
|
import convertFormatsToIntlMessageFormat from './use-intl.esm13.js';
|
|
6
|
-
import useIntlContext from './use-intl.
|
|
6
|
+
import useIntlContext from './use-intl.esm11.js';
|
|
7
7
|
|
|
8
8
|
function resolvePath(messages, idPath, namespace) {
|
|
9
9
|
if (!messages) {
|
package/dist/use-intl.esm2.js
CHANGED
|
@@ -1,155 +1,48 @@
|
|
|
1
|
-
import { extends as _extends } from './_virtual/use-intl.esm.js';
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
var absValue = Math.abs(seconds);
|
|
15
|
-
var value, unit; // We have to round the resulting values, as `Intl.RelativeTimeFormat`
|
|
16
|
-
// will include fractions like '2.1 hours ago'.
|
|
17
|
-
|
|
18
|
-
if (absValue < MINUTE) {
|
|
19
|
-
unit = 'second';
|
|
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
|
-
};
|
|
1
|
+
import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose, extends as _extends } from './_virtual/use-intl.esm.js';
|
|
2
|
+
import React, { useEffect } from 'react';
|
|
3
|
+
import IntlContext from './use-intl.esm9.js';
|
|
4
|
+
import validateMessages from './use-intl.esm10.js';
|
|
5
|
+
|
|
6
|
+
var _excluded = ["children", "onError", "getMessageFallback", "messages"];
|
|
7
|
+
|
|
8
|
+
function defaultGetMessageFallback(_ref) {
|
|
9
|
+
var key = _ref.key,
|
|
10
|
+
namespace = _ref.namespace;
|
|
11
|
+
return [namespace, key].filter(function (part) {
|
|
12
|
+
return part != null;
|
|
13
|
+
}).join('.');
|
|
45
14
|
}
|
|
46
15
|
|
|
47
|
-
function
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
locale = _useIntlContext.locale,
|
|
51
|
-
globalNow = _useIntlContext.now,
|
|
52
|
-
onError = _useIntlContext.onError,
|
|
53
|
-
timeZone = _useIntlContext.timeZone;
|
|
54
|
-
|
|
55
|
-
function resolveFormatOrOptions(typeFormats, formatOrOptions) {
|
|
56
|
-
var options;
|
|
57
|
-
|
|
58
|
-
if (typeof formatOrOptions === 'string') {
|
|
59
|
-
var formatName = formatOrOptions;
|
|
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;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return options;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function getFormattedValue(value, formatOrOptions, typeFormats, formatter) {
|
|
75
|
-
var options;
|
|
76
|
-
|
|
77
|
-
try {
|
|
78
|
-
options = resolveFormatOrOptions(typeFormats, formatOrOptions);
|
|
79
|
-
} catch (error) {
|
|
80
|
-
return String(value);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
try {
|
|
84
|
-
return formatter(options);
|
|
85
|
-
} catch (error) {
|
|
86
|
-
onError(new IntlError(IntlErrorCode.FORMATTING_ERROR, error.message));
|
|
87
|
-
return String(value);
|
|
88
|
-
}
|
|
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
|
-
|
|
100
|
-
if (timeZone && !((_options = options) != null && _options.timeZone)) {
|
|
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
|
-
}
|
|
16
|
+
function defaultOnError(error) {
|
|
17
|
+
console.error(error);
|
|
18
|
+
}
|
|
115
19
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
20
|
+
function IntlProvider(_ref2) {
|
|
21
|
+
var children = _ref2.children,
|
|
22
|
+
_ref2$onError = _ref2.onError,
|
|
23
|
+
onError = _ref2$onError === void 0 ? defaultOnError : _ref2$onError,
|
|
24
|
+
_ref2$getMessageFallb = _ref2.getMessageFallback,
|
|
25
|
+
getMessageFallback = _ref2$getMessageFallb === void 0 ? defaultGetMessageFallback : _ref2$getMessageFallb,
|
|
26
|
+
messages = _ref2.messages,
|
|
27
|
+
contextValues = _objectWithoutPropertiesLoose(_ref2, _excluded);
|
|
28
|
+
|
|
29
|
+
if (process.env.NODE_ENV !== "production") {
|
|
30
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
31
|
+
useEffect(function () {
|
|
32
|
+
if (messages) {
|
|
33
|
+
validateMessages(messages, onError);
|
|
128
34
|
}
|
|
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
|
+
}, [messages, onError]);
|
|
145
36
|
}
|
|
146
37
|
|
|
147
|
-
return {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
38
|
+
return React.createElement(IntlContext.Provider, {
|
|
39
|
+
value: _extends({}, contextValues, {
|
|
40
|
+
messages: messages,
|
|
41
|
+
onError: onError,
|
|
42
|
+
getMessageFallback: getMessageFallback
|
|
43
|
+
})
|
|
44
|
+
}, children);
|
|
152
45
|
}
|
|
153
46
|
|
|
154
|
-
export {
|
|
47
|
+
export { IntlProvider as default };
|
|
155
48
|
//# sourceMappingURL=use-intl.esm2.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-intl.esm2.js","sources":["../src/useIntl.tsx"],"sourcesContent":["import DateTimeFormatOptions from './DateTimeFormatOptions';\nimport IntlError, {IntlErrorCode} from './IntlError';\nimport NumberFormatOptions from './NumberFormatOptions';\nimport useIntlContext from './useIntlContext';\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\nexport default function useIntl() {\n const {formats, locale, now: globalNow, onError, timeZone} = useIntlContext();\n\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 __DEV__\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 __DEV__\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","useIntl","useIntlContext","formats","locale","globalNow","now","onError","timeZone","resolveFormatOrOptions","typeFormats","formatOrOptions","options","formatName","error","IntlError","IntlErrorCode","MISSING_FORMAT","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":";;;;AAKA,IAAMA,MAAM,GAAG,EAAf,CAAA;AACA,IAAMC,IAAI,GAAGD,MAAM,GAAG,EAAtB,CAAA;AACA,IAAME,GAAG,GAAGD,IAAI,GAAG,EAAnB,CAAA;AACA,IAAME,IAAI,GAAGD,GAAG,GAAG,CAAnB,CAAA;AACA,IAAME,KAAK,GAAGF,GAAG,IAAI,MAAM,EAAV,CAAjB;;AACA,IAAMG,IAAI,GAAGH,GAAG,GAAG,GAAnB,CAAA;;AAEA,SAASI,2BAAT,CAAqCC,OAArC,EAAoD;AAClD,EAAA,IAAMC,QAAQ,GAAGC,IAAI,CAACC,GAAL,CAASH,OAAT,CAAjB,CAAA;AACA,EAAA,IAAII,KAAJ,EAAWC,IAAX,CAFkD;AAKlD;;AAEA,EAAIJ,IAAAA,QAAQ,GAAGR,MAAf,EAAuB;AACrBY,IAAAA,IAAI,GAAG,QAAP,CAAA;AACAD,IAAAA,KAAK,GAAGF,IAAI,CAACI,KAAL,CAAWN,OAAX,CAAR,CAAA;AACD,GAHD,MAGO,IAAIC,QAAQ,GAA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AAD,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.esm2.js","sources":["../src/IntlProvider.tsx"],"sourcesContent":["import React, {ReactNode, useEffect} from 'react';\nimport AbstractIntlMessages from './AbstractIntlMessages';\nimport Formats from './Formats';\nimport IntlContext from './IntlContext';\nimport IntlError from './IntlError';\nimport {RichTranslationValues} from './TranslationValues';\nimport validateMessages from './validateMessages';\n\ntype Props = {\n /** All messages that will be available in your components. */\n messages?: AbstractIntlMessages;\n /** A valid Unicode locale tag (e.g. \"en\" or \"en-GB\"). */\n locale: string;\n /** Global formats can be provided to achieve consistent\n * formatting across components. */\n formats?: Partial<Formats>;\n /** A time zone as defined in [the tz database](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) which will be applied when formatting dates and times. If this is absent, the user time zone will be used. You can override this by supplying an explicit time zone to `formatDateTime`. */\n timeZone?: string;\n /** This callback will be invoked when an error is encountered during\n * resolving a message or formatting it. This defaults to `console.error` to\n * keep your app running. You can customize the handling by taking\n * `error.code` into account. */\n onError?(error: IntlError): void;\n /** Will be called when a message couldn't be resolved or formatting it led to\n * an error. This defaults to `${namespace}.${key}` You can use this to\n * customize what will be rendered in this case. */\n getMessageFallback?(info: {\n namespace?: string;\n key: string;\n error: IntlError;\n }): string;\n /** All components that use the provided hooks should be within this tree. */\n children: ReactNode;\n /**\n * Providing this value will have two effects:\n * 1. It will be used as the default for the `now` argument of\n * `useIntl().formatRelativeTime` if no explicit value is provided.\n * 2. It will be returned as a static value from the `useNow` hook. Note\n * however that when `updateInterval` is configured on the `useNow` hook,\n * the global `now` value will only be used for the initial render, but\n * afterwards the current date will be returned continuously.\n */\n now?: Date;\n /** Global default values for translation values and rich text elements.\n * Can be used for consistent usage or styling of rich text elements.\n * Defaults will be overidden by locally provided values. */\n defaultTranslationValues?: RichTranslationValues;\n};\n\nfunction defaultGetMessageFallback({\n key,\n namespace\n}: {\n key: string;\n namespace?: string;\n}) {\n return [namespace, key].filter((part) => part != null).join('.');\n}\n\nfunction defaultOnError(error: IntlError) {\n console.error(error);\n}\n\nexport default function IntlProvider({\n children,\n onError = defaultOnError,\n getMessageFallback = defaultGetMessageFallback,\n messages,\n ...contextValues\n}: Props) {\n if (__DEV__) {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useEffect(() => {\n if (messages) {\n validateMessages(messages, onError);\n }\n }, [messages, onError]);\n }\n\n return (\n <IntlContext.Provider\n value={{...contextValues, messages, onError, getMessageFallback}}\n >\n {children}\n </IntlContext.Provider>\n );\n}\n"],"names":["defaultGetMessageFallback","key","namespace","filter","part","join","defaultOnError","error","console","IntlProvider","children","onError","getMessageFallback","messages","contextValues","useEffect","validateMessages","React","IntlContext","Provider","value"],"mappings":";;;;;;;AAiDA,SAASA,yBAAT,CAMC,IAAA,EAAA;AAAA,EALCC,IAAAA,GAKD,QALCA,GAKD;AAAA,MAJCC,SAID,QAJCA,SAID,CAAA;AACC,EAAO,OAAA,CAACA,SAAD,EAAYD,GAAZ,EAAiBE,MAAjB,CAAwB,UAACC,IAAD,EAAA;AAAA,IAAUA,OAAAA,IAAI,IAAI,IAAlB,CAAA;AAAA,GAAxB,CAAgDC,CAAAA,IAAhD,CAAqD,GAArD,CAAP,CAAA;AACD,CAAA;;AAED,SAASC,cAAT,CAAwBC,KAAxB,EAAwC;AACtCC,EAAAA,OAAO,CAACD,KAAR,CAAcA,KAAd,CAAA,CAAA;AACD,CAAA;;AAEuB,SAAAE,YAAA,CAMhB,KAAA,EAAA;AAAA,EALNC,IAAAA,QAKM,SALNA,QAKM;AAAA,MAAA,aAAA,GAAA,KAAA,CAJNC,OAIM;AAAA,MAJNA,OAIM,8BAJIL,cAIJ,GAAA,aAAA;AAAA,MAAA,qBAAA,GAAA,KAAA,CAHNM,kBAGM;AAAA,MAHNA,kBAGM,sCAHeZ,yBAGf,GAAA,qBAAA;AAAA,MAFNa,QAEM,SAFNA,QAEM;AAAA,MADHC,aACG,GAAA,6BAAA,CAAA,KAAA,EAAA,SAAA,CAAA,CAAA;;AACN,EAAa,IAAA,OAAA,CAAA,GAAA,CAAA,QAAA,KAAA,YAAA,EAAA;AACX;AACAC,IAAAA,SAAS,CAAC,YAAK;AACb,MAAA,IAAIF,QAAJ,EAAc;AACZG,QAAAA,gBAAgB,CAACH,QAAD,EAAWF,OAAX,CAAhB,CAAA;AACD,OAAA;AACF,KAJQ,EAIN,CAACE,QAAD,EAAWF,OAAX,CAJM,CAAT,CAAA;AAKD,GAAA;;AAED,EAAA,OACEM,mBAAA,CAACC,WAAW,CAACC,QAAb,EACE;AAAAC,IAAAA,KAAK,eAAMN,aAAN,EAAA;AAAqBD,MAAAA,QAAQ,EAARA,QAArB;AAA+BF,MAAAA,OAAO,EAAPA,OAA/B;AAAwCC,MAAAA,kBAAkB,EAAlBA,kBAAAA;AAAxC,KAAA,CAAA;AAAL,GADF,EAGGF,QAHH,CADF,CAAA;AAOD;;;;"}
|
package/dist/use-intl.esm3.js
CHANGED
|
@@ -1,48 +1,34 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import validateMessages from './use-intl.esm9.js';
|
|
1
|
+
import IntlError, { IntlErrorCode } from './use-intl.esm8.js';
|
|
2
|
+
import useIntlContext from './use-intl.esm11.js';
|
|
3
|
+
import useTranslationsImpl from './use-intl.esm12.js';
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Translates messages from the given namespace by using the ICU syntax.
|
|
7
|
+
* See https://formatjs.io/docs/core-concepts/icu-syntax.
|
|
8
|
+
*
|
|
9
|
+
* If no namespace is provided, all available messages are returned.
|
|
10
|
+
* The namespace can also indicate nesting by using a dot
|
|
11
|
+
* (e.g. `namespace.Component`).
|
|
12
|
+
*/
|
|
7
13
|
|
|
8
|
-
function
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
return [namespace, key].filter(function (part) {
|
|
12
|
-
return part != null;
|
|
13
|
-
}).join('.');
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function defaultOnError(error) {
|
|
17
|
-
console.error(error);
|
|
18
|
-
}
|
|
14
|
+
function useTranslations(namespace) {
|
|
15
|
+
var context = useIntlContext();
|
|
16
|
+
var messages = context.messages;
|
|
19
17
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
contextValues = _objectWithoutPropertiesLoose(_ref2, _excluded);
|
|
18
|
+
if (!messages) {
|
|
19
|
+
var intlError = new IntlError(IntlErrorCode.MISSING_MESSAGE, process.env.NODE_ENV !== "production" ? "No messages were configured on the provider." : undefined);
|
|
20
|
+
context.onError(intlError);
|
|
21
|
+
throw intlError;
|
|
22
|
+
} // We have to wrap the actual hook so the type inference for the optional
|
|
23
|
+
// namespace works correctly. See https://stackoverflow.com/a/71529575/343045
|
|
24
|
+
// The prefix ("!"") is arbitrary, but we have to use some.
|
|
28
25
|
|
|
29
|
-
if (process.env.NODE_ENV !== "production") {
|
|
30
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
31
|
-
useEffect(function () {
|
|
32
|
-
if (messages) {
|
|
33
|
-
validateMessages(messages, onError);
|
|
34
|
-
}
|
|
35
|
-
}, [messages, onError]);
|
|
36
|
-
}
|
|
37
26
|
|
|
38
|
-
return
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
getMessageFallback: getMessageFallback
|
|
43
|
-
})
|
|
44
|
-
}, children);
|
|
27
|
+
return useTranslationsImpl({
|
|
28
|
+
'!': messages
|
|
29
|
+
}, // @ts-ignore
|
|
30
|
+
namespace ? "!." + namespace : '!', '!');
|
|
45
31
|
}
|
|
46
32
|
|
|
47
|
-
export {
|
|
33
|
+
export { useTranslations as default };
|
|
48
34
|
//# sourceMappingURL=use-intl.esm3.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-intl.esm3.js","sources":["../src/
|
|
1
|
+
{"version":3,"file":"use-intl.esm3.js","sources":["../src/useTranslations.tsx"],"sourcesContent":["import {ReactElement, ReactNodeArray} from 'react';\nimport Formats from './Formats';\nimport IntlError, {IntlErrorCode} from './IntlError';\nimport TranslationValues, {RichTranslationValues} from './TranslationValues';\nimport useIntlContext from './useIntlContext';\nimport useTranslationsImpl from './useTranslationsImpl';\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 useTranslations<\n NestedKey extends NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>>\n>(\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 NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> extends NestedKey\n ? '!'\n : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n NamespaceKeys<\n IntlMessages,\n NestedKeyOf<IntlMessages>\n > extends NestedKey\n ? '!'\n : `!.${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 NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> extends NestedKey\n ? '!'\n : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n NamespaceKeys<\n IntlMessages,\n NestedKeyOf<IntlMessages>\n > extends NestedKey\n ? '!'\n : `!.${NestedKey}`\n >\n >\n >\n >(\n key: TargetKey,\n values?: RichTranslationValues,\n formats?: Partial<Formats>\n ): string | ReactElement | ReactNodeArray;\n\n // `raw`\n raw<\n TargetKey extends MessageKeys<\n NestedValueOf<\n {'!': IntlMessages},\n NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> extends NestedKey\n ? '!'\n : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n NamespaceKeys<\n IntlMessages,\n NestedKeyOf<IntlMessages>\n > extends NestedKey\n ? '!'\n : `!.${NestedKey}`\n >\n >\n >\n >(\n key: TargetKey\n ): any;\n} {\n const context = useIntlContext();\n\n const messages = context.messages as IntlMessages;\n if (!messages) {\n const intlError = new IntlError(\n IntlErrorCode.MISSING_MESSAGE,\n __DEV__ ? `No messages were configured on the provider.` : undefined\n );\n context.onError(intlError);\n throw intlError;\n }\n\n // We have to wrap the actual hook so the type inference for the optional\n // namespace works correctly. See https://stackoverflow.com/a/71529575/343045\n // The prefix (\"!\"\") is arbitrary, but we have to use some.\n return useTranslationsImpl<\n {'!': IntlMessages},\n NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> extends NestedKey\n ? '!'\n : `!.${NestedKey}`\n >(\n {'!': messages},\n // @ts-ignore\n namespace ? `!.${namespace}` : '!',\n '!'\n );\n}\n"],"names":["useTranslations","namespace","context","useIntlContext","messages","intlError","IntlError","IntlErrorCode","MISSING_MESSAGE","undefined","onError","useTranslationsImpl"],"mappings":";;;;AAWA;;;;;;;AAOG;;AACqB,SAAAA,eAAA,CAGtBC,SAHsB,EAGD;AAkFrB,EAAMC,IAAAA,OAAO,GAAGC,cAAc,EAA9B,CAAA;AAEA,EAAA,IAAMC,QAAQ,GAAGF,OAAO,CAACE,QAAzB,CAAA;;AACA,EAAI,IAAA,CAACA,QAAL,EAAe;AACb,IAAMC,IAAAA,SAAS,GAAG,IAAIC,SAAJ,CAChBC,aAAa,CAACC,eADE,EAEhB,OAA2DC,CAAAA,GAAAA,CAAAA,QAAAA,KAAAA,YAAAA,GAAAA,8CAAAA,GAAAA,SAF3C,CAAlB,CAAA;AAIAP,IAAAA,OAAO,CAACQ,OAAR,CAAgBL,SAAhB,CAAA,CAAA;AACA,IAAA,MAAMA,SAAN,CAAA;AACD,GA5FoB;AA+FrB;AACA;;;AACA,EAAA,OAAOM,mBAAmB,CAMxB;AAAC,IAAKP,GAAAA,EAAAA,QAAAA;AAAN,GANwB;AAQxBH,EAAAA,SAAS,GAAQA,IAAAA,GAAAA,SAAR,GAAsB,GARP,EASxB,GATwB,CAA1B,CAAA;AAWD;;;;"}
|
package/dist/use-intl.esm4.js
CHANGED
|
@@ -1,34 +1,155 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
*
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
var
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
'
|
|
29
|
-
|
|
30
|
-
|
|
1
|
+
import { extends as _extends } from './_virtual/use-intl.esm.js';
|
|
2
|
+
import IntlError, { IntlErrorCode } from './use-intl.esm8.js';
|
|
3
|
+
import useIntlContext from './use-intl.esm11.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
|
+
|
|
11
|
+
var YEAR = DAY * 365;
|
|
12
|
+
|
|
13
|
+
function getRelativeTimeFormatConfig(seconds) {
|
|
14
|
+
var absValue = Math.abs(seconds);
|
|
15
|
+
var value, unit; // We have to round the resulting values, as `Intl.RelativeTimeFormat`
|
|
16
|
+
// will include fractions like '2.1 hours ago'.
|
|
17
|
+
|
|
18
|
+
if (absValue < MINUTE) {
|
|
19
|
+
unit = 'second';
|
|
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 useIntl() {
|
|
48
|
+
var _useIntlContext = useIntlContext(),
|
|
49
|
+
formats = _useIntlContext.formats,
|
|
50
|
+
locale = _useIntlContext.locale,
|
|
51
|
+
globalNow = _useIntlContext.now,
|
|
52
|
+
onError = _useIntlContext.onError,
|
|
53
|
+
timeZone = _useIntlContext.timeZone;
|
|
54
|
+
|
|
55
|
+
function resolveFormatOrOptions(typeFormats, formatOrOptions) {
|
|
56
|
+
var options;
|
|
57
|
+
|
|
58
|
+
if (typeof formatOrOptions === 'string') {
|
|
59
|
+
var formatName = formatOrOptions;
|
|
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;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return options;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function getFormattedValue(value, formatOrOptions, typeFormats, formatter) {
|
|
75
|
+
var options;
|
|
76
|
+
|
|
77
|
+
try {
|
|
78
|
+
options = resolveFormatOrOptions(typeFormats, formatOrOptions);
|
|
79
|
+
} catch (error) {
|
|
80
|
+
return String(value);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
try {
|
|
84
|
+
return formatter(options);
|
|
85
|
+
} catch (error) {
|
|
86
|
+
onError(new IntlError(IntlErrorCode.FORMATTING_ERROR, error.message));
|
|
87
|
+
return String(value);
|
|
88
|
+
}
|
|
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
|
+
|
|
100
|
+
if (timeZone && !((_options = options) != null && _options.timeZone)) {
|
|
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
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return {
|
|
148
|
+
formatDateTime: formatDateTime,
|
|
149
|
+
formatNumber: formatNumber,
|
|
150
|
+
formatRelativeTime: formatRelativeTime
|
|
151
|
+
};
|
|
31
152
|
}
|
|
32
153
|
|
|
33
|
-
export {
|
|
154
|
+
export { useIntl as default };
|
|
34
155
|
//# sourceMappingURL=use-intl.esm4.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-intl.esm4.js","sources":["../src/useTranslations.tsx"],"sourcesContent":["import {ReactElement, ReactNodeArray} from 'react';\nimport Formats from './Formats';\nimport IntlError, {IntlErrorCode} from './IntlError';\nimport TranslationValues, {RichTranslationValues} from './TranslationValues';\nimport useIntlContext from './useIntlContext';\nimport useTranslationsImpl from './useTranslationsImpl';\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 useTranslations<\n NestedKey extends NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>>\n>(\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 NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> extends NestedKey\n ? '!'\n : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n NamespaceKeys<\n IntlMessages,\n NestedKeyOf<IntlMessages>\n > extends NestedKey\n ? '!'\n : `!.${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 NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> extends NestedKey\n ? '!'\n : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n NamespaceKeys<\n IntlMessages,\n NestedKeyOf<IntlMessages>\n > extends NestedKey\n ? '!'\n : `!.${NestedKey}`\n >\n >\n >\n >(\n key: TargetKey,\n values?: RichTranslationValues,\n formats?: Partial<Formats>\n ): string | ReactElement | ReactNodeArray;\n\n // `raw`\n raw<\n TargetKey extends MessageKeys<\n NestedValueOf<\n {'!': IntlMessages},\n NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> extends NestedKey\n ? '!'\n : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n NamespaceKeys<\n IntlMessages,\n NestedKeyOf<IntlMessages>\n > extends NestedKey\n ? '!'\n : `!.${NestedKey}`\n >\n >\n >\n >(\n key: TargetKey\n ): any;\n} {\n const context = useIntlContext();\n\n const messages = context.messages as IntlMessages;\n if (!messages) {\n const intlError = new IntlError(\n IntlErrorCode.MISSING_MESSAGE,\n __DEV__ ? `No messages were configured on the provider.` : undefined\n );\n context.onError(intlError);\n throw intlError;\n }\n\n // We have to wrap the actual hook so the type inference for the optional\n // namespace works correctly. See https://stackoverflow.com/a/71529575/343045\n // The prefix (\"!\"\") is arbitrary, but we have to use some.\n return useTranslationsImpl<\n {'!': IntlMessages},\n NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> extends NestedKey\n ? '!'\n : `!.${NestedKey}`\n >(\n {'!': messages},\n // @ts-ignore\n namespace ? `!.${namespace}` : '!',\n '!'\n );\n}\n"],"names":["useTranslations","namespace","context","useIntlContext","messages","intlError","IntlError","IntlErrorCode","MISSING_MESSAGE","undefined","onError","useTranslationsImpl"],"mappings":";;;;AAWA;;;;;;;AAOG;;AACqB,SAAAA,eAAA,CAGtBC,SAHsB,EAGD;AAkFrB,EAAMC,IAAAA,OAAO,GAAGC,cAAc,EAA9B,CAAA;AAEA,EAAA,IAAMC,QAAQ,GAAGF,OAAO,CAACE,QAAzB,CAAA;;AACA,EAAI,IAAA,CAACA,QAAL,EAAe;AACb,IAAMC,IAAAA,SAAS,GAAG,IAAIC,SAAJ,CAChBC,aAAa,CAACC,eADE,EAEhB,OAA2DC,CAAAA,GAAAA,CAAAA,QAAAA,KAAAA,YAAAA,GAAAA,8CAAAA,GAAAA,SAF3C,CAAlB,CAAA;AAIAP,IAAAA,OAAO,CAACQ,OAAR,CAAgBL,SAAhB,CAAA,CAAA;AACA,IAAA,MAAMA,SAAN,CAAA;AACD,GA5FoB;AA+FrB;AACA;;;AACA,EAAA,OAAOM,mBAAmB,CAMxB;AAAC,IAAKP,GAAAA,EAAAA,QAAAA;AAAN,GANwB;AAQxBH,EAAAA,SAAS,GAAQA,IAAAA,GAAAA,SAAR,GAAsB,GARP,EASxB,GATwB,CAA1B,CAAA;AAWD;;;;"}
|
|
1
|
+
{"version":3,"file":"use-intl.esm4.js","sources":["../src/useIntl.tsx"],"sourcesContent":["import DateTimeFormatOptions from './DateTimeFormatOptions';\nimport IntlError, {IntlErrorCode} from './IntlError';\nimport NumberFormatOptions from './NumberFormatOptions';\nimport useIntlContext from './useIntlContext';\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\nexport default function useIntl() {\n const {formats, locale, now: globalNow, onError, timeZone} = useIntlContext();\n\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 __DEV__\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 __DEV__\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","useIntl","useIntlContext","formats","locale","globalNow","now","onError","timeZone","resolveFormatOrOptions","typeFormats","formatOrOptions","options","formatName","error","IntlError","IntlErrorCode","MISSING_FORMAT","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":";;;;AAKA,IAAMA,MAAM,GAAG,EAAf,CAAA;AACA,IAAMC,IAAI,GAAGD,MAAM,GAAG,EAAtB,CAAA;AACA,IAAME,GAAG,GAAGD,IAAI,GAAG,EAAnB,CAAA;AACA,IAAME,IAAI,GAAGD,GAAG,GAAG,CAAnB,CAAA;AACA,IAAME,KAAK,GAAGF,GAAG,IAAI,MAAM,EAAV,CAAjB;;AACA,IAAMG,IAAI,GAAGH,GAAG,GAAG,GAAnB,CAAA;;AAEA,SAASI,2BAAT,CAAqCC,OAArC,EAAoD;AAClD,EAAA,IAAMC,QAAQ,GAAGC,IAAI,CAACC,GAAL,CAASH,OAAT,CAAjB,CAAA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,OAApC,EAEJZ,MAFI,CAEG9B,KAFH,EAEUC,IAFV,CAAP,CAAA;AAGD,KAtBD,CAsBE,OAAOe,KAAP,EAAc;AACdP,MAAAA,OAAO,CACL,IAAIQ,SAAJ,CAAcC,aAAa,CAACM,gBAA5B,EAA+CR,KAAe,CAACS,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;;;;"}
|
package/dist/use-intl.esm5.js
CHANGED
|
@@ -1,50 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import useIntlContext from './use-intl.esm10.js';
|
|
1
|
+
import useIntlContext from './use-intl.esm11.js';
|
|
3
2
|
|
|
4
|
-
function
|
|
5
|
-
return
|
|
3
|
+
function useLocale() {
|
|
4
|
+
return useIntlContext().locale;
|
|
6
5
|
}
|
|
7
|
-
/**
|
|
8
|
-
* Reading the current date via `new Date()` in components should be avoided, as
|
|
9
|
-
* it causes components to be impure and can lead to flaky tests. Instead, this
|
|
10
|
-
* hook can be used.
|
|
11
|
-
*
|
|
12
|
-
* By default, it returns the time when the component mounts. If `updateInterval`
|
|
13
|
-
* is specified, the value will be updated based on the interval.
|
|
14
|
-
*
|
|
15
|
-
* You can however also return a static value from this hook, if you
|
|
16
|
-
* configure the `now` parameter on the context provider. Note however,
|
|
17
|
-
* that if `updateInterval` is configured in this case, the component
|
|
18
|
-
* will initialize with the global value, but will afterwards update
|
|
19
|
-
* continuously based on the interval.
|
|
20
|
-
*
|
|
21
|
-
* For unit tests, this can be mocked to a constant value. For end-to-end
|
|
22
|
-
* testing, an environment parameter can be passed to the `now` parameter
|
|
23
|
-
* of the provider to mock this to a static value.
|
|
24
|
-
*/
|
|
25
6
|
|
|
26
|
-
|
|
27
|
-
function useNow(options) {
|
|
28
|
-
var updateInterval = options == null ? void 0 : options.updateInterval;
|
|
29
|
-
|
|
30
|
-
var _useIntlContext = useIntlContext(),
|
|
31
|
-
globalNow = _useIntlContext.now;
|
|
32
|
-
|
|
33
|
-
var _useState = useState(globalNow || getNow()),
|
|
34
|
-
now = _useState[0],
|
|
35
|
-
setNow = _useState[1];
|
|
36
|
-
|
|
37
|
-
useEffect(function () {
|
|
38
|
-
if (!updateInterval) return;
|
|
39
|
-
var intervalId = setInterval(function () {
|
|
40
|
-
setNow(getNow());
|
|
41
|
-
}, updateInterval);
|
|
42
|
-
return function () {
|
|
43
|
-
clearInterval(intervalId);
|
|
44
|
-
};
|
|
45
|
-
}, [globalNow, updateInterval]);
|
|
46
|
-
return now;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export { useNow as default };
|
|
7
|
+
export { useLocale as default };
|
|
50
8
|
//# sourceMappingURL=use-intl.esm5.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-intl.esm5.js","sources":["../src/
|
|
1
|
+
{"version":3,"file":"use-intl.esm5.js","sources":["../src/useLocale.tsx"],"sourcesContent":["import useIntlContext from './useIntlContext';\n\nexport default function useLocale() {\n return useIntlContext().locale;\n}\n"],"names":["useLocale","useIntlContext","locale"],"mappings":";;AAEc,SAAUA,SAAV,GAAmB;AAC/B,EAAOC,OAAAA,cAAc,GAAGC,MAAxB,CAAA;AACD;;;;"}
|
package/dist/use-intl.esm6.js
CHANGED
|
@@ -1,42 +1,50 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
|
+
import useIntlContext from './use-intl.esm11.js';
|
|
3
|
+
|
|
4
|
+
function getNow() {
|
|
5
|
+
return new Date();
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Reading the current date via `new Date()` in components should be avoided, as
|
|
9
|
+
* it causes components to be impure and can lead to flaky tests. Instead, this
|
|
10
|
+
* hook can be used.
|
|
11
|
+
*
|
|
12
|
+
* By default, it returns the time when the component mounts. If `updateInterval`
|
|
13
|
+
* is specified, the value will be updated based on the interval.
|
|
14
|
+
*
|
|
15
|
+
* You can however also return a static value from this hook, if you
|
|
16
|
+
* configure the `now` parameter on the context provider. Note however,
|
|
17
|
+
* that if `updateInterval` is configured in this case, the component
|
|
18
|
+
* will initialize with the global value, but will afterwards update
|
|
19
|
+
* continuously based on the interval.
|
|
20
|
+
*
|
|
21
|
+
* For unit tests, this can be mocked to a constant value. For end-to-end
|
|
22
|
+
* testing, an environment parameter can be passed to the `now` parameter
|
|
23
|
+
* of the provider to mock this to a static value.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
function useNow(options) {
|
|
28
|
+
var updateInterval = options == null ? void 0 : options.updateInterval;
|
|
29
|
+
|
|
30
|
+
var _useIntlContext = useIntlContext(),
|
|
31
|
+
globalNow = _useIntlContext.now;
|
|
32
|
+
|
|
33
|
+
var _useState = useState(globalNow || getNow()),
|
|
34
|
+
now = _useState[0],
|
|
35
|
+
setNow = _useState[1];
|
|
36
|
+
|
|
37
|
+
useEffect(function () {
|
|
38
|
+
if (!updateInterval) return;
|
|
39
|
+
var intervalId = setInterval(function () {
|
|
40
|
+
setNow(getNow());
|
|
41
|
+
}, updateInterval);
|
|
42
|
+
return function () {
|
|
43
|
+
clearInterval(intervalId);
|
|
44
|
+
};
|
|
45
|
+
}, [globalNow, updateInterval]);
|
|
46
|
+
return now;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export { useNow as default };
|
|
42
50
|
//# sourceMappingURL=use-intl.esm6.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-intl.esm6.js","sources":["../src/
|
|
1
|
+
{"version":3,"file":"use-intl.esm6.js","sources":["../src/useNow.tsx"],"sourcesContent":["import {useState, useEffect} from 'react';\nimport useIntlContext from './useIntlContext';\n\ntype Options = {\n updateInterval?: number;\n};\n\nfunction getNow() {\n return new Date();\n}\n\n/**\n * Reading the current date via `new Date()` in components should be avoided, as\n * it causes components to be impure and can lead to flaky tests. Instead, this\n * hook can be used.\n *\n * By default, it returns the time when the component mounts. If `updateInterval`\n * is specified, the value will be updated based on the interval.\n *\n * You can however also return a static value from this hook, if you\n * configure the `now` parameter on the context provider. Note however,\n * that if `updateInterval` is configured in this case, the component\n * will initialize with the global value, but will afterwards update\n * continuously based on the interval.\n *\n * For unit tests, this can be mocked to a constant value. For end-to-end\n * testing, an environment parameter can be passed to the `now` parameter\n * of the provider to mock this to a static value.\n */\nexport default function useNow(options?: Options) {\n const updateInterval = options?.updateInterval;\n\n const {now: globalNow} = useIntlContext();\n const [now, setNow] = useState(globalNow || getNow());\n\n useEffect(() => {\n if (!updateInterval) return;\n\n const intervalId = setInterval(() => {\n setNow(getNow());\n }, updateInterval);\n\n return () => {\n clearInterval(intervalId);\n };\n }, [globalNow, updateInterval]);\n\n return now;\n}\n"],"names":["getNow","Date","useNow","options","updateInterval","useIntlContext","globalNow","now","useState","setNow","useEffect","intervalId","setInterval","clearInterval"],"mappings":";;;AAOA,SAASA,MAAT,GAAe;AACb,EAAO,OAAA,IAAIC,IAAJ,EAAP,CAAA;AACD,CAAA;AAED;;;;;;;;;;;;;;;;;AAiBG;;;AACqB,SAAAC,MAAA,CAAOC,OAAP,EAAwB;AAC9C,EAAA,IAAMC,cAAc,GAAGD,OAAH,IAAGA,IAAAA,GAAAA,KAAAA,CAAAA,GAAAA,OAAO,CAAEC,cAAhC,CAAA;;AAEA,EAAA,IAAA,eAAA,GAAyBC,cAAc,EAAvC;AAAA,MAAYC,SAAZ,mBAAOC,GAAP,CAAA;;AACA,EAAA,IAAA,SAAA,GAAsBC,QAAQ,CAACF,SAAS,IAAIN,MAAM,EAApB,CAA9B;AAAA,MAAOO,GAAP,GAAA,SAAA,CAAA,CAAA,CAAA;AAAA,MAAYE,MAAZ,GAAA,SAAA,CAAA,CAAA,CAAA,CAAA;;AAEAC,EAAAA,SAAS,CAAC,YAAK;AACb,IAAI,IAAA,CAACN,cAAL,EAAqB,OAAA;AAErB,IAAA,IAAMO,UAAU,GAAGC,WAAW,CAAC,YAAK;AAClCH,MAAAA,MAAM,CAACT,MAAM,EAAP,CAAN,CAAA;AACD,KAF6B,EAE3BI,cAF2B,CAA9B,CAAA;AAIA,IAAA,OAAO,YAAK;AACVS,MAAAA,aAAa,CAACF,UAAD,CAAb,CAAA;AACD,KAFD,CAAA;AAGD,GAVQ,EAUN,CAACL,SAAD,EAAYF,cAAZ,CAVM,CAAT,CAAA;AAYA,EAAA,OAAOG,GAAP,CAAA;AACD;;;;"}
|
package/dist/use-intl.esm7.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import useIntlContext from './use-intl.
|
|
1
|
+
import useIntlContext from './use-intl.esm11.js';
|
|
2
2
|
|
|
3
|
-
function
|
|
4
|
-
return useIntlContext().
|
|
3
|
+
function useTimeZone() {
|
|
4
|
+
return useIntlContext().timeZone;
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
export {
|
|
7
|
+
export { useTimeZone as default };
|
|
8
8
|
//# sourceMappingURL=use-intl.esm7.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-intl.esm7.js","sources":["../src/
|
|
1
|
+
{"version":3,"file":"use-intl.esm7.js","sources":["../src/useTimeZone.tsx"],"sourcesContent":["import useIntlContext from './useIntlContext';\n\nexport default function useTimeZone() {\n return useIntlContext().timeZone;\n}\n"],"names":["useTimeZone","useIntlContext","timeZone"],"mappings":";;AAEc,SAAUA,WAAV,GAAqB;AACjC,EAAOC,OAAAA,cAAc,GAAGC,QAAxB,CAAA;AACD;;;;"}
|
package/dist/use-intl.esm8.js
CHANGED
|
@@ -1,8 +1,42 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { inheritsLoose as _inheritsLoose, wrapNativeSuper as _wrapNativeSuper } from './_virtual/use-intl.esm.js';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
return useIntlContext().timeZone;
|
|
5
|
-
}
|
|
3
|
+
var IntlErrorCode;
|
|
6
4
|
|
|
7
|
-
|
|
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 = {}));
|
|
13
|
+
|
|
14
|
+
var IntlError = /*#__PURE__*/function (_Error) {
|
|
15
|
+
_inheritsLoose(IntlError, _Error);
|
|
16
|
+
|
|
17
|
+
function IntlError(code, originalMessage) {
|
|
18
|
+
var _this;
|
|
19
|
+
|
|
20
|
+
var message = code;
|
|
21
|
+
|
|
22
|
+
if (originalMessage) {
|
|
23
|
+
message += ': ' + originalMessage;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
_this = _Error.call(this, message) || this;
|
|
27
|
+
_this.code = void 0;
|
|
28
|
+
_this.originalMessage = void 0;
|
|
29
|
+
_this.code = code;
|
|
30
|
+
|
|
31
|
+
if (originalMessage) {
|
|
32
|
+
_this.originalMessage = originalMessage;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return _this;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return IntlError;
|
|
39
|
+
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
40
|
+
|
|
41
|
+
export { IntlErrorCode, IntlError as default };
|
|
8
42
|
//# sourceMappingURL=use-intl.esm8.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-intl.esm8.js","sources":["../src/
|
|
1
|
+
{"version":3,"file":"use-intl.esm8.js","sources":["../src/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","originalMessage","message","Error"],"mappings":";;IAAYA,cAAZ;;AAAA,CAAA,UAAYA,aAAZ,EAAyB;AACvBA,EAAAA,aAAA,CAAA,iBAAA,CAAA,GAAA,iBAAA,CAAA;AACAA,EAAAA,aAAA,CAAA,gBAAA,CAAA,GAAA,gBAAA,CAAA;AACAA,EAAAA,aAAA,CAAA,mBAAA,CAAA,GAAA,mBAAA,CAAA;AACAA,EAAAA,aAAA,CAAA,iBAAA,CAAA,GAAA,iBAAA,CAAA;AACAA,EAAAA,aAAA,CAAA,aAAA,CAAA,GAAA,aAAA,CAAA;AACAA,EAAAA,aAAA,CAAA,kBAAA,CAAA,GAAA,kBAAA,CAAA;AACD,CAPD,EAAYA,aAAa,KAAbA,aAAa,GAOxB,EAPwB,CAAzB,CAAA,CAAA;;IASqBC;;;AAInB,EAAYC,SAAAA,SAAAA,CAAAA,IAAZ,EAAiCC,eAAjC,EAAyD;AAAA,IAAA,IAAA,KAAA,CAAA;;AACvD,IAAIC,IAAAA,OAAO,GAAWF,IAAtB,CAAA;;AACA,IAAA,IAAIC,eAAJ,EAAqB;AACnBC,MAAAA,OAAO,IAAI,IAAA,GAAOD,eAAlB,CAAA;AACD,KAAA;;AACD,IAAA,KAAA,GAAA,MAAA,CAAA,IAAA,CAAA,IAAA,EAAMC,OAAN,CAAA,IAAA,IAAA,CAAA;AALuD,IAAA,KAAA,CAHzCF,IAGyC,GAAA,KAAA,CAAA,CAAA;AAAA,IAAA,KAAA,CAFzCC,eAEyC,GAAA,KAAA,CAAA,CAAA;AAOvD,IAAKD,KAAAA,CAAAA,IAAL,GAAYA,IAAZ,CAAA;;AACA,IAAA,IAAIC,eAAJ,EAAqB;AACnB,MAAKA,KAAAA,CAAAA,eAAL,GAAuBA,eAAvB,CAAA;AACD,KAAA;;AAVsD,IAAA,OAAA,KAAA,CAAA;AAWxD,GAAA;;;iCAfoCE;;;;"}
|
package/dist/use-intl.esm9.js
CHANGED
|
@@ -1,32 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { createContext } from 'react';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
Object.entries(messages).forEach(function (_ref) {
|
|
5
|
-
var key = _ref[0],
|
|
6
|
-
messageOrMessages = _ref[1];
|
|
3
|
+
var IntlContext = /*#__PURE__*/createContext(undefined);
|
|
7
4
|
|
|
8
|
-
|
|
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
|
-
});
|
|
20
|
-
}
|
|
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
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export { validateMessages as default };
|
|
5
|
+
export { IntlContext as default };
|
|
32
6
|
//# sourceMappingURL=use-intl.esm9.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-intl.esm9.js","sources":["../src/
|
|
1
|
+
{"version":3,"file":"use-intl.esm9.js","sources":["../src/IntlContext.tsx"],"sourcesContent":["import {createContext} from 'react';\nimport AbstractIntlMessages from './AbstractIntlMessages';\nimport Formats from './Formats';\nimport IntlError from './IntlError';\nimport {RichTranslationValues} from './TranslationValues';\n\nexport type IntlContextShape = {\n messages?: AbstractIntlMessages;\n locale: string;\n formats?: Partial<Formats>;\n timeZone?: string;\n onError(error: IntlError): void;\n getMessageFallback(info: {\n error: IntlError;\n key: string;\n namespace?: string;\n }): string;\n now?: Date;\n defaultTranslationValues?: RichTranslationValues;\n};\n\nconst IntlContext = createContext<IntlContextShape | undefined>(undefined);\n\nexport default IntlContext;\n"],"names":["IntlContext","createContext","undefined"],"mappings":";;AAqBA,IAAMA,WAAW,gBAAGC,aAAa,CAA+BC,SAA/B;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "use-intl",
|
|
3
|
-
"version": "2.7.2
|
|
3
|
+
"version": "2.7.2",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"author": "Jan Amann <jan@amann.me>",
|
|
6
6
|
"description": "Minimal, but complete solution for managing internationalization in React apps.",
|
|
@@ -59,5 +59,5 @@
|
|
|
59
59
|
"engines": {
|
|
60
60
|
"node": ">=10"
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "0e4dd6047240d66186b376eaf9c9b6d18dee3c53"
|
|
63
63
|
}
|