@depup/use-intl 4.13.3-depup.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.
Files changed (69) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +33 -0
  3. package/changes.json +18 -0
  4. package/core.d.ts +2 -0
  5. package/dist/esm/development/core.js +76 -0
  6. package/dist/esm/development/format-message/format-only.js +145 -0
  7. package/dist/esm/development/format-message/index.js +138 -0
  8. package/dist/esm/development/formatters-r4aAmsMP.js +79 -0
  9. package/dist/esm/development/index.js +8 -0
  10. package/dist/esm/development/initializeConfig-CUsOI8u2.js +527 -0
  11. package/dist/esm/development/react.js +231 -0
  12. package/dist/esm/production/core.js +1 -0
  13. package/dist/esm/production/format-message/format-only.js +1 -0
  14. package/dist/esm/production/format-message/index.js +1 -0
  15. package/dist/esm/production/formatters-CJcico0N.js +1 -0
  16. package/dist/esm/production/index.js +1 -0
  17. package/dist/esm/production/initializeConfig-CHgjheii.js +1 -0
  18. package/dist/esm/production/react.js +1 -0
  19. package/dist/types/core/AbstractIntlMessages.d.ts +10 -0
  20. package/dist/types/core/AppConfig.d.ts +29 -0
  21. package/dist/types/core/DateTimeFormatOptions.d.ts +73 -0
  22. package/dist/types/core/Formats.d.ts +9 -0
  23. package/dist/types/core/ICUArgs.d.ts +3 -0
  24. package/dist/types/core/ICUTags.d.ts +2 -0
  25. package/dist/types/core/IntlConfig.d.ts +54 -0
  26. package/dist/types/core/IntlError.d.ts +6 -0
  27. package/dist/types/core/IntlErrorCode.d.ts +10 -0
  28. package/dist/types/core/MessageKeys.d.ts +10 -0
  29. package/dist/types/core/NumberFormatOptions.d.ts +3 -0
  30. package/dist/types/core/RelativeTimeFormatOptions.d.ts +7 -0
  31. package/dist/types/core/TimeZone.d.ts +2 -0
  32. package/dist/types/core/TranslationValues.d.ts +6 -0
  33. package/dist/types/core/convertFormatsToIntlMessageFormat.d.ts +11 -0
  34. package/dist/types/core/createBaseTranslator.d.ts +21 -0
  35. package/dist/types/core/createFormatter.d.ts +47 -0
  36. package/dist/types/core/createTranslator.d.ts +59 -0
  37. package/dist/types/core/createTranslatorImpl.d.ts +17 -0
  38. package/dist/types/core/defaults.d.ts +11 -0
  39. package/dist/types/core/format-message/compile-format.d.ts +12 -0
  40. package/dist/types/core/format-message/format-only.d.ts +13 -0
  41. package/dist/types/core/format-message/index.d.ts +5 -0
  42. package/dist/types/core/format-message/types.d.ts +15 -0
  43. package/dist/types/core/formatters.d.ts +25 -0
  44. package/dist/types/core/hasLocale.d.ts +7 -0
  45. package/dist/types/core/index.d.ts +22 -0
  46. package/dist/types/core/initializeConfig.d.ts +14 -0
  47. package/dist/types/core/joinPath.d.ts +1 -0
  48. package/dist/types/core/resolveNamespace.d.ts +5 -0
  49. package/dist/types/core/types.d.ts +6 -0
  50. package/dist/types/core/validateMessages.d.ts +3 -0
  51. package/dist/types/core.d.ts +1 -0
  52. package/dist/types/index.d.ts +2 -0
  53. package/dist/types/react/IntlContext.d.ts +8 -0
  54. package/dist/types/react/IntlProvider.d.ts +7 -0
  55. package/dist/types/react/index.d.ts +9 -0
  56. package/dist/types/react/useExtracted.d.ts +42 -0
  57. package/dist/types/react/useFormatter.d.ts +2 -0
  58. package/dist/types/react/useIntlContext.d.ts +2 -0
  59. package/dist/types/react/useLocale.d.ts +2 -0
  60. package/dist/types/react/useMessages.d.ts +2 -0
  61. package/dist/types/react/useNow.d.ts +8 -0
  62. package/dist/types/react/useTimeZone.d.ts +1 -0
  63. package/dist/types/react/useTranslations.d.ts +12 -0
  64. package/dist/types/react/useTranslationsImpl.d.ts +9 -0
  65. package/dist/types/react.d.ts +1 -0
  66. package/format-message/format-only.d.ts +2 -0
  67. package/format-message.d.ts +2 -0
  68. package/package.json +115 -0
  69. package/react.d.ts +2 -0
