use-intl 2.19.3 → 2.20.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/MessageFormatCache.d.ts +5 -0
- package/dist/core/createBaseTranslator.d.ts +3 -3
- package/dist/core/use-intl.esm10.js.map +1 -1
- 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.esm5.js.map +1 -1
- package/dist/core/use-intl.esm6.js +12 -50
- package/dist/core/use-intl.esm6.js.map +1 -1
- package/dist/core/use-intl.esm7.js +22 -13
- package/dist/core/use-intl.esm7.js.map +1 -1
- package/dist/react/IntlContext.d.ts +11 -2
- package/dist/react/use-intl.esm.js +9 -3
- package/dist/react/use-intl.esm.js.map +1 -1
- package/dist/react/use-intl.esm10.js +1 -1
- package/dist/react/use-intl.esm12.js +4 -4
- package/dist/react/use-intl.esm12.js.map +1 -1
- package/dist/react/use-intl.esm9.js.map +1 -1
- package/dist/react/useIntlContext.d.ts +10 -1
- package/dist/src/core/MessageFormatCache.d.ts +5 -0
- package/dist/src/core/MessageFormatCache.js +2 -0
- package/dist/src/core/MessageFormatCache.js.map +1 -0
- package/dist/src/core/convertFormatsToIntlMessageFormat.js +1 -0
- package/dist/src/core/convertFormatsToIntlMessageFormat.js.map +1 -1
- package/dist/src/core/createBaseTranslator.d.ts +3 -3
- package/dist/src/core/createBaseTranslator.js +22 -10
- package/dist/src/core/createBaseTranslator.js.map +1 -1
- package/dist/src/react/IntlContext.d.ts +11 -2
- package/dist/src/react/IntlContext.js.map +1 -1
- package/dist/src/react/IntlProvider.js +6 -2
- package/dist/src/react/IntlProvider.js.map +1 -1
- package/dist/src/react/useIntlContext.d.ts +10 -1
- package/dist/src/react/useTranslationsImpl.js +4 -4
- package/dist/src/react/useTranslationsImpl.js.map +1 -1
- package/dist/use-intl.cjs.development.js +31 -16
- package/dist/use-intl.cjs.development.js.map +1 -1
- package/dist/use-intl.cjs.production.min.js +1 -1
- package/dist/use-intl.cjs.production.min.js.map +1 -1
- package/package.json +2 -2
- package/src/core/MessageFormatCache.tsx +10 -0
- package/src/core/convertFormatsToIntlMessageFormat.tsx +1 -0
- package/src/core/createBaseTranslator.tsx +29 -12
- package/src/react/IntlContext.tsx +7 -1
- package/src/react/IntlProvider.tsx +9 -2
- package/src/react/useTranslationsImpl.tsx +4 -8
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import IntlMessageFormat from 'intl-messageformat';
|
|
2
1
|
import { ReactElement, ReactNodeArray } from 'react';
|
|
3
2
|
import AbstractIntlMessages from './AbstractIntlMessages';
|
|
4
3
|
import Formats from './Formats';
|
|
5
4
|
import { InitializedIntlConfig } from './IntlConfig';
|
|
6
5
|
import IntlError from './IntlError';
|
|
6
|
+
import MessageFormatCache from './MessageFormatCache';
|
|
7
7
|
import TranslationValues, { RichTranslationValues } from './TranslationValues';
|
|
8
8
|
import MessageKeys from './utils/MessageKeys';
|
|
9
9
|
import NestedKeyOf from './utils/NestedKeyOf';
|
|
@@ -14,12 +14,12 @@ export declare function getMessagesOrError<Messages extends AbstractIntlMessages
|
|
|
14
14
|
onError?(error: IntlError): void;
|
|
15
15
|
}): AbstractIntlMessages | IntlError;
|
|
16
16
|
export type CreateBaseTranslatorProps<Messages> = InitializedIntlConfig & {
|
|
17
|
-
|
|
17
|
+
messageFormatCache?: MessageFormatCache;
|
|
18
18
|
defaultTranslationValues?: RichTranslationValues;
|
|
19
19
|
namespace?: string;
|
|
20
20
|
messagesOrError: Messages | IntlError;
|
|
21
21
|
};
|
|
22
|
-
export default function createBaseTranslator<Messages extends AbstractIntlMessages, NestedKey extends NestedKeyOf<Messages>>({
|
|
22
|
+
export default function createBaseTranslator<Messages extends AbstractIntlMessages, NestedKey extends NestedKeyOf<Messages>>({ defaultTranslationValues, formats: globalFormats, getMessageFallback, locale, messageFormatCache, messagesOrError, namespace, onError, timeZone }: CreateBaseTranslatorProps<Messages>): {
|
|
23
23
|
<TargetKey extends MessageKeys<NestedValueOf<Messages, NestedKey>, NestedKeyOf<NestedValueOf<Messages, NestedKey>>>>(key: TargetKey, values?: TranslationValues, formats?: Partial<Formats>): string;
|
|
24
24
|
rich: (key: string, values?: RichTranslationValues, formats?: Partial<Formats>) => string | ReactElement | ReactNodeArray;
|
|
25
25
|
raw(key: string): any;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-intl.esm10.js","sources":["../../src/core/convertFormatsToIntlMessageFormat.tsx"],"sourcesContent":["import IntlMessageFormat, {Formats as IntlFormats} from 'intl-messageformat';\nimport DateTimeFormatOptions from './DateTimeFormatOptions';\nimport Formats from './Formats';\nimport TimeZone from './TimeZone';\n\nfunction setTimeZoneInFormats(\n formats: Record<string, DateTimeFormatOptions> | undefined,\n timeZone: TimeZone\n) {\n if (!formats) return formats;\n\n // The only way to set a time zone with `intl-messageformat` is to merge it into the formats\n // https://github.com/formatjs/formatjs/blob/8256c5271505cf2606e48e3c97ecdd16ede4f1b5/packages/intl/src/message.ts#L15\n return Object.keys(formats).reduce(\n (acc: Record<string, DateTimeFormatOptions>, key) => {\n acc[key] = {\n timeZone,\n ...formats[key]\n };\n return acc;\n },\n {}\n );\n}\n\n/**\n * `intl-messageformat` uses separate keys for `date` and `time`, but there's\n * only one native API: `Intl.DateTimeFormat`. Additionally you might want to\n * include both a time and a date in a value, therefore the separation doesn't\n * seem so useful. We offer a single `dateTime` namespace instead, but we have\n * to convert the format before `intl-messageformat` can be used.\n */\nexport default function convertFormatsToIntlMessageFormat(\n formats: Partial<Formats>,\n timeZone?: TimeZone\n): Partial<IntlFormats> {\n const formatsWithTimeZone = timeZone\n ? {...formats, dateTime: setTimeZoneInFormats(formats.dateTime, timeZone)}\n : formats;\n\n const mfDateDefaults = IntlMessageFormat.formats.date as Formats['dateTime'];\n const defaultDateFormats = timeZone\n ? setTimeZoneInFormats(mfDateDefaults, timeZone)\n : mfDateDefaults;\n\n const mfTimeDefaults = IntlMessageFormat.formats.time as Formats['dateTime'];\n const defaultTimeFormats = timeZone\n ? setTimeZoneInFormats(mfTimeDefaults, timeZone)\n : mfTimeDefaults;\n\n return {\n ...formatsWithTimeZone,\n date: {\n ...defaultDateFormats,\n ...formatsWithTimeZone?.dateTime\n },\n time: {\n ...defaultTimeFormats,\n ...formatsWithTimeZone?.dateTime\n }\n };\n}\n"],"names":["setTimeZoneInFormats","formats","timeZone","Object","keys","reduce","acc","key","_extends","convertFormatsToIntlMessageFormat","formatsWithTimeZone","dateTime","mfDateDefaults","IntlMessageFormat","date","defaultDateFormats","mfTimeDefaults","time","defaultTimeFormats"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"use-intl.esm10.js","sources":["../../src/core/convertFormatsToIntlMessageFormat.tsx"],"sourcesContent":["// eslint-disable-next-line import/no-named-as-default -- False positive\nimport IntlMessageFormat, {Formats as IntlFormats} from 'intl-messageformat';\nimport DateTimeFormatOptions from './DateTimeFormatOptions';\nimport Formats from './Formats';\nimport TimeZone from './TimeZone';\n\nfunction setTimeZoneInFormats(\n formats: Record<string, DateTimeFormatOptions> | undefined,\n timeZone: TimeZone\n) {\n if (!formats) return formats;\n\n // The only way to set a time zone with `intl-messageformat` is to merge it into the formats\n // https://github.com/formatjs/formatjs/blob/8256c5271505cf2606e48e3c97ecdd16ede4f1b5/packages/intl/src/message.ts#L15\n return Object.keys(formats).reduce(\n (acc: Record<string, DateTimeFormatOptions>, key) => {\n acc[key] = {\n timeZone,\n ...formats[key]\n };\n return acc;\n },\n {}\n );\n}\n\n/**\n * `intl-messageformat` uses separate keys for `date` and `time`, but there's\n * only one native API: `Intl.DateTimeFormat`. Additionally you might want to\n * include both a time and a date in a value, therefore the separation doesn't\n * seem so useful. We offer a single `dateTime` namespace instead, but we have\n * to convert the format before `intl-messageformat` can be used.\n */\nexport default function convertFormatsToIntlMessageFormat(\n formats: Partial<Formats>,\n timeZone?: TimeZone\n): Partial<IntlFormats> {\n const formatsWithTimeZone = timeZone\n ? {...formats, dateTime: setTimeZoneInFormats(formats.dateTime, timeZone)}\n : formats;\n\n const mfDateDefaults = IntlMessageFormat.formats.date as Formats['dateTime'];\n const defaultDateFormats = timeZone\n ? setTimeZoneInFormats(mfDateDefaults, timeZone)\n : mfDateDefaults;\n\n const mfTimeDefaults = IntlMessageFormat.formats.time as Formats['dateTime'];\n const defaultTimeFormats = timeZone\n ? setTimeZoneInFormats(mfTimeDefaults, timeZone)\n : mfTimeDefaults;\n\n return {\n ...formatsWithTimeZone,\n date: {\n ...defaultDateFormats,\n ...formatsWithTimeZone?.dateTime\n },\n time: {\n ...defaultTimeFormats,\n ...formatsWithTimeZone?.dateTime\n }\n };\n}\n"],"names":["setTimeZoneInFormats","formats","timeZone","Object","keys","reduce","acc","key","_extends","convertFormatsToIntlMessageFormat","formatsWithTimeZone","dateTime","mfDateDefaults","IntlMessageFormat","date","defaultDateFormats","mfTimeDefaults","time","defaultTimeFormats"],"mappings":";;;AAMA,SAASA,oBAAoBA,CAC3BC,OAA0D,EAC1DC,QAAkB,EAAA;AAElB,EAAA,IAAI,CAACD,OAAO,EAAE,OAAOA,OAAO,CAAA;AAE5B;AACA;AACA,EAAA,OAAOE,MAAM,CAACC,IAAI,CAACH,OAAO,CAAC,CAACI,MAAM,CAChC,UAACC,GAA0C,EAAEC,GAAG,EAAI;AAClDD,IAAAA,GAAG,CAACC,GAAG,CAAC,GAAAC,QAAA,CAAA;AACNN,MAAAA,QAAQ,EAARA,QAAAA;AAAQ,KAAA,EACLD,OAAO,CAACM,GAAG,CAAC,CAChB,CAAA;AACD,IAAA,OAAOD,GAAG,CAAA;GACX,EACD,EAAE,CACH,CAAA;AACH,CAAA;AAEA;;;;;;AAMG;AACW,SAAUG,iCAAiCA,CACvDR,OAAyB,EACzBC,QAAmB,EAAA;AAEnB,EAAA,IAAMQ,mBAAmB,GAAGR,QAAQ,GAAAM,QAAA,KAC5BP,OAAO,EAAA;AAAEU,IAAAA,QAAQ,EAAEX,oBAAoB,CAACC,OAAO,CAACU,QAAQ,EAAET,QAAQ,CAAA;AAAC,GAAA,CAAA,GACvED,OAAO,CAAA;AAEX,EAAA,IAAMW,cAAc,GAAGC,iBAAiB,CAACZ,OAAO,CAACa,IAA2B,CAAA;EAC5E,IAAMC,kBAAkB,GAAGb,QAAQ,GAC/BF,oBAAoB,CAACY,cAAc,EAAEV,QAAQ,CAAC,GAC9CU,cAAc,CAAA;AAElB,EAAA,IAAMI,cAAc,GAAGH,iBAAiB,CAACZ,OAAO,CAACgB,IAA2B,CAAA;EAC5E,IAAMC,kBAAkB,GAAGhB,QAAQ,GAC/BF,oBAAoB,CAACgB,cAAc,EAAEd,QAAQ,CAAC,GAC9Cc,cAAc,CAAA;EAElB,OAAAR,QAAA,KACKE,mBAAmB,EAAA;IACtBI,IAAI,EAAAN,QAAA,CAAA,EAAA,EACCO,kBAAkB,EAClBL,mBAAmB,IAAnBA,IAAAA,GAAAA,KAAAA,CAAAA,GAAAA,mBAAmB,CAAEC,QAAQ,CACjC;IACDM,IAAI,EAAAT,QAAA,CACCU,EAAAA,EAAAA,kBAAkB,EAClBR,mBAAmB,IAAA,IAAA,GAAA,KAAA,CAAA,GAAnBA,mBAAmB,CAAEC,QAAQ,CAAA;AACjC,GAAA,CAAA,CAAA;AAEL;;;;"}
|
|
@@ -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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-intl.esm5.js","sources":["../../src/core/
|
|
1
|
+
{"version":3,"file":"use-intl.esm5.js","sources":["../../src/core/createTranslatorImpl.tsx"],"sourcesContent":["import AbstractIntlMessages from './AbstractIntlMessages';\nimport {InitializedIntlConfig} from './IntlConfig';\nimport IntlError, {IntlErrorCode} from './IntlError';\nimport {RichTranslationValues, TranslationValue} from './TranslationValues';\nimport createBaseTranslator, {getMessagesOrError} from './createBaseTranslator';\nimport resolveNamespace from './resolveNamespace';\nimport NestedKeyOf from './utils/NestedKeyOf';\n\nexport type CoreRichTranslationValues = Record<\n string,\n TranslationValue | ((chunks: string) => string)\n>;\n\nexport type CreateTranslatorImplProps<Messages> = Omit<\n InitializedIntlConfig,\n 'messages'\n> & {\n namespace: string;\n messages: Messages;\n};\n\nexport default function createTranslatorImpl<\n Messages extends AbstractIntlMessages,\n NestedKey extends NestedKeyOf<Messages>\n>(\n {\n getMessageFallback,\n messages,\n namespace,\n onError,\n ...rest\n }: CreateTranslatorImplProps<Messages>,\n namespacePrefix: string\n) {\n // The `namespacePrefix` is part of the type system.\n // See the comment in the function invocation.\n messages = messages[namespacePrefix] as Messages;\n namespace = resolveNamespace(namespace, namespacePrefix) as NestedKey;\n\n const translator = createBaseTranslator<Messages, NestedKey>({\n ...rest,\n onError,\n getMessageFallback,\n messagesOrError: getMessagesOrError({\n messages,\n namespace,\n onError\n }) as Messages | IntlError\n });\n\n const originalRich = translator.rich;\n\n function base(...args: Parameters<typeof translator>) {\n return translator(...args);\n }\n\n // Augment `t.rich` to return plain strings\n base.rich = (\n key: Parameters<typeof originalRich>[0],\n /** Key value pairs for values to interpolate into the message. */\n values: CoreRichTranslationValues,\n formats?: Parameters<typeof originalRich>[2]\n ): string => {\n // `chunks` is returned as a string when no React element\n // is used, therefore it's safe to cast this type.\n const result = originalRich(key, values as RichTranslationValues, formats);\n\n // When only string chunks are provided to the parser, only strings should be returned here.\n if (typeof result !== 'string') {\n const error = new IntlError(\n IntlErrorCode.FORMATTING_ERROR,\n process.env.NODE_ENV !== 'production'\n ? \"`createTranslator` only accepts functions for rich text formatting that receive and return strings.\\n\\nE.g. t.rich('rich', {b: (chunks) => `<b>${chunks}</b>`})\"\n : undefined\n );\n\n onError(error);\n return getMessageFallback({error, key, namespace});\n }\n\n return result;\n };\n\n base.raw = translator.raw;\n\n return base;\n}\n"],"names":["createTranslatorImpl","_ref","namespacePrefix","getMessageFallback","messages","namespace","onError","rest","_objectWithoutPropertiesLoose","_excluded","resolveNamespace","translator","createBaseTranslator","_extends","messagesOrError","getMessagesOrError","originalRich","rich","base","apply","arguments","key","values","formats","result","error","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,OAAOC,MAAM,KAAK,QAAQ,EAAE;MAC9B,IAAMC,KAAK,GAAG,IAAIC,SAAS,CACzBC,aAAa,CAACC,gBAAgB,EAC9BC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,GACjC,iKAAiK,GACjKC,SAAS,CACd,CAAA;MAED1B,OAAO,CAACmB,KAAK,CAAC,CAAA;AACd,MAAA,OAAOtB,kBAAkB,CAAC;AAACsB,QAAAA,KAAK,EAALA,KAAK;AAAEJ,QAAAA,GAAG,EAAHA,GAAG;AAAEhB,QAAAA,SAAS,EAATA,SAAAA;AAAU,OAAA,CAAC,CAAA;AACnD,KAAA;AAED,IAAA,OAAOmB,MAAM,CAAA;GACd,CAAA;AAEDN,EAAAA,IAAI,CAACe,GAAG,GAAGtB,UAAU,CAACsB,GAAG,CAAA;AAEzB,EAAA,OAAOf,IAAI,CAAA;AACb;;;;"}
|
|
@@ -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
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-intl.esm6.js","sources":["../../src/core/
|
|
1
|
+
{"version":3,"file":"use-intl.esm6.js","sources":["../../src/core/defaults.tsx"],"sourcesContent":["import IntlError from './IntlError';\n\n/**\n * Contains defaults that are used for all entry points into the core.\n * See also `InitializedIntlConfiguration`.\n */\n\nexport function defaultGetMessageFallback(props: {\n error: IntlError;\n key: string;\n namespace?: string;\n}) {\n return [props.namespace, props.key].filter((part) => part != null).join('.');\n}\n\nexport function defaultOnError(error: IntlError) {\n console.error(error);\n}\n"],"names":["defaultGetMessageFallback","props","namespace","key","filter","part","join","defaultOnError","error","console"],"mappings":"AAEA;;;AAGG;AAEG,SAAUA,yBAAyBA,CAACC,KAIzC,EAAA;AACC,EAAA,OAAO,CAACA,KAAK,CAACC,SAAS,EAAED,KAAK,CAACE,GAAG,CAAC,CAACC,MAAM,CAAC,UAACC,IAAI,EAAA;IAAA,OAAKA,IAAI,IAAI,IAAI,CAAA;AAAA,GAAA,CAAC,CAACC,IAAI,CAAC,GAAG,CAAC,CAAA;AAC9E,CAAA;AAEM,SAAUC,cAAcA,CAACC,KAAgB,EAAA;AAC7CC,EAAAA,OAAO,CAACD,KAAK,CAACA,KAAK,CAAC,CAAA;AACtB;;;;"}
|
|
@@ -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) {
|
|
@@ -61,13 +61,25 @@ function getMessagesOrError(_ref) {
|
|
|
61
61
|
return intlError;
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
|
+
function getPlainMessage(candidate, values) {
|
|
65
|
+
if (values) return undefined;
|
|
66
|
+
var unescapedMessage = candidate.replace(/'([{}])/gi, '$1');
|
|
67
|
+
// Placeholders can be in the message if there are default values,
|
|
68
|
+
// or if the user has forgotten to provide values. In the latter
|
|
69
|
+
// case we need to compile the message to receive an error.
|
|
70
|
+
var hasPlaceholders = /<|{/.test(unescapedMessage);
|
|
71
|
+
if (!hasPlaceholders) {
|
|
72
|
+
return unescapedMessage;
|
|
73
|
+
}
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
64
76
|
function createBaseTranslator(_ref2) {
|
|
65
|
-
var
|
|
66
|
-
defaultTranslationValues = _ref2.defaultTranslationValues,
|
|
77
|
+
var defaultTranslationValues = _ref2.defaultTranslationValues,
|
|
67
78
|
globalFormats = _ref2.formats,
|
|
68
79
|
_ref2$getMessageFallb = _ref2.getMessageFallback,
|
|
69
80
|
getMessageFallback = _ref2$getMessageFallb === void 0 ? defaultGetMessageFallback : _ref2$getMessageFallb,
|
|
70
81
|
locale = _ref2.locale,
|
|
82
|
+
messageFormatCache = _ref2.messageFormatCache,
|
|
71
83
|
messagesOrError = _ref2.messagesOrError,
|
|
72
84
|
namespace = _ref2.namespace,
|
|
73
85
|
onError = _ref2.onError,
|
|
@@ -85,7 +97,6 @@ function createBaseTranslator(_ref2) {
|
|
|
85
97
|
key, /** Key value pairs for values to interpolate into the message. */
|
|
86
98
|
values, /** Provide custom formats for numbers, dates and times. */
|
|
87
99
|
formats) {
|
|
88
|
-
var _cachedFormatsByLocal;
|
|
89
100
|
if (messagesOrError instanceof IntlError) {
|
|
90
101
|
// We have already warned about this during render
|
|
91
102
|
return getMessageFallback({
|
|
@@ -106,10 +117,10 @@ function createBaseTranslator(_ref2) {
|
|
|
106
117
|
return part != null;
|
|
107
118
|
}).join('.');
|
|
108
119
|
}
|
|
109
|
-
var cacheKey = joinPath([namespace, key, String(message)]);
|
|
120
|
+
var cacheKey = joinPath([locale, namespace, key, String(message)]);
|
|
110
121
|
var messageFormat;
|
|
111
|
-
if (
|
|
112
|
-
messageFormat =
|
|
122
|
+
if (messageFormatCache != null && messageFormatCache.has(cacheKey)) {
|
|
123
|
+
messageFormat = messageFormatCache.get(cacheKey);
|
|
113
124
|
} else {
|
|
114
125
|
if (typeof message === 'object') {
|
|
115
126
|
var code, errorMessage;
|
|
@@ -126,17 +137,15 @@ function createBaseTranslator(_ref2) {
|
|
|
126
137
|
}
|
|
127
138
|
return getFallbackFromErrorAndNotify(key, code, errorMessage);
|
|
128
139
|
}
|
|
140
|
+
// Hot path that avoids creating an `IntlMessageFormat` instance
|
|
141
|
+
var plainMessage = getPlainMessage(message, values);
|
|
142
|
+
if (plainMessage) return plainMessage;
|
|
129
143
|
try {
|
|
130
144
|
messageFormat = new IntlMessageFormat(message, locale, convertFormatsToIntlMessageFormat(_extends({}, globalFormats, formats), timeZone));
|
|
131
145
|
} catch (error) {
|
|
132
146
|
return getFallbackFromErrorAndNotify(key, IntlErrorCode.INVALID_MESSAGE, error.message);
|
|
133
147
|
}
|
|
134
|
-
|
|
135
|
-
if (!cachedFormatsByLocale[locale]) {
|
|
136
|
-
cachedFormatsByLocale[locale] = {};
|
|
137
|
-
}
|
|
138
|
-
cachedFormatsByLocale[locale][cacheKey] = messageFormat;
|
|
139
|
-
}
|
|
148
|
+
messageFormatCache == null ? void 0 : messageFormatCache.set(cacheKey, messageFormat);
|
|
140
149
|
}
|
|
141
150
|
try {
|
|
142
151
|
var formattedMessage = messageFormat.format(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-intl.esm7.js","sources":["../../src/core/createBaseTranslator.tsx"],"sourcesContent":["// eslint-disable-next-line import/no-named-as-default -- False positive\nimport IntlMessageFormat from 'intl-messageformat';\nimport {\n cloneElement,\n isValidElement,\n ReactElement,\n ReactNode,\n ReactNodeArray\n} from 'react';\nimport AbstractIntlMessages from './AbstractIntlMessages';\nimport Formats from './Formats';\nimport {InitializedIntlConfig} from './IntlConfig';\nimport IntlError, {IntlErrorCode} from './IntlError';\nimport TranslationValues, {RichTranslationValues} from './TranslationValues';\nimport convertFormatsToIntlMessageFormat from './convertFormatsToIntlMessageFormat';\nimport {defaultGetMessageFallback, defaultOnError} from './defaults';\nimport MessageKeys from './utils/MessageKeys';\nimport NestedKeyOf from './utils/NestedKeyOf';\nimport NestedValueOf from './utils/NestedValueOf';\n\nfunction resolvePath(\n messages: AbstractIntlMessages | undefined,\n key: string,\n namespace?: string\n) {\n if (!messages) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? `No messages available at \\`${namespace}\\`.`\n : undefined\n );\n }\n\n let message = messages;\n\n key.split('.').forEach((part) => {\n const next = (message as any)[part];\n\n if (part == null || next == null) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? `Could not resolve \\`${key}\\` in ${\n namespace ? `\\`${namespace}\\`` : 'messages'\n }.`\n : undefined\n );\n }\n\n message = next;\n });\n\n return message;\n}\n\nfunction prepareTranslationValues(values: RichTranslationValues) {\n if (Object.keys(values).length === 0) return undefined;\n\n // Workaround for https://github.com/formatjs/formatjs/issues/1467\n const transformedValues: RichTranslationValues = {};\n Object.keys(values).forEach((key) => {\n let index = 0;\n const value = values[key];\n\n let transformed;\n if (typeof value === 'function') {\n transformed = (chunks: ReactNode) => {\n const result = value(chunks);\n\n return isValidElement(result)\n ? cloneElement(result, {key: key + index++})\n : result;\n };\n } else {\n transformed = value;\n }\n\n transformedValues[key] = transformed;\n });\n\n return transformedValues;\n}\n\nexport function getMessagesOrError<Messages extends AbstractIntlMessages>({\n messages,\n namespace,\n onError = defaultOnError\n}: {\n messages: Messages;\n namespace?: string;\n onError?(error: IntlError): void;\n}) {\n try {\n if (!messages) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? `No messages were configured on the provider.`\n : undefined\n );\n }\n\n const retrievedMessages = namespace\n ? resolvePath(messages, namespace)\n : messages;\n\n if (!retrievedMessages) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? `No messages for namespace \\`${namespace}\\` found.`\n : undefined\n );\n }\n\n return retrievedMessages;\n } catch (error) {\n const intlError = new IntlError(\n IntlErrorCode.MISSING_MESSAGE,\n (error as Error).message\n );\n onError(intlError);\n return intlError;\n }\n}\n\nexport type CreateBaseTranslatorProps<Messages> = InitializedIntlConfig & {\n cachedFormatsByLocale?: Record<string, Record<string, IntlMessageFormat>>;\n defaultTranslationValues?: RichTranslationValues;\n namespace?: string;\n messagesOrError: Messages | IntlError;\n};\n\nexport default function createBaseTranslator<\n Messages extends AbstractIntlMessages,\n NestedKey extends NestedKeyOf<Messages>\n>({\n cachedFormatsByLocale,\n defaultTranslationValues,\n formats: globalFormats,\n getMessageFallback = defaultGetMessageFallback,\n locale,\n messagesOrError,\n namespace,\n onError,\n timeZone\n}: CreateBaseTranslatorProps<Messages>) {\n function getFallbackFromErrorAndNotify(\n key: string,\n code: IntlErrorCode,\n message?: string\n ) {\n const error = new IntlError(code, message);\n onError(error);\n return getMessageFallback({error, key, namespace});\n }\n\n function translateBaseFn(\n /** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */\n key: string,\n /** Key value pairs for values to interpolate into the message. */\n values?: RichTranslationValues,\n /** Provide custom formats for numbers, dates and times. */\n formats?: Partial<Formats>\n ): string | ReactElement | ReactNodeArray {\n if (messagesOrError instanceof IntlError) {\n // We have already warned about this during render\n return getMessageFallback({\n error: messagesOrError,\n key,\n namespace\n });\n }\n const messages = messagesOrError;\n\n let message;\n try {\n message = resolvePath(messages, key, namespace);\n } catch (error) {\n return getFallbackFromErrorAndNotify(\n key,\n IntlErrorCode.MISSING_MESSAGE,\n (error as Error).message\n );\n }\n\n function joinPath(parts: Array<string | undefined>) {\n return parts.filter((part) => part != null).join('.');\n }\n\n const cacheKey = joinPath([namespace, key, String(message)]);\n\n let messageFormat;\n if (cachedFormatsByLocale?.[locale]?.[cacheKey]) {\n messageFormat = cachedFormatsByLocale?.[locale][cacheKey];\n } else {\n if (typeof message === 'object') {\n let code, errorMessage;\n if (Array.isArray(message)) {\n code = IntlErrorCode.INVALID_MESSAGE;\n if (process.env.NODE_ENV !== 'production') {\n errorMessage = `Message at \\`${joinPath([\n namespace,\n key\n ])}\\` resolved to an array, but only strings are supported. See https://next-intl-docs.vercel.app/docs/usage/messages#arrays-of-messages`;\n }\n } else {\n code = IntlErrorCode.INSUFFICIENT_PATH;\n if (process.env.NODE_ENV !== 'production') {\n errorMessage = `Message at \\`${joinPath([\n namespace,\n key\n ])}\\` resolved to an object, but only strings are supported. Use a \\`.\\` to retrieve nested messages. See https://next-intl-docs.vercel.app/docs/usage/messages#structuring-messages`;\n }\n }\n\n return getFallbackFromErrorAndNotify(key, code, errorMessage);\n }\n\n try {\n messageFormat = new IntlMessageFormat(\n message,\n locale,\n convertFormatsToIntlMessageFormat(\n {...globalFormats, ...formats},\n timeZone\n )\n );\n } catch (error) {\n return getFallbackFromErrorAndNotify(\n key,\n IntlErrorCode.INVALID_MESSAGE,\n (error as Error).message\n );\n }\n\n if (cachedFormatsByLocale) {\n if (!cachedFormatsByLocale[locale]) {\n cachedFormatsByLocale[locale] = {};\n }\n cachedFormatsByLocale[locale][cacheKey] = messageFormat;\n }\n }\n\n try {\n const formattedMessage = messageFormat.format(\n // @ts-ignore `intl-messageformat` expects a different format\n // for rich text elements since a recent minor update. This\n // needs to be evaluated in detail, possibly also in regards\n // to be able to format to parts.\n prepareTranslationValues({...defaultTranslationValues, ...values})\n );\n\n if (formattedMessage == null) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? `Unable to format \\`${key}\\` in ${\n namespace ? `namespace \\`${namespace}\\`` : 'messages'\n }`\n : undefined\n );\n }\n\n // Limit the function signature to return strings or React elements\n return isValidElement(formattedMessage) ||\n // Arrays of React elements\n Array.isArray(formattedMessage) ||\n typeof formattedMessage === 'string'\n ? formattedMessage\n : String(formattedMessage);\n } catch (error) {\n return getFallbackFromErrorAndNotify(\n key,\n IntlErrorCode.FORMATTING_ERROR,\n (error as Error).message\n );\n }\n }\n\n function translateFn<\n TargetKey extends MessageKeys<\n NestedValueOf<Messages, NestedKey>,\n NestedKeyOf<NestedValueOf<Messages, NestedKey>>\n >\n >(\n /** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */\n key: TargetKey,\n /** Key value pairs for values to interpolate into the message. */\n values?: TranslationValues,\n /** Provide custom formats for numbers, dates and times. */\n formats?: Partial<Formats>\n ): string {\n const result = translateBaseFn(key, values, formats);\n\n if (typeof result !== 'string') {\n return getFallbackFromErrorAndNotify(\n key,\n IntlErrorCode.INVALID_MESSAGE,\n process.env.NODE_ENV !== 'production'\n ? `The message \\`${key}\\` in ${\n namespace ? `namespace \\`${namespace}\\`` : 'messages'\n } didn't resolve to a string. If you want to format rich text, use \\`t.rich\\` instead.`\n : undefined\n );\n }\n\n return result;\n }\n\n translateFn.rich = translateBaseFn;\n\n translateFn.raw = (\n /** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */\n key: string\n ): any => {\n if (messagesOrError instanceof IntlError) {\n // We have already warned about this during render\n return getMessageFallback({\n error: messagesOrError,\n key,\n namespace\n });\n }\n const messages = messagesOrError;\n\n try {\n return resolvePath(messages, key, namespace);\n } catch (error) {\n return getFallbackFromErrorAndNotify(\n key,\n IntlErrorCode.MISSING_MESSAGE,\n (error as Error).message\n );\n }\n };\n\n return translateFn;\n}\n"],"names":["resolvePath","messages","key","namespace","Error","process","env","NODE_ENV","undefined","message","split","forEach","part","next","prepareTranslationValues","values","Object","keys","length","transformedValues","index","value","transformed","chunks","result","isValidElement","cloneElement","getMessagesOrError","_ref","_ref$onError","onError","defaultOnError","retrievedMessages","error","intlError","IntlError","IntlErrorCode","MISSING_MESSAGE","createBaseTranslator","_ref2","cachedFormatsByLocale","defaultTranslationValues","globalFormats","formats","_ref2$getMessageFallb","getMessageFallback","defaultGetMessageFallback","locale","messagesOrError","timeZone","getFallbackFromErrorAndNotify","code","translateBaseFn","_cachedFormatsByLocal","joinPath","parts","filter","join","cacheKey","String","messageFormat","errorMessage","Array","isArray","INVALID_MESSAGE","INSUFFICIENT_PATH","IntlMessageFormat","convertFormatsToIntlMessageFormat","_extends","formattedMessage","format","FORMATTING_ERROR","translateFn","rich","raw"],"mappings":";;;;;;;AAoBA,SAASA,WAAWA,CAClBC,QAA0C,EAC1CC,GAAW,EACXC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L,eAAAA,GAAAA,GAAG,GAClBC,OAAAA,IAAAA,SAAS,GAAkBA,aAAAA,GAAAA,SAAS,GAAO,GAAA,GAAA,UAC7C,CACAK,GAAAA,qFAAAA,GAAAA,SAAS,CACd,CAAA;AACF,KAAA;AAED,IAAA,OAAOgB,MAAM,CAAA;AACf,GAAA;EAEAgD,WAAW,CAACC,IAAI,GAAGrB,eAAe,CAAA;EAElCoB,WAAW,CAACE,GAAG,GAAG;AAEhBxE,EAAAA,GAAW,EACJ;IACP,IAAI8C,eAAe,YAAYb,SAAS,EAAE;AACxC;AACA,MAAA,OAAOU,kBAAkB,CAAC;AACxBZ,QAAAA,KAAK,EAAEe,eAAe;AACtB9C,QAAAA,GAAG,EAAHA,GAAG;AACHC,QAAAA,SAAS,EAATA,SAAAA;AACD,OAAA,CAAC,CAAA;AACH,KAAA;IACD,IAAMF,QAAQ,GAAG+C,eAAe,CAAA;IAEhC,IAAI;AACF,MAAA,OAAOhD,WAAW,CAACC,QAAQ,EAAEC,GAAG,EAAEC,SAAS,CAAC,CAAA;KAC7C,CAAC,OAAO8B,KAAK,EAAE;MACd,OAAOiB,6BAA6B,CAClChD,GAAG,EACHkC,aAAa,CAACC,eAAe,EAC5BJ,KAAe,CAACxB,OAAO,CACzB,CAAA;AACF,KAAA;GACF,CAAA;AAED,EAAA,OAAO+D,WAAW,CAAA;AACpB;;;;"}
|
|
1
|
+
{"version":3,"file":"use-intl.esm7.js","sources":["../../src/core/createBaseTranslator.tsx"],"sourcesContent":["// eslint-disable-next-line import/no-named-as-default -- False positive\nimport IntlMessageFormat from 'intl-messageformat';\nimport {\n cloneElement,\n isValidElement,\n ReactElement,\n ReactNode,\n ReactNodeArray\n} from 'react';\nimport AbstractIntlMessages from './AbstractIntlMessages';\nimport Formats from './Formats';\nimport {InitializedIntlConfig} from './IntlConfig';\nimport IntlError, {IntlErrorCode} from './IntlError';\nimport MessageFormatCache from './MessageFormatCache';\nimport TranslationValues, {RichTranslationValues} from './TranslationValues';\nimport convertFormatsToIntlMessageFormat from './convertFormatsToIntlMessageFormat';\nimport {defaultGetMessageFallback, defaultOnError} from './defaults';\nimport MessageKeys from './utils/MessageKeys';\nimport NestedKeyOf from './utils/NestedKeyOf';\nimport NestedValueOf from './utils/NestedValueOf';\n\nfunction resolvePath(\n messages: AbstractIntlMessages | undefined,\n key: string,\n namespace?: string\n) {\n if (!messages) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? `No messages available at \\`${namespace}\\`.`\n : undefined\n );\n }\n\n let message = messages;\n\n key.split('.').forEach((part) => {\n const next = (message as any)[part];\n\n if (part == null || next == null) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? `Could not resolve \\`${key}\\` in ${\n namespace ? `\\`${namespace}\\`` : 'messages'\n }.`\n : undefined\n );\n }\n\n message = next;\n });\n\n return message;\n}\n\nfunction prepareTranslationValues(values: RichTranslationValues) {\n if (Object.keys(values).length === 0) return undefined;\n\n // Workaround for https://github.com/formatjs/formatjs/issues/1467\n const transformedValues: RichTranslationValues = {};\n Object.keys(values).forEach((key) => {\n let index = 0;\n const value = values[key];\n\n let transformed;\n if (typeof value === 'function') {\n transformed = (chunks: ReactNode) => {\n const result = value(chunks);\n\n return isValidElement(result)\n ? cloneElement(result, {key: key + index++})\n : result;\n };\n } else {\n transformed = value;\n }\n\n transformedValues[key] = transformed;\n });\n\n return transformedValues;\n}\n\nexport function getMessagesOrError<Messages extends AbstractIntlMessages>({\n messages,\n namespace,\n onError = defaultOnError\n}: {\n messages: Messages;\n namespace?: string;\n onError?(error: IntlError): void;\n}) {\n try {\n if (!messages) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? `No messages were configured on the provider.`\n : undefined\n );\n }\n\n const retrievedMessages = namespace\n ? resolvePath(messages, namespace)\n : messages;\n\n if (!retrievedMessages) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? `No messages for namespace \\`${namespace}\\` found.`\n : undefined\n );\n }\n\n return retrievedMessages;\n } catch (error) {\n const intlError = new IntlError(\n IntlErrorCode.MISSING_MESSAGE,\n (error as Error).message\n );\n onError(intlError);\n return intlError;\n }\n}\n\nexport type CreateBaseTranslatorProps<Messages> = InitializedIntlConfig & {\n messageFormatCache?: MessageFormatCache;\n defaultTranslationValues?: RichTranslationValues;\n namespace?: string;\n messagesOrError: Messages | IntlError;\n};\n\nfunction getPlainMessage(candidate: string, values?: unknown) {\n if (values) return undefined;\n\n const unescapedMessage = candidate.replace(/'([{}])/gi, '$1');\n\n // Placeholders can be in the message if there are default values,\n // or if the user has forgotten to provide values. In the latter\n // case we need to compile the message to receive an error.\n const hasPlaceholders = /<|{/.test(unescapedMessage);\n\n if (!hasPlaceholders) {\n return unescapedMessage;\n }\n\n return undefined;\n}\n\nexport default function createBaseTranslator<\n Messages extends AbstractIntlMessages,\n NestedKey extends NestedKeyOf<Messages>\n>({\n defaultTranslationValues,\n formats: globalFormats,\n getMessageFallback = defaultGetMessageFallback,\n locale,\n messageFormatCache,\n messagesOrError,\n namespace,\n onError,\n timeZone\n}: CreateBaseTranslatorProps<Messages>) {\n function getFallbackFromErrorAndNotify(\n key: string,\n code: IntlErrorCode,\n message?: string\n ) {\n const error = new IntlError(code, message);\n onError(error);\n return getMessageFallback({error, key, namespace});\n }\n\n function translateBaseFn(\n /** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */\n key: string,\n /** Key value pairs for values to interpolate into the message. */\n values?: RichTranslationValues,\n /** Provide custom formats for numbers, dates and times. */\n formats?: Partial<Formats>\n ): string | ReactElement | ReactNodeArray {\n if (messagesOrError instanceof IntlError) {\n // We have already warned about this during render\n return getMessageFallback({\n error: messagesOrError,\n key,\n namespace\n });\n }\n const messages = messagesOrError;\n\n let message;\n try {\n message = resolvePath(messages, key, namespace);\n } catch (error) {\n return getFallbackFromErrorAndNotify(\n key,\n IntlErrorCode.MISSING_MESSAGE,\n (error as Error).message\n );\n }\n\n function joinPath(parts: Array<string | undefined>) {\n return parts.filter((part) => part != null).join('.');\n }\n\n const cacheKey = joinPath([locale, namespace, key, String(message)]);\n\n let messageFormat: IntlMessageFormat;\n if (messageFormatCache?.has(cacheKey)) {\n messageFormat = messageFormatCache.get(cacheKey)!;\n } else {\n if (typeof message === 'object') {\n let code, errorMessage;\n if (Array.isArray(message)) {\n code = IntlErrorCode.INVALID_MESSAGE;\n if (process.env.NODE_ENV !== 'production') {\n errorMessage = `Message at \\`${joinPath([\n namespace,\n key\n ])}\\` resolved to an array, but only strings are supported. See https://next-intl-docs.vercel.app/docs/usage/messages#arrays-of-messages`;\n }\n } else {\n code = IntlErrorCode.INSUFFICIENT_PATH;\n if (process.env.NODE_ENV !== 'production') {\n errorMessage = `Message at \\`${joinPath([\n namespace,\n key\n ])}\\` resolved to an object, but only strings are supported. Use a \\`.\\` to retrieve nested messages. See https://next-intl-docs.vercel.app/docs/usage/messages#structuring-messages`;\n }\n }\n\n return getFallbackFromErrorAndNotify(key, code, errorMessage);\n }\n\n // Hot path that avoids creating an `IntlMessageFormat` instance\n const plainMessage = getPlainMessage(message as string, values);\n if (plainMessage) return plainMessage;\n\n try {\n messageFormat = new IntlMessageFormat(\n message,\n locale,\n convertFormatsToIntlMessageFormat(\n {...globalFormats, ...formats},\n timeZone\n )\n );\n } catch (error) {\n return getFallbackFromErrorAndNotify(\n key,\n IntlErrorCode.INVALID_MESSAGE,\n (error as Error).message\n );\n }\n\n messageFormatCache?.set(cacheKey, messageFormat);\n }\n\n try {\n const formattedMessage = messageFormat.format(\n // @ts-ignore `intl-messageformat` expects a different format\n // for rich text elements since a recent minor update. This\n // needs to be evaluated in detail, possibly also in regards\n // to be able to format to parts.\n prepareTranslationValues({...defaultTranslationValues, ...values})\n );\n\n if (formattedMessage == null) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? `Unable to format \\`${key}\\` in ${\n namespace ? `namespace \\`${namespace}\\`` : 'messages'\n }`\n : undefined\n );\n }\n\n // Limit the function signature to return strings or React elements\n return isValidElement(formattedMessage) ||\n // Arrays of React elements\n Array.isArray(formattedMessage) ||\n typeof formattedMessage === 'string'\n ? formattedMessage\n : String(formattedMessage);\n } catch (error) {\n return getFallbackFromErrorAndNotify(\n key,\n IntlErrorCode.FORMATTING_ERROR,\n (error as Error).message\n );\n }\n }\n\n function translateFn<\n TargetKey extends MessageKeys<\n NestedValueOf<Messages, NestedKey>,\n NestedKeyOf<NestedValueOf<Messages, NestedKey>>\n >\n >(\n /** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */\n key: TargetKey,\n /** Key value pairs for values to interpolate into the message. */\n values?: TranslationValues,\n /** Provide custom formats for numbers, dates and times. */\n formats?: Partial<Formats>\n ): string {\n const result = translateBaseFn(key, values, formats);\n\n if (typeof result !== 'string') {\n return getFallbackFromErrorAndNotify(\n key,\n IntlErrorCode.INVALID_MESSAGE,\n process.env.NODE_ENV !== 'production'\n ? `The message \\`${key}\\` in ${\n namespace ? `namespace \\`${namespace}\\`` : 'messages'\n } didn't resolve to a string. If you want to format rich text, use \\`t.rich\\` instead.`\n : undefined\n );\n }\n\n return result;\n }\n\n translateFn.rich = translateBaseFn;\n\n translateFn.raw = (\n /** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */\n key: string\n ): any => {\n if (messagesOrError instanceof IntlError) {\n // We have already warned about this during render\n return getMessageFallback({\n error: messagesOrError,\n key,\n namespace\n });\n }\n const messages = messagesOrError;\n\n try {\n return resolvePath(messages, key, namespace);\n } catch (error) {\n return getFallbackFromErrorAndNotify(\n key,\n IntlErrorCode.MISSING_MESSAGE,\n (error as Error).message\n );\n }\n };\n\n return translateFn;\n}\n"],"names":["resolvePath","messages","key","namespace","Error","process","env","NODE_ENV","undefined","message","split","forEach","part","next","prepareTranslationValues","values","Object","keys","length","transformedValues","index","value","transformed","chunks","result","isValidElement","cloneElement","getMessagesOrError","_ref","_ref$onError","onError","defaultOnError","retrievedMessages","error","intlError","IntlError","IntlErrorCode","MISSING_MESSAGE","getPlainMessage","candidate","unescapedMessage","replace","hasPlaceholders","test","createBaseTranslator","_ref2","defaultTranslationValues","globalFormats","formats","_ref2$getMessageFallb","getMessageFallback","defaultGetMessageFallback","locale","messageFormatCache","messagesOrError","timeZone","getFallbackFromErrorAndNotify","code","translateBaseFn","joinPath","parts","filter","join","cacheKey","String","messageFormat","has","get","errorMessage","Array","isArray","INVALID_MESSAGE","INSUFFICIENT_PATH","plainMessage","IntlMessageFormat","convertFormatsToIntlMessageFormat","_extends","set","formattedMessage","format","FORMATTING_ERROR","translateFn","rich","raw"],"mappings":";;;;;;;AAqBA,SAASA,WAAWA,CAClBC,QAA0C,EAC1CC,GAAW,EACXC,SAAkB,EAAA;EAElB,IAAI,CAACF,QAAQ,EAAE;AACb,IAAA,MAAM,IAAIG,KAAK,CACbC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,GAAA,4BAAA,GACHJ,SAAS,GAAA,IAAA,GACvCK,SAAS,CACd,CAAA;AACF,GAAA;EAED,IAAIC,OAAO,GAAGR,QAAQ,CAAA;EAEtBC,GAAG,CAACQ,KAAK,CAAC,GAAG,CAAC,CAACC,OAAO,CAAC,UAACC,IAAI,EAAI;AAC9B,IAAA,IAAMC,IAAI,GAAIJ,OAAe,CAACG,IAAI,CAAC,CAAA;AAEnC,IAAA,IAAIA,IAAI,IAAI,IAAI,IAAIC,IAAI,IAAI,IAAI,EAAE;MAChC,MAAM,IAAIT,KAAK,CACbC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,2BACVL,GAAG,GAAA,OAAA,IACxBC,SAAS,GAAQA,GAAAA,GAAAA,SAAS,SAAO,UACnC,CAAA,GAAA,GAAA,GACAK,SAAS,CACd,CAAA;AACF,KAAA;AAEDC,IAAAA,OAAO,GAAGI,IAAI,CAAA;AAChB,GAAC,CAAC,CAAA;AAEF,EAAA,OAAOJ,OAAO,CAAA;AAChB,CAAA;AAEA,SAASK,wBAAwBA,CAACC,MAA6B,EAAA;AAC7D,EAAA,IAAIC,MAAM,CAACC,IAAI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A,OAAOtD,WAAW,CAACC,QAAQ,EAAEC,GAAG,EAAEC,SAAS,CAAC,CAAA;KAC7C,CAAC,OAAO8B,KAAK,EAAE;MACd,OAAOuB,6BAA6B,CAClCtD,GAAG,EACHkC,aAAa,CAACC,eAAe,EAC5BJ,KAAe,CAACxB,OAAO,CACzB,CAAA;AACF,KAAA;GACF,CAAA;AAED,EAAA,OAAOwE,WAAW,CAAA;AACpB;;;;"}
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import
|
|
3
|
-
declare const IntlContext: import("react").Context<
|
|
2
|
+
import MessageFormatCache from '../core/MessageFormatCache';
|
|
3
|
+
declare const IntlContext: import("react").Context<(import("../core/IntlConfig").default<import("../core/AbstractIntlMessages").default> & {
|
|
4
|
+
onError: (error: import("..").IntlError) => void;
|
|
5
|
+
getMessageFallback: (info: {
|
|
6
|
+
error: import("..").IntlError;
|
|
7
|
+
key: string;
|
|
8
|
+
namespace?: string | undefined;
|
|
9
|
+
}) => string;
|
|
10
|
+
} & {
|
|
11
|
+
messageFormatCache?: MessageFormatCache | undefined;
|
|
12
|
+
}) | undefined>;
|
|
4
13
|
export default IntlContext;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose } from '../_virtual/use-intl.esm.js';
|
|
2
|
-
import React from 'react';
|
|
1
|
+
import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose, extends as _extends } from '../_virtual/use-intl.esm.js';
|
|
2
|
+
import React, { useState } from 'react';
|
|
3
3
|
import IntlContext from './use-intl.esm9.js';
|
|
4
4
|
import getInitializedConfig from './use-intl.esm10.js';
|
|
5
5
|
|
|
@@ -7,8 +7,14 @@ var _excluded = ["children"];
|
|
|
7
7
|
function IntlProvider(_ref) {
|
|
8
8
|
var children = _ref.children,
|
|
9
9
|
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
10
|
+
var _useState = useState(function () {
|
|
11
|
+
return new Map();
|
|
12
|
+
}),
|
|
13
|
+
messageFormatCache = _useState[0];
|
|
10
14
|
return React.createElement(IntlContext.Provider, {
|
|
11
|
-
value: getInitializedConfig(props)
|
|
15
|
+
value: _extends({}, getInitializedConfig(props), {
|
|
16
|
+
messageFormatCache: messageFormatCache
|
|
17
|
+
})
|
|
12
18
|
}, children);
|
|
13
19
|
}
|
|
14
20
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-intl.esm.js","sources":["../../src/react/IntlProvider.tsx"],"sourcesContent":["import React, {ReactNode} from 'react';\nimport IntlConfig from '../core/IntlConfig';\nimport IntlContext from './IntlContext';\nimport getInitializedConfig from './getInitializedConfig';\n\ntype Props = IntlConfig & {\n children: ReactNode;\n};\n\nexport default function IntlProvider({children, ...props}: Props) {\n return (\n <IntlContext.Provider
|
|
1
|
+
{"version":3,"file":"use-intl.esm.js","sources":["../../src/react/IntlProvider.tsx"],"sourcesContent":["import React, {ReactNode, useState} from 'react';\nimport IntlConfig from '../core/IntlConfig';\nimport IntlContext from './IntlContext';\nimport getInitializedConfig from './getInitializedConfig';\n\ntype Props = IntlConfig & {\n children: ReactNode;\n};\n\nexport default function IntlProvider({children, ...props}: Props) {\n const [messageFormatCache] = useState(() => new Map());\n\n return (\n <IntlContext.Provider\n value={{\n ...getInitializedConfig(props),\n messageFormatCache\n }}\n >\n {children}\n </IntlContext.Provider>\n );\n}\n"],"names":["IntlProvider","_ref","children","props","_objectWithoutPropertiesLoose","_excluded","_useState","useState","Map","messageFormatCache","React","createElement","IntlContext","Provider","value","_extends","getInitializedConfig"],"mappings":";;;;;;AASc,SAAUA,YAAYA,CAAAC,IAAA,EAA4B;AAAA,EAAA,IAA1BC,QAAQ,GAAAD,IAAA,CAARC,QAAQ;AAAKC,IAAAA,KAAK,GAAAC,6BAAA,CAAAH,IAAA,EAAAI,SAAA,CAAA,CAAA;EACtD,IAAAC,SAAA,GAA6BC,QAAQ,CAAC,YAAA;MAAA,OAAM,IAAIC,GAAG,EAAE,CAAA;KAAC,CAAA;AAA/CC,IAAAA,kBAAkB,GAAAH,SAAA,CAAA,CAAA,CAAA,CAAA;AAEzB,EAAA,OACEI,KAAC,CAAAC,aAAA,CAAAC,WAAW,CAACC,QAAQ,EAAA;AACnBC,IAAAA,KAAK,EAAAC,QAAA,CAAA,EAAA,EACAC,oBAAoB,CAACb,KAAK,CAAC,EAAA;AAC9BM,MAAAA,kBAAkB,EAAlBA,kBAAAA;AAAkB,KAAA,CAAA;GAGnB,EAAAP,QAAQ,CACY,CAAA;AAE3B;;;;"}
|
|
@@ -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"];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
2
|
import createBaseTranslator, { getMessagesOrError } from '../core/use-intl.esm7.js';
|
|
3
3
|
import resolveNamespace from '../core/use-intl.esm8.js';
|
|
4
4
|
import useIntlContext from './use-intl.esm11.js';
|
|
@@ -9,13 +9,13 @@ function useTranslationsImpl(allMessages, namespace, namespacePrefix) {
|
|
|
9
9
|
globalFormats = _useIntlContext.formats,
|
|
10
10
|
getMessageFallback = _useIntlContext.getMessageFallback,
|
|
11
11
|
locale = _useIntlContext.locale,
|
|
12
|
+
messageFormatCache = _useIntlContext.messageFormatCache,
|
|
12
13
|
onError = _useIntlContext.onError,
|
|
13
14
|
timeZone = _useIntlContext.timeZone;
|
|
14
15
|
// The `namespacePrefix` is part of the type system.
|
|
15
16
|
// See the comment in the hook invocation.
|
|
16
17
|
allMessages = allMessages[namespacePrefix];
|
|
17
18
|
namespace = resolveNamespace(namespace, namespacePrefix);
|
|
18
|
-
var cachedFormatsByLocaleRef = useRef({});
|
|
19
19
|
var messagesOrError = useMemo(function () {
|
|
20
20
|
return getMessagesOrError({
|
|
21
21
|
messages: allMessages,
|
|
@@ -25,7 +25,7 @@ function useTranslationsImpl(allMessages, namespace, namespacePrefix) {
|
|
|
25
25
|
}, [allMessages, namespace, onError]);
|
|
26
26
|
var translate = useMemo(function () {
|
|
27
27
|
return createBaseTranslator({
|
|
28
|
-
|
|
28
|
+
messageFormatCache: messageFormatCache,
|
|
29
29
|
getMessageFallback: getMessageFallback,
|
|
30
30
|
messagesOrError: messagesOrError,
|
|
31
31
|
defaultTranslationValues: defaultTranslationValues,
|
|
@@ -35,7 +35,7 @@ function useTranslationsImpl(allMessages, namespace, namespacePrefix) {
|
|
|
35
35
|
locale: locale,
|
|
36
36
|
timeZone: timeZone
|
|
37
37
|
});
|
|
38
|
-
}, [getMessageFallback, messagesOrError, defaultTranslationValues, namespace, onError, globalFormats, locale, timeZone]);
|
|
38
|
+
}, [messageFormatCache, getMessageFallback, messagesOrError, defaultTranslationValues, namespace, onError, globalFormats, locale, timeZone]);
|
|
39
39
|
return translate;
|
|
40
40
|
}
|
|
41
41
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-intl.esm12.js","sources":["../../src/react/useTranslationsImpl.tsx"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"use-intl.esm12.js","sources":["../../src/react/useTranslationsImpl.tsx"],"sourcesContent":["import {useMemo} 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 messageFormatCache,\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 messagesOrError = useMemo(\n () => getMessagesOrError({messages: allMessages, namespace, onError}),\n [allMessages, namespace, onError]\n );\n\n const translate = useMemo(\n () =>\n createBaseTranslator({\n messageFormatCache,\n getMessageFallback,\n messagesOrError,\n defaultTranslationValues,\n namespace,\n onError,\n formats: globalFormats,\n locale,\n timeZone\n }),\n [\n messageFormatCache,\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","messageFormatCache","onError","timeZone","resolveNamespace","messagesOrError","useMemo","getMessagesOrError","messages","translate","createBaseTranslator"],"mappings":";;;;;AASwB,SAAAA,mBAAmBA,CAGzCC,WAAqB,EAAEC,SAAoB,EAAEC,eAAuB,EAAA;AACpE,EAAA,IAAAC,eAAA,GAQIC,cAAc,EAAE;IAPlBC,wBAAwB,GAAAF,eAAA,CAAxBE,wBAAwB;IACfC,aAAa,GAAAH,eAAA,CAAtBI,OAAO;IACPC,kBAAkB,GAAAL,eAAA,CAAlBK,kBAAkB;IAClBC,MAAM,GAAAN,eAAA,CAANM,MAAM;IACNC,kBAAkB,GAAAP,eAAA,CAAlBO,kBAAkB;IAClBC,OAAO,GAAAR,eAAA,CAAPQ,OAAO;IACPC,QAAQ,GAAAT,eAAA,CAARS,QAAQ,CAAA;AAGV;AACA;AACAZ,EAAAA,WAAW,GAAGA,WAAW,CAACE,eAAe,CAAa,CAAA;AACtDD,EAAAA,SAAS,GAAGY,gBAAgB,CAACZ,SAAS,EAAEC,eAAe,CAAc,CAAA;EAErE,IAAMY,eAAe,GAAGC,OAAO,CAC7B,YAAA;AAAA,IAAA,OAAMC,kBAAkB,CAAC;AAACC,MAAAA,QAAQ,EAAEjB,WAAW;AAAEC,MAAAA,SAAS,EAATA,SAAS;AAAEU,MAAAA,OAAO,EAAPA,OAAAA;AAAO,KAAC,CAAC,CAAA;AAAA,GAAA,EACrE,CAACX,WAAW,EAAEC,SAAS,EAAEU,OAAO,CAAC,CAClC,CAAA;EAED,IAAMO,SAAS,GAAGH,OAAO,CACvB,YAAA;AAAA,IAAA,OACEI,oBAAoB,CAAC;AACnBT,MAAAA,kBAAkB,EAAlBA,kBAAkB;AAClBF,MAAAA,kBAAkB,EAAlBA,kBAAkB;AAClBM,MAAAA,eAAe,EAAfA,eAAe;AACfT,MAAAA,wBAAwB,EAAxBA,wBAAwB;AACxBJ,MAAAA,SAAS,EAATA,SAAS;AACTU,MAAAA,OAAO,EAAPA,OAAO;AACPJ,MAAAA,OAAO,EAAED,aAAa;AACtBG,MAAAA,MAAM,EAANA,MAAM;AACNG,MAAAA,QAAQ,EAARA,QAAAA;AACD,KAAA,CAAC,CAAA;AAAA,GAAA,EACJ,CACEF,kBAAkB,EAClBF,kBAAkB,EAClBM,eAAe,EACfT,wBAAwB,EACxBJ,SAAS,EACTU,OAAO,EACPL,aAAa,EACbG,MAAM,EACNG,QAAQ,CACT,CACF,CAAA;AAED,EAAA,OAAOM,SAAS,CAAA;AAClB;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-intl.esm9.js","sources":["../../src/react/IntlContext.tsx"],"sourcesContent":["import {createContext} from 'react';\nimport {InitializedIntlConfig} from '../core/IntlConfig';\n\nconst IntlContext = createContext
|
|
1
|
+
{"version":3,"file":"use-intl.esm9.js","sources":["../../src/react/IntlContext.tsx"],"sourcesContent":["import {createContext} from 'react';\nimport {InitializedIntlConfig} from '../core/IntlConfig';\nimport MessageFormatCache from '../core/MessageFormatCache';\n\nconst IntlContext = createContext<\n | (InitializedIntlConfig & {\n messageFormatCache?: MessageFormatCache;\n })\n | undefined\n>(undefined);\n\nexport default IntlContext;\n"],"names":["IntlContext","createContext","undefined"],"mappings":";;AAIA,IAAMA,WAAW,gBAAGC,aAAa,CAK/BC,SAAS;;;;"}
|
|
@@ -1 +1,10 @@
|
|
|
1
|
-
export default function useIntlContext(): import("../core/IntlConfig").
|
|
1
|
+
export default function useIntlContext(): import("../core/IntlConfig").default<import("../core/AbstractIntlMessages").default> & {
|
|
2
|
+
onError: (error: import("..").IntlError) => void;
|
|
3
|
+
getMessageFallback: (info: {
|
|
4
|
+
error: import("..").IntlError;
|
|
5
|
+
key: string;
|
|
6
|
+
namespace?: string | undefined;
|
|
7
|
+
}) => string;
|
|
8
|
+
} & {
|
|
9
|
+
messageFormatCache?: import("../core/MessageFormatCache").default | undefined;
|
|
10
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MessageFormatCache.js","sourceRoot":"","sources":["../../../src/core/MessageFormatCache.tsx"],"names":[],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convertFormatsToIntlMessageFormat.js","sourceRoot":"","sources":["../../../src/core/convertFormatsToIntlMessageFormat.tsx"],"names":[],"mappings":"AAAA,OAAO,iBAA2C,MAAM,oBAAoB,CAAC;AAK7E,SAAS,oBAAoB,CAC3B,OAA0D,EAC1D,QAAkB;IAElB,IAAI,CAAC,OAAO;QAAE,OAAO,OAAO,CAAC;IAE7B,4FAA4F;IAC5F,sHAAsH;IACtH,OAAO,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,CAChC,CAAC,GAA0C,EAAE,GAAG,EAAE,EAAE;QAClD,GAAG,CAAC,GAAG,CAAC,GAAG;YACT,QAAQ;YACR,GAAG,OAAO,CAAC,GAAG,CAAC;SAChB,CAAC;QACF,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