use-intl 2.7.3-alpha.0 → 2.7.4

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.
@@ -1,213 +1,32 @@
1
- import { extends as _extends } from './_virtual/use-intl.esm.js';
2
- import { IntlMessageFormat } from 'intl-messageformat';
3
- import { useRef, useMemo, isValidElement, cloneElement } from 'react';
4
- import IntlError, { IntlErrorCode } from './use-intl.esm7.js';
5
- import convertFormatsToIntlMessageFormat from './use-intl.esm13.js';
6
- import useIntlContext from './use-intl.esm9.js';
1
+ import IntlError, { IntlErrorCode } from './use-intl.esm8.js';
7
2
 
8
- function resolvePath(messages, idPath, namespace) {
9
- if (!messages) {
10
- throw new Error(process.env.NODE_ENV !== "production" ? "No messages available at `" + namespace + "`." : undefined);
11
- }
12
-
13
- var message = messages;
14
- idPath.split('.').forEach(function (part) {
15
- var next = message[part];
3
+ function validateMessagesSegment(messages, invalidKeyLabels, parentPath) {
4
+ Object.entries(messages).forEach(function (_ref) {
5
+ var key = _ref[0],
6
+ messageOrMessages = _ref[1];
16
7
 
17
- if (part == null || next == null) {
18
- throw new Error(process.env.NODE_ENV !== "production" ? "Could not resolve `" + idPath + "` in " + (namespace ? "`" + namespace + "`" : 'messages') + "." : undefined);
8
+ if (key.includes('.')) {
9
+ var keyLabel = key;
10
+ if (parentPath) keyLabel += " (at " + parentPath + ")";
11
+ invalidKeyLabels.push(keyLabel);
19
12
  }
20
13
 
21
- message = next;
22
- });
23
- return message;
24
- }
25
-
26
- function prepareTranslationValues(values) {
27
- if (Object.keys(values).length === 0) return undefined; // Workaround for https://github.com/formatjs/formatjs/issues/1467
28
-
29
- var transformedValues = {};
30
- Object.keys(values).forEach(function (key) {
31
- var index = 0;
32
- var value = values[key];
33
- var transformed;
34
-
35
- if (typeof value === 'function') {
36
- transformed = function transformed(children) {
37
- var result = value(children);
38
- return isValidElement(result) ? cloneElement(result, {
39
- key: key + index++
40
- }) : result;
41
- };
42
- } else {
43
- transformed = value;
14
+ if (messageOrMessages != null && typeof messageOrMessages === 'object') {
15
+ validateMessagesSegment(messageOrMessages, invalidKeyLabels, [parentPath, key].filter(function (part) {
16
+ return part != null;
17
+ }).join('.'));
44
18
  }
45
-
46
- transformedValues[key] = transformed;
47
19
  });
48
- return transformedValues;
49
20
  }
50
21
 
51
- function useTranslationsImpl(allMessages, namespace, namespacePrefix) {
52
- var _useIntlContext = useIntlContext(),
53
- defaultTranslationValues = _useIntlContext.defaultTranslationValues,
54
- globalFormats = _useIntlContext.formats,
55
- getMessageFallback = _useIntlContext.getMessageFallback,
56
- locale = _useIntlContext.locale,
57
- onError = _useIntlContext.onError,
58
- timeZone = _useIntlContext.timeZone; // The `namespacePrefix` is part of the type system.
59
- // See the comment in the hook invocation.
60
-
61
-
62
- allMessages = allMessages[namespacePrefix];
63
- namespace = namespace === namespacePrefix ? undefined : namespace.slice((namespacePrefix + '.').length);
64
- var cachedFormatsByLocaleRef = useRef({});
65
- var messagesOrError = useMemo(function () {
66
- try {
67
- if (!allMessages) {
68
- throw new Error(process.env.NODE_ENV !== "production" ? "No messages were configured on the provider." : undefined);
69
- }
70
-
71
- var retrievedMessages = namespace ? resolvePath(allMessages, namespace) : allMessages;
72
-
73
- if (!retrievedMessages) {
74
- throw new Error(process.env.NODE_ENV !== "production" ? "No messages for namespace `" + namespace + "` found." : undefined);
75
- }
76
-
77
- return retrievedMessages;
78
- } catch (error) {
79
- var intlError = new IntlError(IntlErrorCode.MISSING_MESSAGE, error.message);
80
- onError(intlError);
81
- return intlError;
82
- }
83
- }, [allMessages, namespace, onError]);
84
- var translate = useMemo(function () {
85
- function getFallbackFromErrorAndNotify(key, code, message) {
86
- var error = new IntlError(code, message);
87
- onError(error);
88
- return getMessageFallback({
89
- error: error,
90
- key: key,
91
- namespace: namespace
92
- });
93
- }
94
-
95
- function translateBaseFn(
96
- /** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */
97
- key,
98
- /** Key value pairs for values to interpolate into the message. */
99
- values,
100
- /** Provide custom formats for numbers, dates and times. */
101
- formats) {
102
- var _cachedFormatsByLocal;
103
-
104
- var cachedFormatsByLocale = cachedFormatsByLocaleRef.current;
105
-
106
- if (messagesOrError instanceof IntlError) {
107
- // We have already warned about this during render
108
- return getMessageFallback({
109
- error: messagesOrError,
110
- key: key,
111
- namespace: namespace
112
- });
113
- }
114
-
115
- var messages = messagesOrError;
116
- var cacheKey = [namespace, key].filter(function (part) {
117
- return part != null;
118
- }).join('.');
119
- var messageFormat;
22
+ function validateMessages(messages, onError) {
23
+ var invalidKeyLabels = [];
24
+ validateMessagesSegment(messages, invalidKeyLabels);
120
25
 
121
- if ((_cachedFormatsByLocal = cachedFormatsByLocale[locale]) != null && _cachedFormatsByLocal[cacheKey]) {
122
- messageFormat = cachedFormatsByLocale[locale][cacheKey];
123
- } else {
124
- var message;
125
-
126
- try {
127
- message = resolvePath(messages, key, namespace);
128
- } catch (error) {
129
- return getFallbackFromErrorAndNotify(key, IntlErrorCode.MISSING_MESSAGE, error.message);
130
- }
131
-
132
- if (typeof message === 'object') {
133
- return getFallbackFromErrorAndNotify(key, IntlErrorCode.INSUFFICIENT_PATH, process.env.NODE_ENV !== "production" ? "Insufficient path specified for `" + key + "` in `" + (namespace ? "`" + namespace + "`" : 'messages') + "`." : undefined);
134
- }
135
-
136
- try {
137
- messageFormat = new IntlMessageFormat(message, locale, convertFormatsToIntlMessageFormat(_extends({}, globalFormats, formats), timeZone));
138
- } catch (error) {
139
- return getFallbackFromErrorAndNotify(key, IntlErrorCode.INVALID_MESSAGE, error.message);
140
- }
141
-
142
- if (!cachedFormatsByLocale[locale]) {
143
- cachedFormatsByLocale[locale] = {};
144
- }
145
-
146
- cachedFormatsByLocale[locale][cacheKey] = messageFormat;
147
- }
148
-
149
- try {
150
- var formattedMessage = messageFormat.format( // @ts-ignore `intl-messageformat` expects a different format
151
- // for rich text elements since a recent minor update. This
152
- // needs to be evaluated in detail, possibly also in regards
153
- // to be able to format to parts.
154
- prepareTranslationValues(_extends({}, defaultTranslationValues, values)));
155
-
156
- if (formattedMessage == null) {
157
- throw new Error(process.env.NODE_ENV !== "production" ? "Unable to format `" + key + "` in " + (namespace ? "namespace `" + namespace + "`" : 'messages') : undefined);
158
- } // Limit the function signature to return strings or React elements
159
-
160
-
161
- return isValidElement(formattedMessage) || // Arrays of React elements
162
- Array.isArray(formattedMessage) || typeof formattedMessage === 'string' ? formattedMessage : String(formattedMessage);
163
- } catch (error) {
164
- return getFallbackFromErrorAndNotify(key, IntlErrorCode.FORMATTING_ERROR, error.message);
165
- }
166
- }
167
-
168
- function translateFn(
169
- /** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */
170
- key,
171
- /** Key value pairs for values to interpolate into the message. */
172
- values,
173
- /** Provide custom formats for numbers, dates and times. */
174
- formats) {
175
- var message = translateBaseFn(key, values, formats);
176
-
177
- if (typeof message !== 'string') {
178
- return getFallbackFromErrorAndNotify(key, IntlErrorCode.INVALID_MESSAGE, process.env.NODE_ENV !== "production" ? "The message `" + key + "` in " + (namespace ? "namespace `" + namespace + "`" : 'messages') + " didn't resolve to a string. If you want to format rich text, use `t.rich` instead." : undefined);
179
- }
180
-
181
- return message;
182
- }
183
-
184
- translateFn.rich = translateBaseFn;
185
-
186
- translateFn.raw = function (
187
- /** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */
188
- key) {
189
- if (messagesOrError instanceof IntlError) {
190
- // We have already warned about this during render
191
- return getMessageFallback({
192
- error: messagesOrError,
193
- key: key,
194
- namespace: namespace
195
- });
196
- }
197
-
198
- var messages = messagesOrError;
199
-
200
- try {
201
- return resolvePath(messages, key, namespace);
202
- } catch (error) {
203
- return getFallbackFromErrorAndNotify(key, IntlErrorCode.MISSING_MESSAGE, error.message);
204
- }
205
- };
206
-
207
- return translateFn;
208
- }, [onError, getMessageFallback, namespace, messagesOrError, locale, globalFormats, timeZone, defaultTranslationValues]);
209
- return translate;
26
+ if (invalidKeyLabels.length > 0) {
27
+ onError(new IntlError(IntlErrorCode.INVALID_KEY, "Namespace keys can not contain the character \".\" as this is used to express nesting. Please remove it or replace it with another character.\n\nInvalid " + (invalidKeyLabels.length === 1 ? 'key' : 'keys') + ": " + invalidKeyLabels.join(', ')));
28
+ }
210
29
  }
211
30
 
212
- export { useTranslationsImpl as default };
31
+ export { validateMessages as default };
213
32
  //# sourceMappingURL=use-intl.esm10.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-intl.esm10.js","sources":["../src/useTranslationsImpl.tsx"],"sourcesContent":["import {IntlMessageFormat} from 'intl-messageformat';\nimport {\n cloneElement,\n isValidElement,\n ReactElement,\n ReactNode,\n ReactNodeArray,\n useMemo,\n useRef\n} from 'react';\nimport AbstractIntlMessages from './AbstractIntlMessages';\nimport Formats from './Formats';\nimport IntlError, {IntlErrorCode} from './IntlError';\nimport TranslationValues, {RichTranslationValues} from './TranslationValues';\nimport convertFormatsToIntlMessageFormat from './convertFormatsToIntlMessageFormat';\nimport useIntlContext from './useIntlContext';\nimport MessageKeys from './utils/MessageKeys';\nimport NestedKeyOf from './utils/NestedKeyOf';\nimport NestedValueOf from './utils/NestedValueOf';\n\nfunction resolvePath(\n messages: AbstractIntlMessages | undefined,\n idPath: string,\n namespace?: string\n) {\n if (!messages) {\n throw new Error(\n __DEV__ ? `No messages available at \\`${namespace}\\`.` : undefined\n );\n }\n\n let message = messages;\n\n idPath.split('.').forEach((part) => {\n const next = (message as any)[part];\n\n if (part == null || next == null) {\n throw new Error(\n __DEV__\n ? `Could not resolve \\`${idPath}\\` 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 = (children: ReactNode) => {\n const result = value(children);\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 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 = (\n namespace === namespacePrefix\n ? undefined\n : namespace.slice((namespacePrefix + '.').length)\n ) as NestedKey;\n\n const cachedFormatsByLocaleRef = useRef<\n Record<string, Record<string, IntlMessageFormat>>\n >({});\n\n const messagesOrError = useMemo(() => {\n try {\n if (!allMessages) {\n throw new Error(\n __DEV__ ? `No messages were configured on the provider.` : undefined\n );\n }\n\n const retrievedMessages = namespace\n ? resolvePath(allMessages, namespace)\n : allMessages;\n\n if (!retrievedMessages) {\n throw new Error(\n __DEV__\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 }, [allMessages, namespace, onError]);\n\n const translate = useMemo(() => {\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 const cachedFormatsByLocale = cachedFormatsByLocaleRef.current;\n\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 const cacheKey = [namespace, key]\n .filter((part) => part != null)\n .join('.');\n\n let messageFormat;\n if (cachedFormatsByLocale[locale]?.[cacheKey]) {\n messageFormat = cachedFormatsByLocale[locale][cacheKey];\n } else {\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 if (typeof message === 'object') {\n return getFallbackFromErrorAndNotify(\n key,\n IntlErrorCode.INSUFFICIENT_PATH,\n __DEV__\n ? `Insufficient path specified for \\`${key}\\` in \\`${\n namespace ? `\\`${namespace}\\`` : 'messages'\n }\\`.`\n : undefined\n );\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[locale]) {\n cachedFormatsByLocale[locale] = {};\n }\n cachedFormatsByLocale[locale][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 __DEV__\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 message = translateBaseFn(key, values, formats);\n\n if (typeof message !== 'string') {\n return getFallbackFromErrorAndNotify(\n key,\n IntlErrorCode.INVALID_MESSAGE,\n __DEV__\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 message;\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 onError,\n getMessageFallback,\n namespace,\n messagesOrError,\n locale,\n globalFormats,\n timeZone,\n defaultTranslationValues\n ]);\n\n return translate;\n}\n"],"names":["resolvePath","messages","idPath","namespace","Error","undefined","message","split","forEach","part","next","prepareTranslationValues","values","Object","keys","length","transformedValues","key","index","value","transformed","children","result","isValidElement","cloneElement","useTranslationsImpl","allMessages","namespacePrefix","useIntlContext","defaultTranslationValues","globalFormats","formats","getMessageFallback","locale","onError","timeZone","slice","cachedFormatsByLocaleRef","useRef","messagesOrError","useMemo","retrievedMessages","error","intlError","IntlError","IntlErrorCode","MISSING_MESSAGE","translate","getFallbackFromErrorAndNotify","code","translateBaseFn","cachedFormatsByLocale","current","cacheKey","filter","join","messageFormat","INSUFFICIENT_PATH","IntlMessageFormat","convertFormatsToIntlMessageFormat","INVALID_MESSAGE","formattedMessage","format","Array","isArray","String","FORMATTING_ERROR","translateFn","rich","raw"],"mappings":";;;;;;;AAoBA,SAASA,WAAT,CACEC,QADF,EAEEC,MAFF,EAGEC,SAHF,EAGoB;AAElB,EAAI,IAAA,CAACF,QAAL,EAAe;AACb,IAAA,MAAM,IAAIG,KAAJ,CACJ,uEAAwCD,SAAxC,GAAA,IAAA,GAAyDE,SADrD,CAAN,CAAA;AAGD,GAAA;;AAED,EAAIC,IAAAA,OAAO,GAAGL,QAAd,CAAA;AAEAC,EAAAA,MAAM,CAACK,KAAP,CAAa,GAAb,EAAkBC,OAAlB,CAA0B,UAACC,IAAD,EAAS;AACjC,IAAA,IAAMC,IAAI,GAAIJ,OAAe,CAACG,IAAD,CAA7B,CAAA;;AAEA,IAAA,IAAIA,IAAI,IAAI,IAAR,IAAgBC,IAAI,IAAI,IAA5B,EAAkC;AAChC,MAAA,MAAM,IAAIN,KAAJ,CACJ,OAAA,CAAA,GAAA,CAAA,QAAA,KAAA,YAAA,GAAA,qBAAA,GAC2BF,MAD3B,GAAA,OAAA,IAEMC,SAAS,GAAA,GAAA,GAAQA,SAAR,GAAA,GAAA,GAAwB,UAFvC,CAAA,GAAA,GAAA,GAIIE,SALA,CAAN,CAAA;AAOD,KAAA;;AAEDC,IAAAA,OAAO,GAAGI,IAAV,CAAA;AACD,GAdD,CAAA,CAAA;AAgBA,EAAA,OAAOJ,OAAP,CAAA;AACD,CAAA;;AAED,SAASK,wBAAT,CAAkCC,MAAlC,EAA+D;AAC7D,EAAA,IAAIC,MAAM,CAACC,IAAP,CAAYF,MAAZ,CAAA,CAAoBG,MAApB,KAA+B,CAAnC,EAAsC,OAAOV,SAAP,CADuB;;AAI7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AA,GAAAA,SAAlB,SAAkC,UAFjD,CAAA,GAAA,qFAAA,GAIIE,SAP8B,CAApC,CAAA;AASD,OAAA;;AAED,MAAA,OAAOC,OAAP,CAAA;AACD,KAAA;;AAED6D,IAAAA,WAAW,CAACC,IAAZ,GAAmBlB,eAAnB,CAAA;;AAEAiB,IAAAA,WAAW,CAACE,GAAZ,GAAkB;AAChB;AACApD,IAAAA,GAFgB,EAGT;AACP,MAAIsB,IAAAA,eAAe,YAAYK,SAA/B,EAA0C;AACxC;AACA,QAAA,OAAOZ,kBAAkB,CAAC;AACxBU,UAAAA,KAAK,EAAEH,eADiB;AAExBtB,UAAAA,GAAG,EAAHA,GAFwB;AAGxBd,UAAAA,SAAS,EAATA,SAAAA;AAHwB,SAAD,CAAzB,CAAA;AAKD,OAAA;;AACD,MAAMF,IAAAA,QAAQ,GAAGsC,eAAjB,CAAA;;AAEA,MAAI,IAAA;AACF,QAAA,OAAOvC,WAAW,CAACC,QAAD,EAAWgB,GAAX,EAAgBd,SAAhB,CAAlB,CAAA;AACD,OAFD,CAEE,OAAOuC,KAAP,EAAc;AACd,QAAOM,OAAAA,6BAA6B,CAClC/B,GADkC,EAElC4B,aAAa,CAACC,eAFoB,EAGjCJ,KAAe,CAACpC,OAHiB,CAApC,CAAA;AAKD,OAAA;AACF,KAvBD,CAAA;;AAyBA,IAAA,OAAO6D,WAAP,CAAA;AACD,GAlLwB,EAkLtB,CACDjC,OADC,EAEDF,kBAFC,EAGD7B,SAHC,EAIDoC,eAJC,EAKDN,MALC,EAMDH,aANC,EAODK,QAPC,EAQDN,wBARC,CAlLsB,CAAzB,CAAA;AA6LA,EAAA,OAAOkB,SAAP,CAAA;AACD;;;;"}
1
+ {"version":3,"file":"use-intl.esm10.js","sources":["../src/validateMessages.tsx"],"sourcesContent":["import AbstractIntlMessages from './AbstractIntlMessages';\nimport IntlError, {IntlErrorCode} from './IntlError';\n\nfunction validateMessagesSegment(\n messages: AbstractIntlMessages,\n invalidKeyLabels: Array<string>,\n parentPath?: string\n) {\n Object.entries(messages).forEach(([key, messageOrMessages]) => {\n if (key.includes('.')) {\n let keyLabel = key;\n if (parentPath) keyLabel += ` (at ${parentPath})`;\n invalidKeyLabels.push(keyLabel);\n }\n\n if (messageOrMessages != null && typeof messageOrMessages === 'object') {\n validateMessagesSegment(\n messageOrMessages,\n invalidKeyLabels,\n [parentPath, key].filter((part) => part != null).join('.')\n );\n }\n });\n}\n\nexport default function validateMessages(\n messages: AbstractIntlMessages,\n onError: (error: IntlError) => void\n) {\n const invalidKeyLabels: Array<string> = [];\n validateMessagesSegment(messages, invalidKeyLabels);\n\n if (invalidKeyLabels.length > 0) {\n onError(\n new IntlError(\n IntlErrorCode.INVALID_KEY,\n `Namespace keys can not contain the character \".\" as this is used to express nesting. Please remove it or replace it with another character.\\n\\nInvalid ${\n invalidKeyLabels.length === 1 ? 'key' : 'keys'\n }: ${invalidKeyLabels.join(', ')}`\n )\n );\n }\n}\n"],"names":["validateMessagesSegment","messages","invalidKeyLabels","parentPath","Object","entries","forEach","key","messageOrMessages","includes","keyLabel","push","filter","part","join","validateMessages","onError","length","IntlError","IntlErrorCode","INVALID_KEY"],"mappings":";;AAGA,SAASA,uBAAT,CACEC,QADF,EAEEC,gBAFF,EAGEC,UAHF,EAGqB;AAEnBC,EAAAA,MAAM,CAACC,OAAP,CAAeJ,QAAf,CAAyBK,CAAAA,OAAzB,CAAiC,UAA6B,IAAA,EAAA;AAAA,IAAA,IAA3BC,GAA2B,GAAA,IAAA,CAAA,CAAA,CAAA;AAAA,QAAtBC,iBAAsB,GAAA,IAAA,CAAA,CAAA,CAAA,CAAA;;AAC5D,IAAA,IAAID,GAAG,CAACE,QAAJ,CAAa,GAAb,CAAJ,EAAuB;AACrB,MAAIC,IAAAA,QAAQ,GAAGH,GAAf,CAAA;AACA,MAAA,IAAIJ,UAAJ,EAAgBO,QAAQ,IAAA,OAAA,GAAYP,UAAZ,GAAR,GAAA,CAAA;AAChBD,MAAAA,gBAAgB,CAACS,IAAjB,CAAsBD,QAAtB,CAAA,CAAA;AACD,KAAA;;AAED,IAAIF,IAAAA,iBAAiB,IAAI,IAArB,IAA6B,OAAOA,iBAAP,KAA6B,QAA9D,EAAwE;AACtER,MAAAA,uBAAuB,CACrBQ,iBADqB,EAErBN,gBAFqB,EAGrB,CAACC,UAAD,EAAaI,GAAb,CAAA,CAAkBK,MAAlB,CAAyB,UAACC,IAAD,EAAA;AAAA,QAAUA,OAAAA,IAAI,IAAI,IAAlB,CAAA;AAAA,OAAzB,CAAiDC,CAAAA,IAAjD,CAAsD,GAAtD,CAHqB,CAAvB,CAAA;AAKD,KAAA;AACF,GAdD,CAAA,CAAA;AAeD,CAAA;;AAEa,SAAUC,gBAAV,CACZd,QADY,EAEZe,OAFY,EAEuB;AAEnC,EAAMd,IAAAA,gBAAgB,GAAkB,EAAxC,CAAA;AACAF,EAAAA,uBAAuB,CAACC,QAAD,EAAWC,gBAAX,CAAvB,CAAA;;AAEA,EAAA,IAAIA,gBAAgB,CAACe,MAAjB,GAA0B,CAA9B,EAAiC;AAC/BD,IAAAA,OAAO,CACL,IAAIE,SAAJ,CACEC,aAAa,CAACC,WADhB,EAAA,2JAAA,IAGIlB,gBAAgB,CAACe,MAAjB,KAA4B,CAA5B,GAAgC,KAAhC,GAAwC,MAH5C,CAIOf,GAAAA,IAAAA,GAAAA,gBAAgB,CAACY,IAAjB,CAAsB,IAAtB,CAJP,CADK,CAAP,CAAA;AAQD,GAAA;AACF;;;;"}
@@ -1,32 +1,15 @@
1
- import IntlError, { IntlErrorCode } from './use-intl.esm7.js';
1
+ import { useContext } from 'react';
2
+ import IntlContext from './use-intl.esm9.js';
2
3
 
3
- function validateMessagesSegment(messages, invalidKeyLabels, parentPath) {
4
- Object.entries(messages).forEach(function (_ref) {
5
- var key = _ref[0],
6
- messageOrMessages = _ref[1];
4
+ function useIntlContext() {
5
+ var context = useContext(IntlContext);
7
6
 
8
- if (key.includes('.')) {
9
- var keyLabel = key;
10
- if (parentPath) keyLabel += " (at " + parentPath + ")";
11
- invalidKeyLabels.push(keyLabel);
12
- }
13
-
14
- if (messageOrMessages != null && typeof messageOrMessages === 'object') {
15
- validateMessagesSegment(messageOrMessages, invalidKeyLabels, [parentPath, key].filter(function (part) {
16
- return part != null;
17
- }).join('.'));
18
- }
19
- });
20
- }
21
-
22
- function validateMessages(messages, onError) {
23
- var invalidKeyLabels = [];
24
- validateMessagesSegment(messages, invalidKeyLabels);
25
-
26
- if (invalidKeyLabels.length > 0) {
27
- onError(new IntlError(IntlErrorCode.INVALID_KEY, "Namespace keys can not contain the character \".\" as this is used to express nesting. Please remove it or replace it with another character.\n\nInvalid " + (invalidKeyLabels.length === 1 ? 'key' : 'keys') + ": " + invalidKeyLabels.join(', ')));
7
+ if (!context) {
8
+ throw new Error(process.env.NODE_ENV !== "production" ? 'No intl context found. Have you configured the provider?' : undefined);
28
9
  }
10
+
11
+ return context;
29
12
  }
30
13
 
31
- export { validateMessages as default };
14
+ export { useIntlContext as default };
32
15
  //# sourceMappingURL=use-intl.esm11.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-intl.esm11.js","sources":["../src/validateMessages.tsx"],"sourcesContent":["import AbstractIntlMessages from './AbstractIntlMessages';\nimport IntlError, {IntlErrorCode} from './IntlError';\n\nfunction validateMessagesSegment(\n messages: AbstractIntlMessages,\n invalidKeyLabels: Array<string>,\n parentPath?: string\n) {\n Object.entries(messages).forEach(([key, messageOrMessages]) => {\n if (key.includes('.')) {\n let keyLabel = key;\n if (parentPath) keyLabel += ` (at ${parentPath})`;\n invalidKeyLabels.push(keyLabel);\n }\n\n if (messageOrMessages != null && typeof messageOrMessages === 'object') {\n validateMessagesSegment(\n messageOrMessages,\n invalidKeyLabels,\n [parentPath, key].filter((part) => part != null).join('.')\n );\n }\n });\n}\n\nexport default function validateMessages(\n messages: AbstractIntlMessages,\n onError: (error: IntlError) => void\n) {\n const invalidKeyLabels: Array<string> = [];\n validateMessagesSegment(messages, invalidKeyLabels);\n\n if (invalidKeyLabels.length > 0) {\n onError(\n new IntlError(\n IntlErrorCode.INVALID_KEY,\n `Namespace keys can not contain the character \".\" as this is used to express nesting. Please remove it or replace it with another character.\\n\\nInvalid ${\n invalidKeyLabels.length === 1 ? 'key' : 'keys'\n }: ${invalidKeyLabels.join(', ')}`\n )\n );\n }\n}\n"],"names":["validateMessagesSegment","messages","invalidKeyLabels","parentPath","Object","entries","forEach","key","messageOrMessages","includes","keyLabel","push","filter","part","join","validateMessages","onError","length","IntlError","IntlErrorCode","INVALID_KEY"],"mappings":";;AAGA,SAASA,uBAAT,CACEC,QADF,EAEEC,gBAFF,EAGEC,UAHF,EAGqB;AAEnBC,EAAAA,MAAM,CAACC,OAAP,CAAeJ,QAAf,CAAyBK,CAAAA,OAAzB,CAAiC,UAA6B,IAAA,EAAA;AAAA,IAAA,IAA3BC,GAA2B,GAAA,IAAA,CAAA,CAAA,CAAA;AAAA,QAAtBC,iBAAsB,GAAA,IAAA,CAAA,CAAA,CAAA,CAAA;;AAC5D,IAAA,IAAID,GAAG,CAACE,QAAJ,CAAa,GAAb,CAAJ,EAAuB;AACrB,MAAIC,IAAAA,QAAQ,GAAGH,GAAf,CAAA;AACA,MAAA,IAAIJ,UAAJ,EAAgBO,QAAQ,IAAA,OAAA,GAAYP,UAAZ,GAAR,GAAA,CAAA;AAChBD,MAAAA,gBAAgB,CAACS,IAAjB,CAAsBD,QAAtB,CAAA,CAAA;AACD,KAAA;;AAED,IAAIF,IAAAA,iBAAiB,IAAI,IAArB,IAA6B,OAAOA,iBAAP,KAA6B,QAA9D,EAAwE;AACtER,MAAAA,uBAAuB,CACrBQ,iBADqB,EAErBN,gBAFqB,EAGrB,CAACC,UAAD,EAAaI,GAAb,CAAA,CAAkBK,MAAlB,CAAyB,UAACC,IAAD,EAAA;AAAA,QAAUA,OAAAA,IAAI,IAAI,IAAlB,CAAA;AAAA,OAAzB,CAAiDC,CAAAA,IAAjD,CAAsD,GAAtD,CAHqB,CAAvB,CAAA;AAKD,KAAA;AACF,GAdD,CAAA,CAAA;AAeD,CAAA;;AAEa,SAAUC,gBAAV,CACZd,QADY,EAEZe,OAFY,EAEuB;AAEnC,EAAMd,IAAAA,gBAAgB,GAAkB,EAAxC,CAAA;AACAF,EAAAA,uBAAuB,CAACC,QAAD,EAAWC,gBAAX,CAAvB,CAAA;;AAEA,EAAA,IAAIA,gBAAgB,CAACe,MAAjB,GAA0B,CAA9B,EAAiC;AAC/BD,IAAAA,OAAO,CACL,IAAIE,SAAJ,CACEC,aAAa,CAACC,WADhB,EAAA,2JAAA,IAGIlB,gBAAgB,CAACe,MAAjB,KAA4B,CAA5B,GAAgC,KAAhC,GAAwC,MAH5C,CAIOf,GAAAA,IAAAA,GAAAA,gBAAgB,CAACY,IAAjB,CAAsB,IAAtB,CAJP,CADK,CAAP,CAAA;AAQD,GAAA;AACF;;;;"}
1
+ {"version":3,"file":"use-intl.esm11.js","sources":["../src/useIntlContext.tsx"],"sourcesContent":["import {useContext} from 'react';\nimport IntlContext from './IntlContext';\n\nexport default function useIntlContext() {\n const context = useContext(IntlContext);\n\n if (!context) {\n throw new Error(\n __DEV__\n ? 'No intl context found. Have you configured the provider?'\n : undefined\n );\n }\n\n return context;\n}\n"],"names":["useIntlContext","context","useContext","IntlContext","Error","undefined"],"mappings":";;;AAGc,SAAUA,cAAV,GAAwB;AACpC,EAAA,IAAMC,OAAO,GAAGC,UAAU,CAACC,WAAD,CAA1B,CAAA;;AAEA,EAAI,IAAA,CAACF,OAAL,EAAc;AACZ,IAAA,MAAM,IAAIG,KAAJ,CACJ,wCACI,0DADJ,GAEIC,SAHA,CAAN,CAAA;AAKD,GAAA;;AAED,EAAA,OAAOJ,OAAP,CAAA;AACD;;;;"}
@@ -1,6 +1,213 @@
1
- import { createContext } from 'react';
1
+ import { extends as _extends } from './_virtual/use-intl.esm.js';
2
+ import { IntlMessageFormat } from 'intl-messageformat';
3
+ import { useRef, useMemo, isValidElement, cloneElement } from 'react';
4
+ import IntlError, { IntlErrorCode } from './use-intl.esm8.js';
5
+ import convertFormatsToIntlMessageFormat from './use-intl.esm13.js';
6
+ import useIntlContext from './use-intl.esm11.js';
2
7
 
3
- var IntlContext = /*#__PURE__*/createContext(undefined);
8
+ function resolvePath(messages, idPath, namespace) {
9
+ if (!messages) {
10
+ throw new Error(process.env.NODE_ENV !== "production" ? "No messages available at `" + namespace + "`." : undefined);
11
+ }
4
12
 
5
- export { IntlContext as default };
13
+ var message = messages;
14
+ idPath.split('.').forEach(function (part) {
15
+ var next = message[part];
16
+
17
+ if (part == null || next == null) {
18
+ throw new Error(process.env.NODE_ENV !== "production" ? "Could not resolve `" + idPath + "` in " + (namespace ? "`" + namespace + "`" : 'messages') + "." : undefined);
19
+ }
20
+
21
+ message = next;
22
+ });
23
+ return message;
24
+ }
25
+
26
+ function prepareTranslationValues(values) {
27
+ if (Object.keys(values).length === 0) return undefined; // Workaround for https://github.com/formatjs/formatjs/issues/1467
28
+
29
+ var transformedValues = {};
30
+ Object.keys(values).forEach(function (key) {
31
+ var index = 0;
32
+ var value = values[key];
33
+ var transformed;
34
+
35
+ if (typeof value === 'function') {
36
+ transformed = function transformed(children) {
37
+ var result = value(children);
38
+ return isValidElement(result) ? cloneElement(result, {
39
+ key: key + index++
40
+ }) : result;
41
+ };
42
+ } else {
43
+ transformed = value;
44
+ }
45
+
46
+ transformedValues[key] = transformed;
47
+ });
48
+ return transformedValues;
49
+ }
50
+
51
+ function useTranslationsImpl(allMessages, namespace, namespacePrefix) {
52
+ var _useIntlContext = useIntlContext(),
53
+ defaultTranslationValues = _useIntlContext.defaultTranslationValues,
54
+ globalFormats = _useIntlContext.formats,
55
+ getMessageFallback = _useIntlContext.getMessageFallback,
56
+ locale = _useIntlContext.locale,
57
+ onError = _useIntlContext.onError,
58
+ timeZone = _useIntlContext.timeZone; // The `namespacePrefix` is part of the type system.
59
+ // See the comment in the hook invocation.
60
+
61
+
62
+ allMessages = allMessages[namespacePrefix];
63
+ namespace = namespace === namespacePrefix ? undefined : namespace.slice((namespacePrefix + '.').length);
64
+ var cachedFormatsByLocaleRef = useRef({});
65
+ var messagesOrError = useMemo(function () {
66
+ try {
67
+ if (!allMessages) {
68
+ throw new Error(process.env.NODE_ENV !== "production" ? "No messages were configured on the provider." : undefined);
69
+ }
70
+
71
+ var retrievedMessages = namespace ? resolvePath(allMessages, namespace) : allMessages;
72
+
73
+ if (!retrievedMessages) {
74
+ throw new Error(process.env.NODE_ENV !== "production" ? "No messages for namespace `" + namespace + "` found." : undefined);
75
+ }
76
+
77
+ return retrievedMessages;
78
+ } catch (error) {
79
+ var intlError = new IntlError(IntlErrorCode.MISSING_MESSAGE, error.message);
80
+ onError(intlError);
81
+ return intlError;
82
+ }
83
+ }, [allMessages, namespace, onError]);
84
+ var translate = useMemo(function () {
85
+ function getFallbackFromErrorAndNotify(key, code, message) {
86
+ var error = new IntlError(code, message);
87
+ onError(error);
88
+ return getMessageFallback({
89
+ error: error,
90
+ key: key,
91
+ namespace: namespace
92
+ });
93
+ }
94
+
95
+ function translateBaseFn(
96
+ /** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */
97
+ key,
98
+ /** Key value pairs for values to interpolate into the message. */
99
+ values,
100
+ /** Provide custom formats for numbers, dates and times. */
101
+ formats) {
102
+ var _cachedFormatsByLocal;
103
+
104
+ var cachedFormatsByLocale = cachedFormatsByLocaleRef.current;
105
+
106
+ if (messagesOrError instanceof IntlError) {
107
+ // We have already warned about this during render
108
+ return getMessageFallback({
109
+ error: messagesOrError,
110
+ key: key,
111
+ namespace: namespace
112
+ });
113
+ }
114
+
115
+ var messages = messagesOrError;
116
+ var cacheKey = [namespace, key].filter(function (part) {
117
+ return part != null;
118
+ }).join('.');
119
+ var messageFormat;
120
+
121
+ if ((_cachedFormatsByLocal = cachedFormatsByLocale[locale]) != null && _cachedFormatsByLocal[cacheKey]) {
122
+ messageFormat = cachedFormatsByLocale[locale][cacheKey];
123
+ } else {
124
+ var message;
125
+
126
+ try {
127
+ message = resolvePath(messages, key, namespace);
128
+ } catch (error) {
129
+ return getFallbackFromErrorAndNotify(key, IntlErrorCode.MISSING_MESSAGE, error.message);
130
+ }
131
+
132
+ if (typeof message === 'object') {
133
+ return getFallbackFromErrorAndNotify(key, IntlErrorCode.INSUFFICIENT_PATH, process.env.NODE_ENV !== "production" ? "Insufficient path specified for `" + key + "` in `" + (namespace ? "`" + namespace + "`" : 'messages') + "`." : undefined);
134
+ }
135
+
136
+ try {
137
+ messageFormat = new IntlMessageFormat(message, locale, convertFormatsToIntlMessageFormat(_extends({}, globalFormats, formats), timeZone));
138
+ } catch (error) {
139
+ return getFallbackFromErrorAndNotify(key, IntlErrorCode.INVALID_MESSAGE, error.message);
140
+ }
141
+
142
+ if (!cachedFormatsByLocale[locale]) {
143
+ cachedFormatsByLocale[locale] = {};
144
+ }
145
+
146
+ cachedFormatsByLocale[locale][cacheKey] = messageFormat;
147
+ }
148
+
149
+ try {
150
+ var formattedMessage = messageFormat.format( // @ts-ignore `intl-messageformat` expects a different format
151
+ // for rich text elements since a recent minor update. This
152
+ // needs to be evaluated in detail, possibly also in regards
153
+ // to be able to format to parts.
154
+ prepareTranslationValues(_extends({}, defaultTranslationValues, values)));
155
+
156
+ if (formattedMessage == null) {
157
+ throw new Error(process.env.NODE_ENV !== "production" ? "Unable to format `" + key + "` in " + (namespace ? "namespace `" + namespace + "`" : 'messages') : undefined);
158
+ } // Limit the function signature to return strings or React elements
159
+
160
+
161
+ return isValidElement(formattedMessage) || // Arrays of React elements
162
+ Array.isArray(formattedMessage) || typeof formattedMessage === 'string' ? formattedMessage : String(formattedMessage);
163
+ } catch (error) {
164
+ return getFallbackFromErrorAndNotify(key, IntlErrorCode.FORMATTING_ERROR, error.message);
165
+ }
166
+ }
167
+
168
+ function translateFn(
169
+ /** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */
170
+ key,
171
+ /** Key value pairs for values to interpolate into the message. */
172
+ values,
173
+ /** Provide custom formats for numbers, dates and times. */
174
+ formats) {
175
+ var message = translateBaseFn(key, values, formats);
176
+
177
+ if (typeof message !== 'string') {
178
+ return getFallbackFromErrorAndNotify(key, IntlErrorCode.INVALID_MESSAGE, process.env.NODE_ENV !== "production" ? "The message `" + key + "` in " + (namespace ? "namespace `" + namespace + "`" : 'messages') + " didn't resolve to a string. If you want to format rich text, use `t.rich` instead." : undefined);
179
+ }
180
+
181
+ return message;
182
+ }
183
+
184
+ translateFn.rich = translateBaseFn;
185
+
186
+ translateFn.raw = function (
187
+ /** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */
188
+ key) {
189
+ if (messagesOrError instanceof IntlError) {
190
+ // We have already warned about this during render
191
+ return getMessageFallback({
192
+ error: messagesOrError,
193
+ key: key,
194
+ namespace: namespace
195
+ });
196
+ }
197
+
198
+ var messages = messagesOrError;
199
+
200
+ try {
201
+ return resolvePath(messages, key, namespace);
202
+ } catch (error) {
203
+ return getFallbackFromErrorAndNotify(key, IntlErrorCode.MISSING_MESSAGE, error.message);
204
+ }
205
+ };
206
+
207
+ return translateFn;
208
+ }, [onError, getMessageFallback, namespace, messagesOrError, locale, globalFormats, timeZone, defaultTranslationValues]);
209
+ return translate;
210
+ }
211
+
212
+ export { useTranslationsImpl as default };
6
213
  //# sourceMappingURL=use-intl.esm12.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-intl.esm12.js","sources":["../src/IntlContext.tsx"],"sourcesContent":["import {createContext} from 'react';\nimport AbstractIntlMessages from './AbstractIntlMessages';\nimport Formats from './Formats';\nimport IntlError from './IntlError';\nimport {RichTranslationValues} from './TranslationValues';\n\nexport type IntlContextShape = {\n messages?: AbstractIntlMessages;\n locale: string;\n formats?: Partial<Formats>;\n timeZone?: string;\n onError(error: IntlError): void;\n getMessageFallback(info: {\n error: IntlError;\n key: string;\n namespace?: string;\n }): string;\n now?: Date;\n defaultTranslationValues?: RichTranslationValues;\n};\n\nconst IntlContext = createContext<IntlContextShape | undefined>(undefined);\n\nexport default IntlContext;\n"],"names":["IntlContext","createContext","undefined"],"mappings":";;AAqBA,IAAMA,WAAW,gBAAGC,aAAa,CAA+BC,SAA/B;;;;"}
1
+ {"version":3,"file":"use-intl.esm12.js","sources":["../src/useTranslationsImpl.tsx"],"sourcesContent":["import {IntlMessageFormat} from 'intl-messageformat';\nimport {\n cloneElement,\n isValidElement,\n ReactElement,\n ReactNode,\n ReactNodeArray,\n useMemo,\n useRef\n} from 'react';\nimport AbstractIntlMessages from './AbstractIntlMessages';\nimport Formats from './Formats';\nimport IntlError, {IntlErrorCode} from './IntlError';\nimport TranslationValues, {RichTranslationValues} from './TranslationValues';\nimport convertFormatsToIntlMessageFormat from './convertFormatsToIntlMessageFormat';\nimport useIntlContext from './useIntlContext';\nimport MessageKeys from './utils/MessageKeys';\nimport NestedKeyOf from './utils/NestedKeyOf';\nimport NestedValueOf from './utils/NestedValueOf';\n\nfunction resolvePath(\n messages: AbstractIntlMessages | undefined,\n idPath: string,\n namespace?: string\n) {\n if (!messages) {\n throw new Error(\n __DEV__ ? `No messages available at \\`${namespace}\\`.` : undefined\n );\n }\n\n let message = messages;\n\n idPath.split('.').forEach((part) => {\n const next = (message as any)[part];\n\n if (part == null || next == null) {\n throw new Error(\n __DEV__\n ? `Could not resolve \\`${idPath}\\` 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 = (children: ReactNode) => {\n const result = value(children);\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 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 = (\n namespace === namespacePrefix\n ? undefined\n : namespace.slice((namespacePrefix + '.').length)\n ) as NestedKey;\n\n const cachedFormatsByLocaleRef = useRef<\n Record<string, Record<string, IntlMessageFormat>>\n >({});\n\n const messagesOrError = useMemo(() => {\n try {\n if (!allMessages) {\n throw new Error(\n __DEV__ ? `No messages were configured on the provider.` : undefined\n );\n }\n\n const retrievedMessages = namespace\n ? resolvePath(allMessages, namespace)\n : allMessages;\n\n if (!retrievedMessages) {\n throw new Error(\n __DEV__\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 }, [allMessages, namespace, onError]);\n\n const translate = useMemo(() => {\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 const cachedFormatsByLocale = cachedFormatsByLocaleRef.current;\n\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 const cacheKey = [namespace, key]\n .filter((part) => part != null)\n .join('.');\n\n let messageFormat;\n if (cachedFormatsByLocale[locale]?.[cacheKey]) {\n messageFormat = cachedFormatsByLocale[locale][cacheKey];\n } else {\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 if (typeof message === 'object') {\n return getFallbackFromErrorAndNotify(\n key,\n IntlErrorCode.INSUFFICIENT_PATH,\n __DEV__\n ? `Insufficient path specified for \\`${key}\\` in \\`${\n namespace ? `\\`${namespace}\\`` : 'messages'\n }\\`.`\n : undefined\n );\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[locale]) {\n cachedFormatsByLocale[locale] = {};\n }\n cachedFormatsByLocale[locale][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 __DEV__\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 message = translateBaseFn(key, values, formats);\n\n if (typeof message !== 'string') {\n return getFallbackFromErrorAndNotify(\n key,\n IntlErrorCode.INVALID_MESSAGE,\n __DEV__\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 message;\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 onError,\n getMessageFallback,\n namespace,\n messagesOrError,\n locale,\n globalFormats,\n timeZone,\n defaultTranslationValues\n ]);\n\n return translate;\n}\n"],"names":["resolvePath","messages","idPath","namespace","Error","undefined","message","split","forEach","part","next","prepareTranslationValues","values","Object","keys","length","transformedValues","key","index","value","transformed","children","result","isValidElement","cloneElement","useTranslationsImpl","allMessages","namespacePrefix","useIntlContext","defaultTranslationValues","globalFormats","formats","getMessageFallback","locale","onError","timeZone","slice","cachedFormatsByLocaleRef","useRef","messagesOrError","useMemo","retrievedMessages","error","intlError","IntlError","IntlErrorCode","MISSING_MESSAGE","translate","getFallbackFromErrorAndNotify","code","translateBaseFn","cachedFormatsByLocale","current","cacheKey","filter","join","messageFormat","INSUFFICIENT_PATH","IntlMessageFormat","convertFormatsToIntlMessageFormat","INVALID_MESS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