use-intl 2.14.0 → 2.14.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/core/use-intl.esm.js +34 -30
- package/dist/core/use-intl.esm.js.map +1 -1
- package/dist/core/use-intl.esm2.js +126 -31
- package/dist/core/use-intl.esm3.js +8 -126
- package/dist/core/use-intl.esm4.js +30 -11
- package/dist/core/use-intl.esm4.js.map +1 -1
- package/dist/core/use-intl.esm5.js +12 -50
- package/dist/core/use-intl.esm6.js +50 -12
- package/dist/core/use-intl.esm7.js +20 -183
- package/dist/core/use-intl.esm7.js.map +1 -1
- package/dist/core/use-intl.esm8.js +188 -7
- package/dist/core/use-intl.esm8.js.map +1 -1
- package/dist/core/use-intl.esm9.js +7 -25
- package/dist/core/use-intl.esm9.js.map +1 -1
- package/dist/react/use-intl.esm.js +1 -1
- package/dist/react/use-intl.esm.js.map +1 -1
- package/dist/react/use-intl.esm10.js +24 -8
- package/dist/react/use-intl.esm10.js.map +1 -1
- package/dist/react/use-intl.esm11.js +3 -3
- package/dist/react/use-intl.esm11.js.map +1 -1
- package/dist/react/use-intl.esm2.js +20 -22
- package/dist/react/use-intl.esm2.js.map +1 -1
- package/dist/react/use-intl.esm3.js +1 -1
- package/dist/react/use-intl.esm3.js.map +1 -1
- package/dist/react/use-intl.esm4.js +19 -38
- package/dist/react/use-intl.esm4.js.map +1 -1
- package/dist/react/use-intl.esm5.js +41 -4
- package/dist/react/use-intl.esm5.js.map +1 -1
- package/dist/react/use-intl.esm6.js +4 -20
- package/dist/react/use-intl.esm7.js +2 -2
- package/dist/react/use-intl.esm7.js.map +1 -1
- package/dist/react/use-intl.esm8.js.map +1 -1
- package/dist/react/use-intl.esm9.js +8 -24
- package/dist/use-intl.esm.js +8 -8
- package/package.json +1 -1
|
@@ -1,13 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose, extends as _extends } from '../_virtual/use-intl.esm.js';
|
|
2
|
+
import { defaultOnError, defaultGetMessageFallback } from '../core/use-intl.esm5.js';
|
|
3
|
+
import validateMessages from '../core/use-intl.esm7.js';
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
var _excluded = ["getMessageFallback", "messages", "onError"];
|
|
6
|
+
/**
|
|
7
|
+
* Enhances the incoming props with defaults.
|
|
8
|
+
*/
|
|
9
|
+
function getInitializedConfig(_ref) {
|
|
10
|
+
var getMessageFallback = _ref.getMessageFallback,
|
|
11
|
+
messages = _ref.messages,
|
|
12
|
+
onError = _ref.onError,
|
|
13
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
14
|
+
var finalOnError = onError || defaultOnError;
|
|
15
|
+
var finalGetMessageFallback = getMessageFallback || defaultGetMessageFallback;
|
|
16
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
17
|
+
if (messages) {
|
|
18
|
+
validateMessages(messages, finalOnError);
|
|
19
|
+
}
|
|
8
20
|
}
|
|
9
|
-
return
|
|
21
|
+
return _extends({}, rest, {
|
|
22
|
+
messages: messages,
|
|
23
|
+
onError: finalOnError,
|
|
24
|
+
getMessageFallback: finalGetMessageFallback
|
|
25
|
+
});
|
|
10
26
|
}
|
|
11
27
|
|
|
12
|
-
export {
|
|
28
|
+
export { getInitializedConfig as default };
|
|
13
29
|
//# sourceMappingURL=use-intl.esm10.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-intl.esm10.js","sources":["../../src/react/
|
|
1
|
+
{"version":3,"file":"use-intl.esm10.js","sources":["../../src/react/getInitializedConfig.tsx"],"sourcesContent":["import IntlConfig from '../core/IntlConfig';\nimport {defaultGetMessageFallback, defaultOnError} from '../core/defaults';\nimport validateMessages from '../core/validateMessages';\n\n/**\n * Enhances the incoming props with defaults.\n */\nexport default function getInitializedConfig<\n // This is a generic to allow for stricter typing. E.g.\n // the RSC integration always provides a `now` value.\n Props extends Omit<IntlConfig, 'children'>\n>({getMessageFallback, messages, onError, ...rest}: Props) {\n const finalOnError = onError || defaultOnError;\n const finalGetMessageFallback =\n getMessageFallback || defaultGetMessageFallback;\n\n if (process.env.NODE_ENV !== 'production') {\n if (messages) {\n validateMessages(messages, finalOnError);\n }\n }\n\n return {\n ...rest,\n messages,\n onError: finalOnError,\n getMessageFallback: finalGetMessageFallback\n };\n}\n"],"names":["getInitializedConfig","_ref","getMessageFallback","messages","onError","rest","_objectWithoutPropertiesLoose","_excluded","finalOnError","defaultOnError","finalGetMessageFallback","defaultGetMessageFallback","process","env","NODE_ENV","validateMessages","_extends"],"mappings":";;;;;AAIA;;AAEG;AACqB,SAAAA,oBAAoBA,CAAAC,IAAA,EAIa;AAAA,EAAA,IAAtDC,kBAAkB,GAAAD,IAAA,CAAlBC,kBAAkB;IAAEC,QAAQ,GAAAF,IAAA,CAARE,QAAQ;IAAEC,OAAO,GAAAH,IAAA,CAAPG,OAAO;AAAKC,IAAAA,IAAI,GAAAC,6BAAA,CAAAL,IAAA,EAAAM,SAAA,CAAA,CAAA;AAC/C,EAAA,IAAMC,YAAY,GAAGJ,OAAO,IAAIK,cAAc,CAAA;AAC9C,EAAA,IAAMC,uBAAuB,GAC3BR,kBAAkB,IAAIS,yBAAyB,CAAA;AAEjD,EAAA,IAAIC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,EAAE;AACzC,IAAA,IAAIX,QAAQ,EAAE;AACZY,MAAAA,gBAAgB,CAACZ,QAAQ,EAAEK,YAAY,CAAC,CAAA;AACzC,KAAA;AACF,GAAA;EAED,OAAAQ,QAAA,KACKX,IAAI,EAAA;AACPF,IAAAA,QAAQ,EAARA,QAAQ;AACRC,IAAAA,OAAO,EAAEI,YAAY;AACrBN,IAAAA,kBAAkB,EAAEQ,uBAAAA;AAAuB,GAAA,CAAA,CAAA;AAE/C;;;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useRef, useMemo } from 'react';
|
|
2
|
-
import createBaseTranslator, { getMessagesOrError } from '../core/use-intl.
|
|
3
|
-
import resolveNamespace from '../core/use-intl.
|
|
4
|
-
import useIntlContext from './use-intl.
|
|
2
|
+
import createBaseTranslator, { getMessagesOrError } from '../core/use-intl.esm8.js';
|
|
3
|
+
import resolveNamespace from '../core/use-intl.esm9.js';
|
|
4
|
+
import useIntlContext from './use-intl.esm9.js';
|
|
5
5
|
|
|
6
6
|
function useTranslationsImpl(allMessages, namespace, namespacePrefix) {
|
|
7
7
|
var _useIntlContext = useIntlContext(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-intl.esm11.js","sources":["../../src/react/
|
|
1
|
+
{"version":3,"file":"use-intl.esm11.js","sources":["../../src/react/useTranslationsImpl.tsx"],"sourcesContent":["// eslint-disable-next-line import/no-named-as-default -- False positive\nimport IntlMessageFormat from 'intl-messageformat';\nimport {useMemo, useRef} from 'react';\nimport AbstractIntlMessages from '../core/AbstractIntlMessages';\nimport createBaseTranslator, {\n getMessagesOrError\n} from '../core/createBaseTranslator';\nimport resolveNamespace from '../core/resolveNamespace';\nimport NestedKeyOf from '../core/utils/NestedKeyOf';\nimport useIntlContext from './useIntlContext';\n\nexport default function useTranslationsImpl<\n Messages extends AbstractIntlMessages,\n NestedKey extends NestedKeyOf<Messages>\n>(allMessages: Messages, namespace: NestedKey, namespacePrefix: string) {\n const {\n defaultTranslationValues,\n formats: globalFormats,\n getMessageFallback,\n locale,\n onError,\n timeZone\n } = useIntlContext();\n\n // The `namespacePrefix` is part of the type system.\n // See the comment in the hook invocation.\n allMessages = allMessages[namespacePrefix] as Messages;\n namespace = resolveNamespace(namespace, namespacePrefix) as NestedKey;\n\n const cachedFormatsByLocaleRef = useRef<\n Record<string, Record<string, IntlMessageFormat>>\n >({});\n\n const messagesOrError = useMemo(\n () => getMessagesOrError({messages: allMessages, namespace, onError}),\n [allMessages, namespace, onError]\n );\n\n const translate = useMemo(\n () =>\n createBaseTranslator({\n cachedFormatsByLocale: cachedFormatsByLocaleRef.current,\n getMessageFallback,\n messagesOrError,\n defaultTranslationValues,\n namespace,\n onError,\n formats: globalFormats,\n locale,\n timeZone\n }),\n [\n getMessageFallback,\n messagesOrError,\n defaultTranslationValues,\n namespace,\n onError,\n globalFormats,\n locale,\n timeZone\n ]\n );\n\n return translate;\n}\n"],"names":["useTranslationsImpl","allMessages","namespace","namespacePrefix","_useIntlContext","useIntlContext","defaultTranslationValues","globalFormats","formats","getMessageFallback","locale","onError","timeZone","resolveNamespace","cachedFormatsByLocaleRef","useRef","messagesOrError","useMemo","getMessagesOrError","messages","translate","createBaseTranslator","cachedFormatsByLocale","current"],"mappings":";;;;;AAWwB,SAAAA,mBAAmBA,CAGzCC,WAAqB,EAAEC,SAAoB,EAAEC,eAAuB,EAAA;AACpE,EAAA,IAAAC,eAAA,GAOIC,cAAc,EAAE;IANlBC,wBAAwB,GAAAF,eAAA,CAAxBE,wBAAwB;IACfC,aAAa,GAAAH,eAAA,CAAtBI,OAAO;IACPC,kBAAkB,GAAAL,eAAA,CAAlBK,kBAAkB;IAClBC,MAAM,GAAAN,eAAA,CAANM,MAAM;IACNC,OAAO,GAAAP,eAAA,CAAPO,OAAO;IACPC,QAAQ,GAAAR,eAAA,CAARQ,QAAQ,CAAA;AAGV;AACA;AACAX,EAAAA,WAAW,GAAGA,WAAW,CAACE,eAAe,CAAa,CAAA;AACtDD,EAAAA,SAAS,GAAGW,gBAAgB,CAACX,SAAS,EAAEC,eAAe,CAAc,CAAA;AAErE,EAAA,IAAMW,wBAAwB,GAAGC,MAAM,CAErC,EAAE,CAAC,CAAA;EAEL,IAAMC,eAAe,GAAGC,OAAO,CAC7B,YAAA;AAAA,IAAA,OAAMC,kBAAkB,CAAC;AAACC,MAAAA,QAAQ,EAAElB,WAAW;AAAEC,MAAAA,SAAS,EAATA,SAAS;AAAES,MAAAA,OAAO,EAAPA,OAAAA;AAAO,KAAC,CAAC,CAAA;AAAA,GAAA,EACrE,CAACV,WAAW,EAAEC,SAAS,EAAES,OAAO,CAAC,CAClC,CAAA;EAED,IAAMS,SAAS,GAAGH,OAAO,CACvB,YAAA;AAAA,IAAA,OACEI,oBAAoB,CAAC;MACnBC,qBAAqB,EAAER,wBAAwB,CAACS,OAAO;AACvDd,MAAAA,kBAAkB,EAAlBA,kBAAkB;AAClBO,MAAAA,eAAe,EAAfA,eAAe;AACfV,MAAAA,wBAAwB,EAAxBA,wBAAwB;AACxBJ,MAAAA,SAAS,EAATA,SAAS;AACTS,MAAAA,OAAO,EAAPA,OAAO;AACPH,MAAAA,OAAO,EAAED,aAAa;AACtBG,MAAAA,MAAM,EAANA,MAAM;AACNE,MAAAA,QAAQ,EAARA,QAAAA;AACD,KAAA,CAAC,CAAA;AAAA,GAAA,EACJ,CACEH,kBAAkB,EAClBO,eAAe,EACfV,wBAAwB,EACxBJ,SAAS,EACTS,OAAO,EACPJ,aAAa,EACbG,MAAM,EACNE,QAAQ,CACT,CACF,CAAA;AAED,EAAA,OAAOQ,SAAS,CAAA;AAClB;;;;"}
|
|
@@ -1,26 +1,24 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import createFormatter from '../core/use-intl.esm2.js';
|
|
3
|
+
import useIntlContext from './use-intl.esm9.js';
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
},
|
|
21
|
-
// @ts-ignore
|
|
22
|
-
namespace ? "!." + namespace : '!', '!');
|
|
5
|
+
function useFormatter() {
|
|
6
|
+
var _useIntlContext = useIntlContext(),
|
|
7
|
+
formats = _useIntlContext.formats,
|
|
8
|
+
locale = _useIntlContext.locale,
|
|
9
|
+
globalNow = _useIntlContext.now,
|
|
10
|
+
onError = _useIntlContext.onError,
|
|
11
|
+
timeZone = _useIntlContext.timeZone;
|
|
12
|
+
return useMemo(function () {
|
|
13
|
+
return createFormatter({
|
|
14
|
+
formats: formats,
|
|
15
|
+
locale: locale,
|
|
16
|
+
now: globalNow,
|
|
17
|
+
onError: onError,
|
|
18
|
+
timeZone: timeZone
|
|
19
|
+
});
|
|
20
|
+
}, [formats, globalNow, locale, onError, timeZone]);
|
|
23
21
|
}
|
|
24
22
|
|
|
25
|
-
export {
|
|
23
|
+
export { useFormatter as default };
|
|
26
24
|
//# sourceMappingURL=use-intl.esm2.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-intl.esm2.js","sources":["../../src/react/
|
|
1
|
+
{"version":3,"file":"use-intl.esm2.js","sources":["../../src/react/useFormatter.tsx"],"sourcesContent":["import {useMemo} from 'react';\nimport createFormatter from '../core/createFormatter';\nimport useIntlContext from './useIntlContext';\n\nexport default function useFormatter() {\n const {formats, locale, now: globalNow, onError, timeZone} = useIntlContext();\n\n return useMemo(\n () =>\n createFormatter({\n formats,\n locale,\n now: globalNow,\n onError,\n timeZone\n }),\n [formats, globalNow, locale, onError, timeZone]\n );\n}\n"],"names":["useFormatter","_useIntlContext","useIntlContext","formats","locale","globalNow","now","onError","timeZone","useMemo","createFormatter"],"mappings":";;;;AAIc,SAAUA,YAAYA,GAAA;AAClC,EAAA,IAAAC,eAAA,GAA6DC,cAAc,EAAE;IAAtEC,OAAO,GAAAF,eAAA,CAAPE,OAAO;IAAEC,MAAM,GAAAH,eAAA,CAANG,MAAM;IAAOC,SAAS,GAAAJ,eAAA,CAAdK,GAAG;IAAaC,OAAO,GAAAN,eAAA,CAAPM,OAAO;IAAEC,QAAQ,GAAAP,eAAA,CAARO,QAAQ,CAAA;AAEzD,EAAA,OAAOC,OAAO,CACZ,YAAA;AAAA,IAAA,OACEC,eAAe,CAAC;AACdP,MAAAA,OAAO,EAAPA,OAAO;AACPC,MAAAA,MAAM,EAANA,MAAM;AACNE,MAAAA,GAAG,EAAED,SAAS;AACdE,MAAAA,OAAO,EAAPA,OAAO;AACPC,MAAAA,QAAQ,EAARA,QAAAA;AACD,KAAA,CAAC,CAAA;GACJ,EAAA,CAACL,OAAO,EAAEE,SAAS,EAAED,MAAM,EAAEG,OAAO,EAAEC,QAAQ,CAAC,CAChD,CAAA;AACH;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-intl.esm3.js","sources":["../../src/react/
|
|
1
|
+
{"version":3,"file":"use-intl.esm3.js","sources":["../../src/react/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,SAASA,GAAA;AAC/B,EAAA,OAAOC,cAAc,EAAE,CAACC,MAAM,CAAA;AAChC;;;;"}
|
|
@@ -1,45 +1,26 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import useIntlContext from './use-intl.esm9.js';
|
|
2
|
+
import useTranslationsImpl from './use-intl.esm11.js';
|
|
3
3
|
|
|
4
|
-
function getNow() {
|
|
5
|
-
return new Date();
|
|
6
|
-
}
|
|
7
4
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
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.
|
|
5
|
+
* Translates messages from the given namespace by using the ICU syntax.
|
|
6
|
+
* See https://formatjs.io/docs/core-concepts/icu-syntax.
|
|
20
7
|
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
8
|
+
* If no namespace is provided, all available messages are returned.
|
|
9
|
+
* The namespace can also indicate nesting by using a dot
|
|
10
|
+
* (e.g. `namespace.Component`).
|
|
24
11
|
*/
|
|
25
|
-
function
|
|
26
|
-
var
|
|
27
|
-
var
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}, updateInterval);
|
|
37
|
-
return function () {
|
|
38
|
-
clearInterval(intervalId);
|
|
39
|
-
};
|
|
40
|
-
}, [globalNow, updateInterval]);
|
|
41
|
-
return now;
|
|
12
|
+
function useTranslations(namespace) {
|
|
13
|
+
var context = useIntlContext();
|
|
14
|
+
var messages = context.messages;
|
|
15
|
+
// We have to wrap the actual hook so the type inference for the optional
|
|
16
|
+
// namespace works correctly. See https://stackoverflow.com/a/71529575/343045
|
|
17
|
+
// The prefix ("!") is arbitrary.
|
|
18
|
+
return useTranslationsImpl({
|
|
19
|
+
'!': messages
|
|
20
|
+
},
|
|
21
|
+
// @ts-ignore
|
|
22
|
+
namespace ? "!." + namespace : '!', '!');
|
|
42
23
|
}
|
|
43
24
|
|
|
44
|
-
export {
|
|
25
|
+
export { useTranslations as default };
|
|
45
26
|
//# sourceMappingURL=use-intl.esm4.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-intl.esm4.js","sources":["../../src/react/
|
|
1
|
+
{"version":3,"file":"use-intl.esm4.js","sources":["../../src/react/useTranslations.tsx"],"sourcesContent":["import {ReactElement, ReactNodeArray} from 'react';\nimport Formats from '../core/Formats';\nimport TranslationValues, {\n RichTranslationValues\n} from '../core/TranslationValues';\nimport MessageKeys from '../core/utils/MessageKeys';\nimport NamespaceKeys from '../core/utils/NamespaceKeys';\nimport NestedKeyOf from '../core/utils/NestedKeyOf';\nimport NestedValueOf from '../core/utils/NestedValueOf';\nimport useIntlContext from './useIntlContext';\nimport useTranslationsImpl from './useTranslationsImpl';\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<\n IntlMessages,\n NestedKeyOf<IntlMessages>\n > = never\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 [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?: RichTranslationValues,\n formats?: Partial<Formats>\n ): string | ReactElement | ReactNodeArray;\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 const context = useIntlContext();\n const messages = context.messages as IntlMessages;\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.\n return useTranslationsImpl<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >(\n {'!': messages},\n // @ts-ignore\n namespace ? `!.${namespace}` : '!',\n '!'\n );\n}\n"],"names":["useTranslations","namespace","context","useIntlContext","messages","useTranslationsImpl"],"mappings":";;;AAYA;;;;;;;AAOG;AACqB,SAAAA,eAAeA,CAMrCC,SAAqB,EAAA;AA6DrB,EAAA,IAAMC,OAAO,GAAGC,cAAc,EAAE,CAAA;AAChC,EAAA,IAAMC,QAAQ,GAAGF,OAAO,CAACE,QAAwB,CAAA;AAEjD;AACA;AACA;AACA,EAAA,OAAOC,mBAAmB,CAIxB;AAAC,IAAA,GAAG,EAAED,QAAAA;GAAS;AACf;AACAH,EAAAA,SAAS,UAAQA,SAAS,GAAK,GAAG,EAClC,GAAG,CACJ,CAAA;AACH;;;;"}
|
|
@@ -1,8 +1,45 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
|
+
import useIntlContext from './use-intl.esm9.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.esm5.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-intl.esm5.js","sources":["../../src/react/
|
|
1
|
+
{"version":3,"file":"use-intl.esm5.js","sources":["../../src/react/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","useIntlContext","globalNow","now","_useState","useState","setNow","useEffect","intervalId","setInterval","clearInterval"],"mappings":";;;AAOA,SAASA,MAAMA,GAAA;EACb,OAAO,IAAIC,IAAI,EAAE,CAAA;AACnB,CAAA;AAEA;;;;;;;;;;;;;;;;;AAiBG;AACqB,SAAAC,MAAMA,CAACC,OAAiB,EAAA;AAC9C,EAAA,IAAMC,cAAc,GAAGD,OAAO,IAAPA,IAAAA,GAAAA,KAAAA,CAAAA,GAAAA,OAAO,CAAEC,cAAc,CAAA;AAE9C,EAAA,IAAAC,eAAA,GAAyBC,cAAc,EAAE;IAA7BC,SAAS,GAAAF,eAAA,CAAdG,GAAG,CAAA;EACV,IAAAC,SAAA,GAAsBC,QAAQ,CAACH,SAAS,IAAIP,MAAM,EAAE,CAAC;AAA9CQ,IAAAA,GAAG,GAAAC,SAAA,CAAA,CAAA,CAAA;AAAEE,IAAAA,MAAM,GAAAF,SAAA,CAAA,CAAA,CAAA,CAAA;AAElBG,EAAAA,SAAS,CAAC,YAAK;IACb,IAAI,CAACR,cAAc,EAAE,OAAA;AAErB,IAAA,IAAMS,UAAU,GAAGC,WAAW,CAAC,YAAK;AAClCH,MAAAA,MAAM,CAACX,MAAM,EAAE,CAAC,CAAA;KACjB,EAAEI,cAAc,CAAC,CAAA;AAElB,IAAA,OAAO,YAAK;MACVW,aAAa,CAACF,UAAU,CAAC,CAAA;KAC1B,CAAA;AACH,GAAC,EAAE,CAACN,SAAS,EAAEH,cAAc,CAAC,CAAC,CAAA;AAE/B,EAAA,OAAOI,GAAG,CAAA;AACZ;;;;"}
|
|
@@ -1,24 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import createFormatter from '../core/use-intl.esm3.js';
|
|
3
|
-
import useIntlContext from './use-intl.esm10.js';
|
|
1
|
+
import useIntlContext from './use-intl.esm9.js';
|
|
4
2
|
|
|
5
|
-
function
|
|
6
|
-
|
|
7
|
-
formats = _useIntlContext.formats,
|
|
8
|
-
locale = _useIntlContext.locale,
|
|
9
|
-
globalNow = _useIntlContext.now,
|
|
10
|
-
onError = _useIntlContext.onError,
|
|
11
|
-
timeZone = _useIntlContext.timeZone;
|
|
12
|
-
return useMemo(function () {
|
|
13
|
-
return createFormatter({
|
|
14
|
-
formats: formats,
|
|
15
|
-
locale: locale,
|
|
16
|
-
now: globalNow,
|
|
17
|
-
onError: onError,
|
|
18
|
-
timeZone: timeZone
|
|
19
|
-
});
|
|
20
|
-
}, [formats, globalNow, locale, onError, timeZone]);
|
|
3
|
+
function useTimeZone() {
|
|
4
|
+
return useIntlContext().timeZone;
|
|
21
5
|
}
|
|
22
6
|
|
|
23
|
-
export {
|
|
7
|
+
export { useTimeZone as default };
|
|
24
8
|
//# sourceMappingURL=use-intl.esm6.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useMemo } from 'react';
|
|
2
|
-
import createIntl from '../core/use-intl.
|
|
3
|
-
import useIntlContext from './use-intl.
|
|
2
|
+
import createIntl from '../core/use-intl.esm3.js';
|
|
3
|
+
import useIntlContext from './use-intl.esm9.js';
|
|
4
4
|
|
|
5
5
|
var hasWarned = false;
|
|
6
6
|
/** @deprecated Switch to `useFormatter` instead. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-intl.esm7.js","sources":["../../src/react/
|
|
1
|
+
{"version":3,"file":"use-intl.esm7.js","sources":["../../src/react/useIntl.tsx"],"sourcesContent":["import {useMemo} from 'react';\nimport createIntl from '../core/createIntl';\nimport useIntlContext from './useIntlContext';\n\nlet hasWarned = false;\n\n/** @deprecated Switch to `useFormatter` instead. */\nexport default function useIntl() {\n const {formats, locale, now: globalNow, onError, timeZone} = useIntlContext();\n\n if (!hasWarned) {\n hasWarned = true;\n console.warn(\n '`useIntl()` is deprecated and will be removed in the next major version. Please switch to `useFormatter()`.'\n );\n }\n\n return useMemo(\n () =>\n createIntl({\n formats,\n locale,\n now: globalNow,\n onError,\n timeZone\n }),\n [formats, globalNow, locale, onError, timeZone]\n );\n}\n"],"names":["hasWarned","useIntl","_useIntlContext","useIntlContext","formats","locale","globalNow","now","onError","timeZone","console","warn","useMemo","createIntl"],"mappings":";;;;AAIA,IAAIA,SAAS,GAAG,KAAK,CAAA;AAErB;AACc,SAAUC,OAAOA,GAAA;AAC7B,EAAA,IAAAC,eAAA,GAA6DC,cAAc,EAAE;IAAtEC,OAAO,GAAAF,eAAA,CAAPE,OAAO;IAAEC,MAAM,GAAAH,eAAA,CAANG,MAAM;IAAOC,SAAS,GAAAJ,eAAA,CAAdK,GAAG;IAAaC,OAAO,GAAAN,eAAA,CAAPM,OAAO;IAAEC,QAAQ,GAAAP,eAAA,CAARO,QAAQ,CAAA;EAEzD,IAAI,CAACT,SAAS,EAAE;AACdA,IAAAA,SAAS,GAAG,IAAI,CAAA;AAChBU,IAAAA,OAAO,CAACC,IAAI,CACV,6GAA6G,CAC9G,CAAA;AACF,GAAA;AAED,EAAA,OAAOC,OAAO,CACZ,YAAA;AAAA,IAAA,OACEC,UAAU,CAAC;AACTT,MAAAA,OAAO,EAAPA,OAAO;AACPC,MAAAA,MAAM,EAANA,MAAM;AACNE,MAAAA,GAAG,EAAED,SAAS;AACdE,MAAAA,OAAO,EAAPA,OAAO;AACPC,MAAAA,QAAQ,EAARA,QAAAA;AACD,KAAA,CAAC,CAAA;GACJ,EAAA,CAACL,OAAO,EAAEE,SAAS,EAAED,MAAM,EAAEG,OAAO,EAAEC,QAAQ,CAAC,CAChD,CAAA;AACH;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-intl.esm8.js","sources":["../../src/react/
|
|
1
|
+
{"version":3,"file":"use-intl.esm8.js","sources":["../../src/react/IntlContext.tsx"],"sourcesContent":["import {createContext} from 'react';\nimport {InitializedIntlConfig} from '../core/IntlConfig';\n\nconst IntlContext = createContext<InitializedIntlConfig | undefined>(undefined);\n\nexport default IntlContext;\n"],"names":["IntlContext","createContext","undefined"],"mappings":";;AAGA,IAAMA,WAAW,gBAAGC,aAAa,CAAoCC,SAAS;;;;"}
|
|
@@ -1,29 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import validateMessages from '../core/use-intl.esm9.js';
|
|
1
|
+
import { useContext } from 'react';
|
|
2
|
+
import IntlContext from './use-intl.esm8.js';
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
function getInitializedConfig(_ref) {
|
|
10
|
-
var getMessageFallback = _ref.getMessageFallback,
|
|
11
|
-
messages = _ref.messages,
|
|
12
|
-
onError = _ref.onError,
|
|
13
|
-
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
14
|
-
var finalOnError = onError || defaultOnError;
|
|
15
|
-
var finalGetMessageFallback = getMessageFallback || defaultGetMessageFallback;
|
|
16
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
17
|
-
if (messages) {
|
|
18
|
-
validateMessages(messages, finalOnError);
|
|
19
|
-
}
|
|
4
|
+
function useIntlContext() {
|
|
5
|
+
var context = useContext(IntlContext);
|
|
6
|
+
if (!context) {
|
|
7
|
+
throw new Error(process.env.NODE_ENV !== 'production' ? 'No intl context found. Have you configured the provider?' : undefined);
|
|
20
8
|
}
|
|
21
|
-
return
|
|
22
|
-
messages: messages,
|
|
23
|
-
onError: finalOnError,
|
|
24
|
-
getMessageFallback: finalGetMessageFallback
|
|
25
|
-
});
|
|
9
|
+
return context;
|
|
26
10
|
}
|
|
27
11
|
|
|
28
|
-
export {
|
|
12
|
+
export { useIntlContext as default };
|
|
29
13
|
//# sourceMappingURL=use-intl.esm9.js.map
|
package/dist/use-intl.esm.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
export { default as IntlError, IntlErrorCode } from './core/use-intl.
|
|
2
|
-
export { default as createTranslator } from './core/use-intl.
|
|
3
|
-
export { default as createFormatter } from './core/use-intl.
|
|
4
|
-
export { default as createIntl } from './core/use-intl.
|
|
1
|
+
export { default as IntlError, IntlErrorCode } from './core/use-intl.esm4.js';
|
|
2
|
+
export { default as createTranslator } from './core/use-intl.esm.js';
|
|
3
|
+
export { default as createFormatter } from './core/use-intl.esm2.js';
|
|
4
|
+
export { default as createIntl } from './core/use-intl.esm3.js';
|
|
5
5
|
export { default as IntlProvider } from './react/use-intl.esm.js';
|
|
6
|
-
export { default as useTranslations } from './react/use-intl.
|
|
6
|
+
export { default as useTranslations } from './react/use-intl.esm4.js';
|
|
7
7
|
export { default as useLocale } from './react/use-intl.esm3.js';
|
|
8
|
-
export { default as useNow } from './react/use-intl.
|
|
9
|
-
export { default as useTimeZone } from './react/use-intl.
|
|
10
|
-
export { default as useFormatter } from './react/use-intl.
|
|
8
|
+
export { default as useNow } from './react/use-intl.esm5.js';
|
|
9
|
+
export { default as useTimeZone } from './react/use-intl.esm6.js';
|
|
10
|
+
export { default as useFormatter } from './react/use-intl.esm2.js';
|
|
11
11
|
export { default as useIntl } from './react/use-intl.esm7.js';
|
|
12
12
|
//# sourceMappingURL=use-intl.esm.js.map
|