@@ -0,0 +1,527 @@
1
+ import { cloneElement, isValidElement } from 'react';
2
+ import formatMessage from 'use-intl/format-message';
3
+ import { I as IntlError, a as IntlErrorCode, c as createIntlFormatters, b as createCache } from './formatters-r4aAmsMP.js';
4
+
5
+ function joinPath(...parts) {
6
+ return parts.filter(Boolean).join('.');
7
+ }
8
+
9
+ /**
10
+ * Contains defaults that are used for all entry points into the core.
11
+ * See also `InitializedIntlConfiguration`.
12
+ */
13
+
14
+ function defaultGetMessageFallback(props) {
15
+ return joinPath(props.namespace, props.key);
16
+ }
17
+ function defaultOnError(error) {
18
+ console.error(error);
19
+ }
20
+
21
+ function prepareTranslationValues(values) {
22
+ // Related to https://github.com/formatjs/formatjs/issues/1467
23
+ const transformedValues = {};
24
+ Object.keys(values).forEach(key => {
25
+ let index = 0;
26
+ const value = values[key];
27
+ let transformed;
28
+ if (typeof value === 'function') {
29
+ transformed = chunks => {
30
+ const result = value(chunks);
31
+ return /*#__PURE__*/isValidElement(result) ? /*#__PURE__*/cloneElement(result, {
32
+ key: key + index++
33
+ }) : result;
34
+ };
35
+ } else {
36
+ transformed = value;
37
+ }
38
+ transformedValues[key] = transformed;
39
+ });
40
+ return transformedValues;
41
+ }
42
+ function resolvePath(locale, messages, key, namespace) {
43
+ const fullKey = joinPath(namespace, key);
44
+ if (!messages) {
45
+ throw new Error(`No messages available at \`${namespace}\`.` );
46
+ }
47
+ let message = messages;
48
+ key.split('.').forEach(part => {
49
+ const next = message[part];
50
+
51
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
52
+ if (part == null || next == null) {
53
+ throw new Error(`Could not resolve \`${fullKey}\` in messages for locale \`${locale}\`.` );
54
+ }
55
+ message = next;
56
+ });
57
+ return message;
58
+ }
59
+ function getMessagesOrError(locale, messages, namespace) {
60
+ try {
61
+ if (!messages) {
62
+ throw new Error(`No messages were configured.` );
63
+ }
64
+ const retrievedMessages = namespace ? resolvePath(locale, messages, namespace) : messages;
65
+
66
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
67
+ if (!retrievedMessages) {
68
+ throw new Error(`No messages for namespace \`${namespace}\` found.` );
69
+ }
70
+ return retrievedMessages;
71
+ } catch (error) {
72
+ const intlError = new IntlError(IntlErrorCode.MISSING_MESSAGE, error.message);
73
+ return intlError;
74
+ }
75
+ }
76
+ function createBaseTranslator(config) {
77
+ const messagesOrError = getMessagesOrError(config.locale, config.messages, config.namespace);
78
+ return createBaseTranslatorImpl({
79
+ ...config,
80
+ messagesOrError
81
+ });
82
+ }
83
+ function createBaseTranslatorImpl({
84
+ cache,
85
+ formats: globalFormats,
86
+ formatters,
87
+ getMessageFallback = defaultGetMessageFallback,
88
+ locale,
89
+ messagesOrError,
90
+ namespace,
91
+ onError,
92
+ timeZone
93
+ }) {
94
+ const hasMessagesError = messagesOrError instanceof IntlError;
95
+ function getFallbackFromErrorAndNotify(key, code, message, fallback) {
96
+ const error = new IntlError(code, message);
97
+ onError(error);
98
+ return fallback ?? getMessageFallback({
99
+ error,
100
+ key,
101
+ namespace
102
+ });
103
+ }
104
+ function translateBaseFn(/** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */
105
+ key, /** Key value pairs for values to interpolate into the message. */
106
+ values, /** Provide custom formats for numbers, dates and times. */
107
+ formats, _fallback) {
108
+ const fallback = _fallback;
109
+ let message;
110
+ if (hasMessagesError) {
111
+ if (fallback) {
112
+ message = fallback;
113
+ } else {
114
+ onError(messagesOrError);
115
+ return getMessageFallback({
116
+ error: messagesOrError,
117
+ key,
118
+ namespace
119
+ });
120
+ }
121
+ } else {
122
+ const messages = messagesOrError;
123
+ try {
124
+ message = resolvePath(locale, messages, key, namespace);
125
+ } catch (error) {
126
+ if (fallback) {
127
+ message = fallback;
128
+ } else {
129
+ return getFallbackFromErrorAndNotify(key, IntlErrorCode.MISSING_MESSAGE, error.message, fallback);
130
+ }
131
+ }
132
+ }
133
+ try {
134
+ const messagePath = joinPath(namespace, key);
135
+ return formatMessage(messagePath,
136
+ // @ts-expect-error -- We have additional validation either in `compile-format.tsx` or in case of `format-only.tsx` in the loader
137
+ message, values ? prepareTranslationValues(values) : values, {
138
+ cache,
139
+ formatters,
140
+ globalFormats,
141
+ formats,
142
+ locale,
143
+ timeZone
144
+ });
145
+ } catch (error) {
146
+ let errorCode, errorMessage;
147
+ if (error instanceof IntlError) {
148
+ errorCode = error.code;
149
+ errorMessage = error.originalMessage;
150
+ } else {
151
+ errorCode = IntlErrorCode.FORMATTING_ERROR;
152
+ errorMessage = error.message;
153
+ }
154
+ return getFallbackFromErrorAndNotify(key, errorCode, errorMessage, fallback);
155
+ }
156
+ }
157
+ function translateFn(/** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */
158
+ key, /** Key value pairs for values to interpolate into the message. */
159
+ values, /** Custom formats for numbers, dates and times. */
160
+ formats, _fallback) {
161
+ const result = translateBaseFn(key, values, formats, _fallback);
162
+ if (typeof result !== 'string') {
163
+ return getFallbackFromErrorAndNotify(key, IntlErrorCode.INVALID_MESSAGE, `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.` );
164
+ }
165
+ return result;
166
+ }
167
+ translateFn.rich = translateBaseFn;
168
+
169
+ // Augment `translateBaseFn` to return plain strings
170
+ translateFn.markup = (key, values, formats, _fallback) => {
171
+ const result = translateBaseFn(key,
172
+ // @ts-expect-error -- `MarkupTranslationValues` is practically a sub type
173
+ // of `RichTranslationValues` but TypeScript isn't smart enough here.
174
+ values, formats, _fallback);
175
+ if (typeof result !== 'string') {
176
+ const error = new IntlError(IntlErrorCode.FORMATTING_ERROR, "`t.markup` only accepts functions for formatting that receive and return strings.\n\nE.g. t.markup('markup', {b: (chunks) => `<b>${chunks}</b>`})");
177
+ onError(error);
178
+ return getMessageFallback({
179
+ error,
180
+ key,
181
+ namespace
182
+ });
183
+ }
184
+ return result;
185
+ };
186
+ translateFn.raw = key => {
187
+ {
188
+ if (!formatMessage.raw) {
189
+ throw new Error('`t.raw` is not supported when messages are precompiled.');
190
+ }
191
+ }
192
+ if (hasMessagesError) {
193
+ onError(messagesOrError);
194
+ return getMessageFallback({
195
+ error: messagesOrError,
196
+ key,
197
+ namespace
198
+ });
199
+ }
200
+ const messages = messagesOrError;
201
+ try {
202
+ return resolvePath(locale, messages, key, namespace);
203
+ } catch (error) {
204
+ return getFallbackFromErrorAndNotify(key, IntlErrorCode.MISSING_MESSAGE, error.message);
205
+ }
206
+ };
207
+ translateFn.has = key => {
208
+ if (hasMessagesError) {
209
+ return false;
210
+ }
211
+ try {
212
+ resolvePath(locale, messagesOrError, key, namespace);
213
+ return true;
214
+ } catch {
215
+ return false;
216
+ }
217
+ };
218
+ return translateFn;
219
+ }
220
+
221
+ /**
222
+ * For the strictly typed messages to work we have to wrap the namespace into
223
+ * a mandatory prefix. See https://stackoverflow.com/a/71529575/343045
224
+ */
225
+ function resolveNamespace(namespace, namespacePrefix) {
226
+ return namespace === namespacePrefix ? undefined : namespace.slice((namespacePrefix + '.').length);
227
+ }
228
+
229
+ const SECOND = 1;
230
+ const MINUTE = SECOND * 60;
231
+ const HOUR = MINUTE * 60;
232
+ const DAY = HOUR * 24;
233
+ const WEEK = DAY * 7;
234
+ const MONTH = DAY * (365 / 12); // Approximation
235
+ const QUARTER = MONTH * 3;
236
+ const YEAR = DAY * 365;
237
+ const UNIT_SECONDS = {
238
+ second: SECOND,
239
+ seconds: SECOND,
240
+ minute: MINUTE,
241
+ minutes: MINUTE,
242
+ hour: HOUR,
243
+ hours: HOUR,
244
+ day: DAY,
245
+ days: DAY,
246
+ week: WEEK,
247
+ weeks: WEEK,
248
+ month: MONTH,
249
+ months: MONTH,
250
+ quarter: QUARTER,
251
+ quarters: QUARTER,
252
+ year: YEAR,
253
+ years: YEAR
254
+ };
255
+ function resolveRelativeTimeUnit(seconds) {
256
+ const absValue = Math.abs(seconds);
257
+ if (absValue < MINUTE) {
258
+ return 'second';
259
+ } else if (absValue < HOUR) {
260
+ return 'minute';
261
+ } else if (absValue < DAY) {
262
+ return 'hour';
263
+ } else if (absValue < WEEK) {
264
+ return 'day';
265
+ } else if (absValue < MONTH) {
266
+ return 'week';
267
+ } else if (absValue < YEAR) {
268
+ return 'month';
269
+ }
270
+ return 'year';
271
+ }
272
+ function calculateRelativeTimeValue(seconds, unit) {
273
+ // We have to round the resulting values, as `Intl.RelativeTimeFormat`
274
+ // will include fractions like '2.1 hours ago'.
275
+ return Math.round(seconds / UNIT_SECONDS[unit]);
276
+ }
277
+ function createFormatter(props) {
278
+ const {
279
+ _cache: cache = createCache(),
280
+ _formatters: formatters = createIntlFormatters(cache),
281
+ formats,
282
+ locale,
283
+ onError = defaultOnError,
284
+ timeZone: globalTimeZone
285
+ } = props;
286
+ function applyTimeZone(options) {
287
+ if (!options?.timeZone) {
288
+ if (globalTimeZone) {
289
+ options = {
290
+ ...options,
291
+ timeZone: globalTimeZone
292
+ };
293
+ } else {
294
+ onError(new IntlError(IntlErrorCode.ENVIRONMENT_FALLBACK, `The \`timeZone\` parameter wasn't provided and there is no global default configured. Consider adding a global default to avoid markup mismatches caused by environment differences. Learn more: https://next-intl.dev/docs/configuration#time-zone` ));
295
+ }
296
+ }
297
+ return options;
298
+ }
299
+ function resolveFormatOrOptions(typeFormats, formatOrOptions, overrides) {
300
+ let options;
301
+ if (typeof formatOrOptions === 'string') {
302
+ const formatName = formatOrOptions;
303
+ options = typeFormats?.[formatName];
304
+ if (!options) {
305
+ const error = new IntlError(IntlErrorCode.MISSING_FORMAT, `Format \`${formatName}\` is not available.` );
306
+ onError(error);
307
+ throw error;
308
+ }
309
+ } else {
310
+ options = formatOrOptions;
311
+ }
312
+ if (overrides) {
313
+ options = {
314
+ ...options,
315
+ ...overrides
316
+ };
317
+ }
318
+ return options;
319
+ }
320
+ function getFormattedValue(formatOrOptions, overrides, typeFormats, formatter, getFallback) {
321
+ let options;
322
+ try {
323
+ options = resolveFormatOrOptions(typeFormats, formatOrOptions, overrides);
324
+ } catch {
325
+ return getFallback();
326
+ }
327
+ try {
328
+ return formatter(options);
329
+ } catch (error) {
330
+ onError(new IntlError(IntlErrorCode.FORMATTING_ERROR, error.message));
331
+ return getFallback();
332
+ }
333
+ }
334
+ function dateTime(value, formatOrOptions, overrides) {
335
+ return getFormattedValue(formatOrOptions, overrides, formats?.dateTime, options => {
336
+ options = applyTimeZone(options);
337
+ return formatters.getDateTimeFormat(locale, options).format(value);
338
+ }, () => String(value));
339
+ }
340
+ function dateTimeRange(start, end, formatOrOptions, overrides) {
341
+ return getFormattedValue(formatOrOptions, overrides, formats?.dateTime, options => {
342
+ options = applyTimeZone(options);
343
+ return formatters.getDateTimeFormat(locale, options).formatRange(start, end);
344
+ }, () => [dateTime(start), dateTime(end)].join(' – '));
345
+ }
346
+ function number(value, formatOrOptions, overrides) {
347
+ return getFormattedValue(formatOrOptions, overrides, formats?.number, options => formatters.getNumberFormat(locale, options).format(value), () => String(value));
348
+ }
349
+ function getGlobalNow() {
350
+ // Only read when necessary to avoid triggering a `dynamicIO` error
351
+ // unnecessarily (`now` is only needed for `format.relativeTime`)
352
+ if (props.now) {
353
+ return props.now;
354
+ } else {
355
+ onError(new IntlError(IntlErrorCode.ENVIRONMENT_FALLBACK, `The \`now\` parameter wasn't provided to \`relativeTime\` and there is no global default configured, therefore the current time will be used as a fallback. See https://next-intl.dev/docs/usage/dates-times#relative-times-usenow` ));
356
+ return new Date();
357
+ }
358
+ }
359
+ function relativeTime(date, nowOrOptions) {
360
+ try {
361
+ let nowDate, unit;
362
+ const opts = {};
363
+ if (nowOrOptions instanceof Date || typeof nowOrOptions === 'number') {
364
+ nowDate = new Date(nowOrOptions);
365
+ } else if (nowOrOptions) {
366
+ if (nowOrOptions.now != null) {
367
+ nowDate = new Date(nowOrOptions.now);
368
+ } else {
369
+ nowDate = getGlobalNow();
370
+ }
371
+ unit = nowOrOptions.unit;
372
+ opts.style = nowOrOptions.style;
373
+ // @ts-expect-error -- Types are slightly outdated
374
+ opts.numberingSystem = nowOrOptions.numberingSystem;
375
+ }
376
+ if (!nowDate) {
377
+ nowDate = getGlobalNow();
378
+ }
379
+ const dateDate = new Date(date);
380
+ const seconds = (dateDate.getTime() - nowDate.getTime()) / 1000;
381
+ if (!unit) {
382
+ unit = resolveRelativeTimeUnit(seconds);
383
+ }
384
+
385
+ // `numeric: 'auto'` can theoretically produce output like "yesterday",
386
+ // but it only works with integers. E.g. -1 day will produce "yesterday",
387
+ // but -1.1 days will produce "-1.1 days". Rounding before formatting is
388
+ // not desired, as the given dates might cross a threshold were the
389
+ // output isn't correct anymore. Example: 2024-01-08T23:00:00.000Z and
390
+ // 2024-01-08T01:00:00.000Z would produce "yesterday", which is not the
391
+ // case. By using `always` we can ensure correct output. The only exception
392
+ // is the formatting of times <1 second as "now".
393
+ opts.numeric = unit === 'second' ? 'auto' : 'always';
394
+ const value = calculateRelativeTimeValue(seconds, unit);
395
+ return formatters.getRelativeTimeFormat(locale, opts).format(value, unit);
396
+ } catch (error) {
397
+ onError(new IntlError(IntlErrorCode.FORMATTING_ERROR, error.message));
398
+ return String(date);
399
+ }
400
+ }
401
+ function list(value, formatOrOptions, overrides) {
402
+ const serializedValue = [];
403
+ const richValues = new Map();
404
+
405
+ // `formatToParts` only accepts strings, therefore we have to temporarily
406
+ // replace React elements with a placeholder ID that can be used to retrieve
407
+ // the original value afterwards.
408
+ let index = 0;
409
+ for (const item of value) {
410
+ let serializedItem;
411
+ if (typeof item === 'object') {
412
+ serializedItem = String(index);
413
+ richValues.set(serializedItem, item);
414
+ } else {
415
+ serializedItem = String(item);
416
+ }
417
+ serializedValue.push(serializedItem);
418
+ index++;
419
+ }
420
+ return getFormattedValue(formatOrOptions, overrides, formats?.list,
421
+ // @ts-expect-error -- `richValues.size` is used to determine the return type, but TypeScript can't infer the meaning of this correctly
422
+ options => {
423
+ const result = formatters.getListFormat(locale, options).formatToParts(serializedValue).map(part => part.type === 'literal' ? part.value : richValues.get(part.value) || part.value);
424
+ if (richValues.size > 0) {
425
+ return result;
426
+ } else {
427
+ return result.join('');
428
+ }
429
+ }, () => String(value));
430
+ }
431
+ function displayName(value, formatOrOptions, overrides) {
432
+ return getFormattedValue(formatOrOptions, overrides, formats?.displayName, options =>
433
+ // `options` is guaranteed non-null because our overloads require
434
+ // either inline options or a named format that resolves to options.
435
+ formatters.getDisplayNames(locale, options).of(value), () => value);
436
+ }
437
+ return {
438
+ dateTime,
439
+ number,
440
+ relativeTime,
441
+ list,
442
+ dateTimeRange,
443
+ displayName
444
+ };
445
+ }
446
+
447
+ function validateMessagesSegment(messages, invalidKeyLabels, parentPath) {
448
+ Object.entries(messages).forEach(([key, messageOrMessages]) => {
449
+ if (key.includes('.')) {
450
+ let keyLabel = key;
451
+ if (parentPath) keyLabel += ` (at ${parentPath})`;
452
+ invalidKeyLabels.push(keyLabel);
453
+ }
454
+
455
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
456
+ if (messageOrMessages != null && typeof messageOrMessages === 'object') {
457
+ validateMessagesSegment(messageOrMessages, invalidKeyLabels, joinPath(parentPath, key));
458
+ }
459
+ });
460
+ }
461
+ function validateMessages(messages, onError) {
462
+ const invalidKeyLabels = [];
463
+ validateMessagesSegment(messages, invalidKeyLabels);
464
+ if (invalidKeyLabels.length > 0) {
465
+ onError(new IntlError(IntlErrorCode.INVALID_KEY, `Namespace keys cannot contain the character "." as this is used to express nesting. Please remove it or replace it with another character.
466
+
467
+ Invalid ${invalidKeyLabels.length === 1 ? 'key' : 'keys'}: ${invalidKeyLabels.join(', ')}
468
+
469
+ If you're migrating from a flat structure, you can convert your messages as follows:
470
+
471
+ import {set} from "lodash";
472
+
473
+ const input = {
474
+ "one.one": "1.1",
475
+ "one.two": "1.2",
476
+ "two.one.one": "2.1.1"
477
+ };
478
+
479
+ const output = Object.entries(input).reduce(
480
+ (acc, [key, value]) => set(acc, key, value),
481
+ {}
482
+ );
483
+
484
+ // Output:
485
+ //
486
+ // {
487
+ // "one": {
488
+ // "one": "1.1",
489
+ // "two": "1.2"
490
+ // },
491
+ // "two": {
492
+ // "one": {
493
+ // "one": "2.1.1"
494
+ // }
495
+ // }
496
+ // }
497
+ ` ));
498
+ }
499
+ }
500
+
501
+ /**
502
+ * Enhances the incoming props with defaults.
503
+ */
504
+ function initializeConfig({
505
+ formats,
506
+ getMessageFallback,
507
+ messages,
508
+ onError,
509
+ ...rest
510
+ }) {
511
+ const finalOnError = onError || defaultOnError;
512
+ const finalGetMessageFallback = getMessageFallback || defaultGetMessageFallback;
513
+ {
514
+ if (messages) {
515
+ validateMessages(messages, finalOnError);
516
+ }
517
+ }
518
+ return {
519
+ ...rest,
520
+ formats: formats || undefined,
521
+ messages: messages || undefined,
522
+ onError: finalOnError,
523
+ getMessageFallback: finalGetMessageFallback
524
+ };
525
+ }
526
+
527
+ export { createBaseTranslator as a, defaultOnError as b, createFormatter as c, defaultGetMessageFallback as d, initializeConfig as i, resolveNamespace as r };