use-intl 2.13.4 → 2.14.0
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/core/use-intl.esm2.js +2 -2
- package/dist/core/use-intl.esm3.js +1 -1
- package/dist/core/use-intl.esm5.js +50 -12
- package/dist/core/use-intl.esm6.js +12 -50
- package/dist/core/use-intl.esm7.js +1 -1
- package/dist/react/use-intl.esm3.js +3 -40
- package/dist/react/use-intl.esm4.js +40 -3
- package/dist/react/use-intl.esm6.js +4 -10
- package/dist/react/use-intl.esm7.js +10 -4
- package/dist/react/use-intl.esm9.js +1 -1
- package/dist/use-intl.esm.js +4 -4
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose, extends as _extends } from '../_virtual/use-intl.esm.js';
|
|
2
|
-
import createTranslatorImpl from './use-intl.
|
|
3
|
-
import { defaultGetMessageFallback, defaultOnError } from './use-intl.
|
|
2
|
+
import createTranslatorImpl from './use-intl.esm5.js';
|
|
3
|
+
import { defaultGetMessageFallback, defaultOnError } from './use-intl.esm6.js';
|
|
4
4
|
|
|
5
5
|
var _excluded = ["getMessageFallback", "messages", "namespace", "onError"];
|
|
6
6
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { extends as _extends } from '../_virtual/use-intl.esm.js';
|
|
2
2
|
import IntlError, { IntlErrorCode } from './use-intl.esm.js';
|
|
3
|
-
import { defaultOnError } from './use-intl.
|
|
3
|
+
import { defaultOnError } from './use-intl.esm6.js';
|
|
4
4
|
|
|
5
5
|
var MINUTE = 60;
|
|
6
6
|
var HOUR = MINUTE * 60;
|
|
@@ -1,15 +1,53 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose, extends as _extends } from '../_virtual/use-intl.esm.js';
|
|
2
|
+
import IntlError, { IntlErrorCode } from './use-intl.esm.js';
|
|
3
|
+
import createBaseTranslator, { getMessagesOrError } from './use-intl.esm7.js';
|
|
4
|
+
import resolveNamespace from './use-intl.esm8.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
|
+
messagesOrError: getMessagesOrError({
|
|
21
|
+
messages: messages,
|
|
22
|
+
namespace: namespace,
|
|
23
|
+
onError: onError
|
|
24
|
+
})
|
|
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 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);
|
|
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;
|
|
12
50
|
}
|
|
13
51
|
|
|
14
|
-
export {
|
|
52
|
+
export { createTranslatorImpl as default };
|
|
15
53
|
//# sourceMappingURL=use-intl.esm5.js.map
|
|
@@ -1,53 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
messagesOrError: getMessagesOrError({
|
|
21
|
-
messages: messages,
|
|
22
|
-
namespace: namespace,
|
|
23
|
-
onError: onError
|
|
24
|
-
})
|
|
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 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);
|
|
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;
|
|
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);
|
|
50
12
|
}
|
|
51
13
|
|
|
52
|
-
export {
|
|
14
|
+
export { defaultGetMessageFallback, defaultOnError };
|
|
53
15
|
//# sourceMappingURL=use-intl.esm6.js.map
|
|
@@ -3,7 +3,7 @@ import IntlMessageFormat from 'intl-messageformat';
|
|
|
3
3
|
import { isValidElement, cloneElement } from 'react';
|
|
4
4
|
import IntlError, { IntlErrorCode } from './use-intl.esm.js';
|
|
5
5
|
import convertFormatsToIntlMessageFormat from './use-intl.esm10.js';
|
|
6
|
-
import { defaultOnError, defaultGetMessageFallback } from './use-intl.
|
|
6
|
+
import { defaultOnError, defaultGetMessageFallback } from './use-intl.esm6.js';
|
|
7
7
|
|
|
8
8
|
function resolvePath(messages, key, namespace) {
|
|
9
9
|
if (!messages) {
|
|
@@ -1,45 +1,8 @@
|
|
|
1
|
-
import { useState, useEffect } from 'react';
|
|
2
1
|
import useIntlContext from './use-intl.esm10.js';
|
|
3
2
|
|
|
4
|
-
function
|
|
5
|
-
return
|
|
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
|
-
function useNow(options) {
|
|
26
|
-
var updateInterval = options == null ? void 0 : options.updateInterval;
|
|
27
|
-
var _useIntlContext = useIntlContext(),
|
|
28
|
-
globalNow = _useIntlContext.now;
|
|
29
|
-
var _useState = useState(globalNow || getNow()),
|
|
30
|
-
now = _useState[0],
|
|
31
|
-
setNow = _useState[1];
|
|
32
|
-
useEffect(function () {
|
|
33
|
-
if (!updateInterval) return;
|
|
34
|
-
var intervalId = setInterval(function () {
|
|
35
|
-
setNow(getNow());
|
|
36
|
-
}, updateInterval);
|
|
37
|
-
return function () {
|
|
38
|
-
clearInterval(intervalId);
|
|
39
|
-
};
|
|
40
|
-
}, [globalNow, updateInterval]);
|
|
41
|
-
return now;
|
|
3
|
+
function useLocale() {
|
|
4
|
+
return useIntlContext().locale;
|
|
42
5
|
}
|
|
43
6
|
|
|
44
|
-
export {
|
|
7
|
+
export { useLocale as default };
|
|
45
8
|
//# sourceMappingURL=use-intl.esm3.js.map
|
|
@@ -1,8 +1,45 @@
|
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
1
2
|
import useIntlContext from './use-intl.esm10.js';
|
|
2
3
|
|
|
3
|
-
function
|
|
4
|
-
return
|
|
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
|
+
function useNow(options) {
|
|
26
|
+
var updateInterval = options == null ? void 0 : options.updateInterval;
|
|
27
|
+
var _useIntlContext = useIntlContext(),
|
|
28
|
+
globalNow = _useIntlContext.now;
|
|
29
|
+
var _useState = useState(globalNow || getNow()),
|
|
30
|
+
now = _useState[0],
|
|
31
|
+
setNow = _useState[1];
|
|
32
|
+
useEffect(function () {
|
|
33
|
+
if (!updateInterval) return;
|
|
34
|
+
var intervalId = setInterval(function () {
|
|
35
|
+
setNow(getNow());
|
|
36
|
+
}, updateInterval);
|
|
37
|
+
return function () {
|
|
38
|
+
clearInterval(intervalId);
|
|
39
|
+
};
|
|
40
|
+
}, [globalNow, updateInterval]);
|
|
41
|
+
return now;
|
|
5
42
|
}
|
|
6
43
|
|
|
7
|
-
export {
|
|
44
|
+
export { useNow as default };
|
|
8
45
|
//# sourceMappingURL=use-intl.esm4.js.map
|
|
@@ -1,22 +1,16 @@
|
|
|
1
1
|
import { useMemo } from 'react';
|
|
2
|
-
import
|
|
2
|
+
import createFormatter from '../core/use-intl.esm3.js';
|
|
3
3
|
import useIntlContext from './use-intl.esm10.js';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
/** @deprecated Switch to `useFormatter` instead. */
|
|
7
|
-
function useIntl() {
|
|
5
|
+
function useFormatter() {
|
|
8
6
|
var _useIntlContext = useIntlContext(),
|
|
9
7
|
formats = _useIntlContext.formats,
|
|
10
8
|
locale = _useIntlContext.locale,
|
|
11
9
|
globalNow = _useIntlContext.now,
|
|
12
10
|
onError = _useIntlContext.onError,
|
|
13
11
|
timeZone = _useIntlContext.timeZone;
|
|
14
|
-
if (!hasWarned) {
|
|
15
|
-
hasWarned = true;
|
|
16
|
-
console.warn('`useIntl()` is deprecated and will be removed in the next major version. Please switch to `useFormatter()`.');
|
|
17
|
-
}
|
|
18
12
|
return useMemo(function () {
|
|
19
|
-
return
|
|
13
|
+
return createFormatter({
|
|
20
14
|
formats: formats,
|
|
21
15
|
locale: locale,
|
|
22
16
|
now: globalNow,
|
|
@@ -26,5 +20,5 @@ function useIntl() {
|
|
|
26
20
|
}, [formats, globalNow, locale, onError, timeZone]);
|
|
27
21
|
}
|
|
28
22
|
|
|
29
|
-
export {
|
|
23
|
+
export { useFormatter as default };
|
|
30
24
|
//# sourceMappingURL=use-intl.esm6.js.map
|
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
import { useMemo } from 'react';
|
|
2
|
-
import
|
|
2
|
+
import createIntl from '../core/use-intl.esm4.js';
|
|
3
3
|
import useIntlContext from './use-intl.esm10.js';
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
var hasWarned = false;
|
|
6
|
+
/** @deprecated Switch to `useFormatter` instead. */
|
|
7
|
+
function useIntl() {
|
|
6
8
|
var _useIntlContext = useIntlContext(),
|
|
7
9
|
formats = _useIntlContext.formats,
|
|
8
10
|
locale = _useIntlContext.locale,
|
|
9
11
|
globalNow = _useIntlContext.now,
|
|
10
12
|
onError = _useIntlContext.onError,
|
|
11
13
|
timeZone = _useIntlContext.timeZone;
|
|
14
|
+
if (!hasWarned) {
|
|
15
|
+
hasWarned = true;
|
|
16
|
+
console.warn('`useIntl()` is deprecated and will be removed in the next major version. Please switch to `useFormatter()`.');
|
|
17
|
+
}
|
|
12
18
|
return useMemo(function () {
|
|
13
|
-
return
|
|
19
|
+
return createIntl({
|
|
14
20
|
formats: formats,
|
|
15
21
|
locale: locale,
|
|
16
22
|
now: globalNow,
|
|
@@ -20,5 +26,5 @@ function useFormatter() {
|
|
|
20
26
|
}, [formats, globalNow, locale, onError, timeZone]);
|
|
21
27
|
}
|
|
22
28
|
|
|
23
|
-
export {
|
|
29
|
+
export { useIntl as default };
|
|
24
30
|
//# sourceMappingURL=use-intl.esm7.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose, extends as _extends } from '../_virtual/use-intl.esm.js';
|
|
2
|
-
import { defaultOnError, defaultGetMessageFallback } from '../core/use-intl.
|
|
2
|
+
import { defaultOnError, defaultGetMessageFallback } from '../core/use-intl.esm6.js';
|
|
3
3
|
import validateMessages from '../core/use-intl.esm9.js';
|
|
4
4
|
|
|
5
5
|
var _excluded = ["getMessageFallback", "messages", "onError"];
|
package/dist/use-intl.esm.js
CHANGED
|
@@ -4,9 +4,9 @@ export { default as createFormatter } from './core/use-intl.esm3.js';
|
|
|
4
4
|
export { default as createIntl } from './core/use-intl.esm4.js';
|
|
5
5
|
export { default as IntlProvider } from './react/use-intl.esm.js';
|
|
6
6
|
export { default as useTranslations } from './react/use-intl.esm2.js';
|
|
7
|
-
export { default as useLocale } from './react/use-intl.
|
|
8
|
-
export { default as useNow } from './react/use-intl.
|
|
7
|
+
export { default as useLocale } from './react/use-intl.esm3.js';
|
|
8
|
+
export { default as useNow } from './react/use-intl.esm4.js';
|
|
9
9
|
export { default as useTimeZone } from './react/use-intl.esm5.js';
|
|
10
|
-
export { default as useFormatter } from './react/use-intl.
|
|
11
|
-
export { default as useIntl } from './react/use-intl.
|
|
10
|
+
export { default as useFormatter } from './react/use-intl.esm6.js';
|
|
11
|
+
export { default as useIntl } from './react/use-intl.esm7.js';
|
|
12
12
|
//# sourceMappingURL=use-intl.esm.js.map
|