use-intl 2.9.1 → 2.10.0-alpha.3

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 (162) hide show
  1. package/CHANGELOG.md +463 -0
  2. package/dist/core/use-intl.esm.js +140 -27
  3. package/dist/core/use-intl.esm.js.map +1 -1
  4. package/dist/core/use-intl.esm2.js +41 -38
  5. package/dist/core/use-intl.esm2.js.map +1 -1
  6. package/dist/core/use-intl.esm3.js +35 -151
  7. package/dist/core/use-intl.esm3.js.map +1 -1
  8. package/dist/core/use-intl.esm4.js +12 -56
  9. package/dist/core/use-intl.esm4.js.map +1 -1
  10. package/dist/core/use-intl.esm5.js +56 -12
  11. package/dist/core/use-intl.esm5.js.map +1 -1
  12. package/dist/core/use-intl.esm6.js +7 -29
  13. package/dist/core/use-intl.esm6.js.map +1 -1
  14. package/dist/core/use-intl.esm7.js +9 -9
  15. package/dist/core/use-intl.esm7.js.map +1 -1
  16. package/dist/core/use-intl.esm8.js +29 -7
  17. package/dist/core/use-intl.esm8.js.map +1 -1
  18. package/dist/react/IntlContext.d.ts +2 -19
  19. package/dist/react/IntlContextValue.d.ts +19 -0
  20. package/dist/react/IntlProvider.d.ts +2 -16
  21. package/dist/react/IntlProviderProps.d.ts +15 -0
  22. package/dist/react/getIntlContextValue.d.ts +18 -0
  23. package/dist/react/use-intl.esm.js +6 -25
  24. package/dist/react/use-intl.esm.js.map +1 -1
  25. package/dist/react/use-intl.esm10.js +44 -0
  26. package/dist/react/use-intl.esm10.js.map +1 -0
  27. package/dist/react/use-intl.esm2.js +20 -21
  28. package/dist/react/use-intl.esm2.js.map +1 -1
  29. package/dist/react/use-intl.esm3.js +21 -20
  30. package/dist/react/use-intl.esm3.js.map +1 -1
  31. package/dist/react/use-intl.esm4.js +46 -4
  32. package/dist/react/use-intl.esm4.js.map +1 -1
  33. package/dist/react/use-intl.esm5.js +4 -46
  34. package/dist/react/use-intl.esm5.js.map +1 -1
  35. package/dist/react/use-intl.esm6.js +1 -1
  36. package/dist/react/use-intl.esm7.js.map +1 -1
  37. package/dist/react/use-intl.esm8.js +26 -8
  38. package/dist/react/use-intl.esm8.js.map +1 -1
  39. package/dist/react/use-intl.esm9.js +9 -38
  40. package/dist/react/use-intl.esm9.js.map +1 -1
  41. package/dist/react/useIntlContext.d.ts +1 -1
  42. package/dist/src/core/AbstractIntlMessages.d.ts +9 -0
  43. package/dist/src/core/AbstractIntlMessages.js +2 -0
  44. package/dist/src/core/AbstractIntlMessages.js.map +1 -0
  45. package/dist/src/core/DateTimeFormatOptions.d.ts +72 -0
  46. package/dist/src/core/DateTimeFormatOptions.js +3 -0
  47. package/dist/src/core/DateTimeFormatOptions.js.map +1 -0
  48. package/dist/src/core/Formats.d.ts +7 -0
  49. package/dist/src/core/Formats.js +2 -0
  50. package/dist/src/core/Formats.js.map +1 -0
  51. package/dist/src/core/IntlConfiguration.d.ts +46 -0
  52. package/dist/src/core/IntlConfiguration.js +2 -0
  53. package/dist/src/core/IntlConfiguration.js.map +1 -0
  54. package/dist/src/core/IntlError.d.ts +13 -0
  55. package/dist/src/core/IntlError.js +23 -0
  56. package/dist/src/core/IntlError.js.map +1 -0
  57. package/dist/src/core/IntlMessages.d.ts +2 -0
  58. package/dist/src/core/IntlMessages.js +4 -0
  59. package/dist/src/core/IntlMessages.js.map +1 -0
  60. package/dist/src/core/NumberFormatOptions.d.ts +2 -0
  61. package/dist/src/core/NumberFormatOptions.js +2 -0
  62. package/dist/src/core/NumberFormatOptions.js.map +1 -0
  63. package/dist/src/core/TranslationValues.d.ts +5 -0
  64. package/dist/src/core/TranslationValues.js +2 -0
  65. package/dist/src/core/TranslationValues.js.map +1 -0
  66. package/dist/src/core/convertFormatsToIntlMessageFormat.d.ts +10 -0
  67. package/dist/src/core/convertFormatsToIntlMessageFormat.js +31 -0
  68. package/dist/src/core/convertFormatsToIntlMessageFormat.js.map +1 -0
  69. package/dist/src/core/createBaseTranslator.d.ts +26 -0
  70. package/dist/src/core/createBaseTranslator.js +185 -0
  71. package/dist/src/core/createBaseTranslator.js.map +1 -0
  72. package/dist/src/core/createIntl.d.ts +17 -0
  73. package/dist/src/core/createIntl.js +126 -0
  74. package/dist/src/core/createIntl.js.map +1 -0
  75. package/dist/src/core/createTranslator.d.ts +48 -0
  76. package/dist/src/core/createTranslator.js +24 -0
  77. package/dist/src/core/createTranslator.js.map +1 -0
  78. package/dist/src/core/createTranslatorImpl.d.ts +14 -0
  79. package/dist/src/core/createTranslatorImpl.js +43 -0
  80. package/dist/src/core/createTranslatorImpl.js.map +1 -0
  81. package/dist/src/core/defaults.d.ts +11 -0
  82. package/dist/src/core/defaults.js +11 -0
  83. package/dist/src/core/defaults.js.map +1 -0
  84. package/dist/src/core/index.d.ts +8 -0
  85. package/dist/src/core/index.js +4 -0
  86. package/dist/src/core/index.js.map +1 -0
  87. package/dist/src/core/resolveNamespace.d.ts +5 -0
  88. package/dist/src/core/resolveNamespace.js +10 -0
  89. package/dist/src/core/resolveNamespace.js.map +1 -0
  90. package/dist/src/core/utils/MessageKeys.d.ts +5 -0
  91. package/dist/src/core/utils/MessageKeys.js +2 -0
  92. package/dist/src/core/utils/MessageKeys.js.map +1 -0
  93. package/dist/src/core/utils/NamespaceKeys.d.ts +5 -0
  94. package/dist/src/core/utils/NamespaceKeys.js +2 -0
  95. package/dist/src/core/utils/NamespaceKeys.js.map +1 -0
  96. package/dist/src/core/utils/NestedKeyOf.d.ts +4 -0
  97. package/dist/src/core/utils/NestedKeyOf.js +2 -0
  98. package/dist/src/core/utils/NestedKeyOf.js.map +1 -0
  99. package/dist/src/core/utils/NestedValueOf.d.ts +2 -0
  100. package/dist/src/core/utils/NestedValueOf.js +2 -0
  101. package/dist/src/core/utils/NestedValueOf.js.map +1 -0
  102. package/dist/src/core/validateMessages.d.ts +3 -0
  103. package/dist/src/core/validateMessages.js +22 -0
  104. package/dist/src/core/validateMessages.js.map +1 -0
  105. package/dist/src/index.d.ts +2 -0
  106. package/dist/src/index.js +3 -0
  107. package/dist/src/index.js.map +1 -0
  108. package/dist/src/react/IntlContext.d.ts +4 -0
  109. package/dist/src/react/IntlContext.js +4 -0
  110. package/dist/src/react/IntlContext.js.map +1 -0
  111. package/dist/src/react/IntlContextValue.d.ts +19 -0
  112. package/dist/src/react/IntlContextValue.js +2 -0
  113. package/dist/src/react/IntlContextValue.js.map +1 -0
  114. package/dist/src/react/IntlProvider.d.ts +2 -0
  115. package/dist/src/react/IntlProvider.js +7 -0
  116. package/dist/src/react/IntlProvider.js.map +1 -0
  117. package/dist/src/react/IntlProviderProps.d.ts +15 -0
  118. package/dist/src/react/IntlProviderProps.js +2 -0
  119. package/dist/src/react/IntlProviderProps.js.map +1 -0
  120. package/dist/src/react/getIntlContextValue.d.ts +18 -0
  121. package/dist/src/react/getIntlContextValue.js +21 -0
  122. package/dist/src/react/getIntlContextValue.js.map +1 -0
  123. package/dist/src/react/index.d.ts +6 -0
  124. package/dist/src/react/index.js +7 -0
  125. package/dist/src/react/index.js.map +1 -0
  126. package/dist/src/react/useIntl.d.ts +5 -0
  127. package/dist/src/react/useIntl.js +14 -0
  128. package/dist/src/react/useIntl.js.map +1 -0
  129. package/dist/src/react/useIntlContext.d.ts +1 -0
  130. package/dist/src/react/useIntlContext.js +12 -0
  131. package/dist/src/react/useIntlContext.js.map +1 -0
  132. package/dist/src/react/useLocale.d.ts +1 -0
  133. package/dist/src/react/useLocale.js +5 -0
  134. package/dist/src/react/useLocale.js.map +1 -0
  135. package/dist/src/react/useNow.d.ts +23 -0
  136. package/dist/src/react/useNow.js +40 -0
  137. package/dist/src/react/useNow.js.map +1 -0
  138. package/dist/src/react/useTimeZone.d.ts +1 -0
  139. package/dist/src/react/useTimeZone.js +5 -0
  140. package/dist/src/react/useTimeZone.js.map +1 -0
  141. package/dist/src/react/useTranslations.d.ts +44 -0
  142. package/dist/src/react/useTranslations.js +21 -0
  143. package/dist/src/react/useTranslations.js.map +1 -0
  144. package/dist/src/react/useTranslationsImpl.d.ts +8 -0
  145. package/dist/src/react/useTranslationsImpl.js +35 -0
  146. package/dist/src/react/useTranslationsImpl.js.map +1 -0
  147. package/dist/use-intl.cjs.development.js +37 -28
  148. package/dist/use-intl.cjs.development.js.map +1 -1
  149. package/dist/use-intl.cjs.production.min.js +1 -1
  150. package/dist/use-intl.cjs.production.min.js.map +1 -1
  151. package/dist/use-intl.esm.js +7 -7
  152. package/package.json +6 -5
  153. package/src/core/createBaseTranslator.tsx +11 -7
  154. package/src/core/createIntl.tsx +2 -2
  155. package/src/core/createTranslatorImpl.tsx +1 -1
  156. package/src/react/IntlContext.tsx +2 -20
  157. package/src/react/IntlContextValue.tsx +21 -0
  158. package/src/react/IntlProvider.tsx +5 -36
  159. package/src/react/IntlProviderProps.tsx +17 -0
  160. package/src/react/getIntlContextValue.tsx +30 -0
  161. package/src/react/useIntlContext.tsx +1 -1
  162. package/LICENSE +0 -21
@@ -0,0 +1,22 @@
1
+ import IntlError, { IntlErrorCode } from './IntlError';
2
+ function validateMessagesSegment(messages, invalidKeyLabels, parentPath) {
3
+ Object.entries(messages).forEach(([key, messageOrMessages]) => {
4
+ if (key.includes('.')) {
5
+ let keyLabel = key;
6
+ if (parentPath)
7
+ keyLabel += ` (at ${parentPath})`;
8
+ invalidKeyLabels.push(keyLabel);
9
+ }
10
+ if (messageOrMessages != null && typeof messageOrMessages === 'object') {
11
+ validateMessagesSegment(messageOrMessages, invalidKeyLabels, [parentPath, key].filter((part) => part != null).join('.'));
12
+ }
13
+ });
14
+ }
15
+ export default function validateMessages(messages, onError) {
16
+ const invalidKeyLabels = [];
17
+ validateMessagesSegment(messages, invalidKeyLabels);
18
+ if (invalidKeyLabels.length > 0) {
19
+ 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(', ')}`));
20
+ }
21
+ }
22
+ //# sourceMappingURL=validateMessages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validateMessages.js","sourceRoot":"","sources":["../../../src/core/validateMessages.tsx"],"names":[],"mappings":"AACA,OAAO,SAAS,EAAE,EAAC,aAAa,EAAC,MAAM,aAAa,CAAC;AAErD,SAAS,uBAAuB,CAC9B,QAA8B,EAC9B,gBAA+B,EAC/B,UAAmB;IAEnB,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,iBAAiB,CAAC,EAAE,EAAE;QAC5D,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;YACrB,IAAI,QAAQ,GAAG,GAAG,CAAC;YACnB,IAAI,UAAU;gBAAE,QAAQ,IAAI,QAAQ,UAAU,GAAG,CAAC;YAClD,gBAAgB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;SACjC;QAED,IAAI,iBAAiB,IAAI,IAAI,IAAI,OAAO,iBAAiB,KAAK,QAAQ,EAAE;YACtE,uBAAuB,CACrB,iBAAiB,EACjB,gBAAgB,EAChB,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAC3D,CAAC;SACH;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,CAAC,OAAO,UAAU,gBAAgB,CACtC,QAA8B,EAC9B,OAAmC;IAEnC,MAAM,gBAAgB,GAAkB,EAAE,CAAC;IAC3C,uBAAuB,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC;IAEpD,IAAI,gBAAgB,CAAC,MAAM,GAAG,CAAC,EAAE;QAC/B,OAAO,CACL,IAAI,SAAS,CACX,aAAa,CAAC,WAAW,EACzB,0JACE,gBAAgB,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAC1C,KAAK,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CACnC,CACF,CAAC;KACH;AACH,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './core';
2
+ export * from './react';
@@ -0,0 +1,3 @@
1
+ export * from './core';
2
+ export * from './react';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC"}
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ import IntlContextValue from './IntlContextValue';
3
+ declare const IntlContext: import("react").Context<IntlContextValue | undefined>;
4
+ export default IntlContext;
@@ -0,0 +1,4 @@
1
+ import { createContext } from 'react';
2
+ const IntlContext = createContext(undefined);
3
+ export default IntlContext;
4
+ //# sourceMappingURL=IntlContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IntlContext.js","sourceRoot":"","sources":["../../../src/react/IntlContext.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,OAAO,CAAC;AAGpC,MAAM,WAAW,GAAG,aAAa,CAA+B,SAAS,CAAC,CAAC;AAE3E,eAAe,WAAW,CAAC"}
@@ -0,0 +1,19 @@
1
+ import AbstractIntlMessages from '../core/AbstractIntlMessages';
2
+ import Formats from '../core/Formats';
3
+ import IntlError from '../core/IntlError';
4
+ import { RichTranslationValues } from '../core/TranslationValues';
5
+ declare type IntlContextValue = {
6
+ messages?: AbstractIntlMessages;
7
+ locale: string;
8
+ formats?: Partial<Formats>;
9
+ timeZone?: string;
10
+ onError(error: IntlError): void;
11
+ getMessageFallback(info: {
12
+ error: IntlError;
13
+ key: string;
14
+ namespace?: string;
15
+ }): string;
16
+ now?: Date;
17
+ defaultTranslationValues?: RichTranslationValues;
18
+ };
19
+ export default IntlContextValue;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=IntlContextValue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IntlContextValue.js","sourceRoot":"","sources":["../../../src/react/IntlContextValue.tsx"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ import IntlProviderProps from './IntlProviderProps';
2
+ export default function IntlProvider({ children, ...props }: IntlProviderProps): JSX.Element;
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+ import IntlContext from './IntlContext';
3
+ import getIntlContextValue from './getIntlContextValue';
4
+ export default function IntlProvider({ children, ...props }) {
5
+ return (React.createElement(IntlContext.Provider, { value: getIntlContextValue(props) }, children));
6
+ }
7
+ //# sourceMappingURL=IntlProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IntlProvider.js","sourceRoot":"","sources":["../../../src/react/IntlProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,WAAW,MAAM,eAAe,CAAC;AAExC,OAAO,mBAAmB,MAAM,uBAAuB,CAAC;AAExD,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,EAAC,QAAQ,EAAE,GAAG,KAAK,EAAoB;IAC1E,OAAO,CACL,oBAAC,WAAW,CAAC,QAAQ,IAAC,KAAK,EAAE,mBAAmB,CAAC,KAAK,CAAC,IACpD,QAAQ,CACY,CACxB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,15 @@
1
+ import { ReactNode } from 'react';
2
+ import { AbstractIntlMessages } from '../core';
3
+ import IntlConfiguration from '../core/IntlConfiguration';
4
+ import { RichTranslationValues } from '../core/TranslationValues';
5
+ declare type IntlProviderProps = IntlConfiguration & {
6
+ /** All components that use the provided hooks should be within this tree. */
7
+ children: ReactNode;
8
+ /** Global default values for translation values and rich text elements.
9
+ * Can be used for consistent usage or styling of rich text elements.
10
+ * Defaults will be overidden by locally provided values. */
11
+ defaultTranslationValues?: RichTranslationValues;
12
+ /** All messages that will be available in your components. */
13
+ messages?: AbstractIntlMessages;
14
+ };
15
+ export default IntlProviderProps;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=IntlProviderProps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IntlProviderProps.js","sourceRoot":"","sources":["../../../src/react/IntlProviderProps.tsx"],"names":[],"mappings":""}
@@ -0,0 +1,18 @@
1
+ import IntlProviderProps from './IntlProviderProps';
2
+ /**
3
+ * Enhances the incoming props with defaults.
4
+ */
5
+ export default function getIntlContextValue({ getMessageFallback, messages, onError, ...rest }: Omit<IntlProviderProps, 'children'>): {
6
+ messages: import("../core/AbstractIntlMessages").default | undefined;
7
+ onError: (error: import("..").IntlError) => void;
8
+ getMessageFallback: (info: {
9
+ error: import("..").IntlError;
10
+ key: string;
11
+ namespace?: string | undefined;
12
+ }) => string;
13
+ defaultTranslationValues?: import("..").RichTranslationValues | undefined;
14
+ formats?: Partial<import("../core/Formats").default> | undefined;
15
+ locale: string;
16
+ timeZone?: string | undefined;
17
+ now?: Date | undefined;
18
+ };
@@ -0,0 +1,21 @@
1
+ import { defaultGetMessageFallback, defaultOnError } from '../core/defaults';
2
+ import validateMessages from '../core/validateMessages';
3
+ /**
4
+ * Enhances the incoming props with defaults.
5
+ */
6
+ export default function getIntlContextValue({ getMessageFallback, messages, onError, ...rest }) {
7
+ const finalOnError = onError || defaultOnError;
8
+ const finalGetMessageFallback = getMessageFallback || defaultGetMessageFallback;
9
+ if (process.env.NODE_ENV !== 'production') {
10
+ if (messages) {
11
+ validateMessages(messages, finalOnError);
12
+ }
13
+ }
14
+ return {
15
+ ...rest,
16
+ messages,
17
+ onError: finalOnError,
18
+ getMessageFallback: finalGetMessageFallback
19
+ };
20
+ }
21
+ //# sourceMappingURL=getIntlContextValue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getIntlContextValue.js","sourceRoot":"","sources":["../../../src/react/getIntlContextValue.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,yBAAyB,EAAE,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAC3E,OAAO,gBAAgB,MAAM,0BAA0B,CAAC;AAGxD;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,mBAAmB,CAAC,EAC1C,kBAAkB,EAClB,QAAQ,EACR,OAAO,EACP,GAAG,IAAI,EAC6B;IACpC,MAAM,YAAY,GAAG,OAAO,IAAI,cAAc,CAAC;IAC/C,MAAM,uBAAuB,GAC3B,kBAAkB,IAAI,yBAAyB,CAAC;IAElD,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE;QACzC,IAAI,QAAQ,EAAE;YACZ,gBAAgB,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;SAC1C;KACF;IAED,OAAO;QACL,GAAG,IAAI;QACP,QAAQ;QACR,OAAO,EAAE,YAAY;QACrB,kBAAkB,EAAE,uBAAuB;KAC5C,CAAC;AACJ,CAAC"}
@@ -0,0 +1,6 @@
1
+ export { default as IntlProvider } from './IntlProvider';
2
+ export { default as useTranslations } from './useTranslations';
3
+ export { default as useIntl } from './useIntl';
4
+ export { default as useLocale } from './useLocale';
5
+ export { default as useNow } from './useNow';
6
+ export { default as useTimeZone } from './useTimeZone';
@@ -0,0 +1,7 @@
1
+ export { default as IntlProvider } from './IntlProvider';
2
+ export { default as useTranslations } from './useTranslations';
3
+ export { default as useIntl } from './useIntl';
4
+ export { default as useLocale } from './useLocale';
5
+ export { default as useNow } from './useNow';
6
+ export { default as useTimeZone } from './useTimeZone';
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/react/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,IAAI,YAAY,EAAC,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAC,OAAO,IAAI,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAC,OAAO,IAAI,OAAO,EAAC,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAC,OAAO,IAAI,SAAS,EAAC,MAAM,aAAa,CAAC;AACjD,OAAO,EAAC,OAAO,IAAI,MAAM,EAAC,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAC,OAAO,IAAI,WAAW,EAAC,MAAM,eAAe,CAAC"}
@@ -0,0 +1,5 @@
1
+ export default function useIntl(): {
2
+ formatDateTime: (value: number | Date, formatOrOptions?: string | import("../core/DateTimeFormatOptions").default | undefined) => string;
3
+ formatNumber: (value: number, formatOrOptions?: string | import("@formatjs/ecma402-abstract").NumberFormatOptions | undefined) => string;
4
+ formatRelativeTime: (date: number | Date, now?: number | Date | undefined) => string;
5
+ };
@@ -0,0 +1,14 @@
1
+ import { useMemo } from 'react';
2
+ import createIntl from '../core/createIntl';
3
+ import useIntlContext from './useIntlContext';
4
+ export default function useIntl() {
5
+ const { formats, locale, now: globalNow, onError, timeZone } = useIntlContext();
6
+ return useMemo(() => createIntl({
7
+ formats,
8
+ locale,
9
+ now: globalNow,
10
+ onError,
11
+ timeZone
12
+ }), [formats, globalNow, locale, onError, timeZone]);
13
+ }
14
+ //# sourceMappingURL=useIntl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useIntl.js","sourceRoot":"","sources":["../../../src/react/useIntl.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,OAAO,CAAC;AAC9B,OAAO,UAAU,MAAM,oBAAoB,CAAC;AAC5C,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAE9C,MAAM,CAAC,OAAO,UAAU,OAAO;IAC7B,MAAM,EAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAC,GAAG,cAAc,EAAE,CAAC;IAE9E,OAAO,OAAO,CACZ,GAAG,EAAE,CACH,UAAU,CAAC;QACT,OAAO;QACP,MAAM;QACN,GAAG,EAAE,SAAS;QACd,OAAO;QACP,QAAQ;KACT,CAAC,EACJ,CAAC,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,CAAC,CAChD,CAAC;AACJ,CAAC"}
@@ -0,0 +1 @@
1
+ export default function useIntlContext(): import("./IntlContextValue").default;
@@ -0,0 +1,12 @@
1
+ import { useContext } from 'react';
2
+ import IntlContext from './IntlContext';
3
+ export default function useIntlContext() {
4
+ const context = useContext(IntlContext);
5
+ if (!context) {
6
+ throw new Error(process.env.NODE_ENV !== 'production'
7
+ ? 'No intl context found. Have you configured the provider?'
8
+ : undefined);
9
+ }
10
+ return context;
11
+ }
12
+ //# sourceMappingURL=useIntlContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useIntlContext.js","sourceRoot":"","sources":["../../../src/react/useIntlContext.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,OAAO,CAAC;AACjC,OAAO,WAAW,MAAM,eAAe,CAAC;AAExC,MAAM,CAAC,OAAO,UAAU,cAAc;IACpC,MAAM,OAAO,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC;IAExC,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,IAAI,KAAK,CACb,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY;YACnC,CAAC,CAAC,0DAA0D;YAC5D,CAAC,CAAC,SAAS,CACd,CAAC;KACH;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -0,0 +1 @@
1
+ export default function useLocale(): string;
@@ -0,0 +1,5 @@
1
+ import useIntlContext from './useIntlContext';
2
+ export default function useLocale() {
3
+ return useIntlContext().locale;
4
+ }
5
+ //# sourceMappingURL=useLocale.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLocale.js","sourceRoot":"","sources":["../../../src/react/useLocale.tsx"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAE9C,MAAM,CAAC,OAAO,UAAU,SAAS;IAC/B,OAAO,cAAc,EAAE,CAAC,MAAM,CAAC;AACjC,CAAC"}
@@ -0,0 +1,23 @@
1
+ declare type Options = {
2
+ updateInterval?: number;
3
+ };
4
+ /**
5
+ * Reading the current date via `new Date()` in components should be avoided, as
6
+ * it causes components to be impure and can lead to flaky tests. Instead, this
7
+ * hook can be used.
8
+ *
9
+ * By default, it returns the time when the component mounts. If `updateInterval`
10
+ * is specified, the value will be updated based on the interval.
11
+ *
12
+ * You can however also return a static value from this hook, if you
13
+ * configure the `now` parameter on the context provider. Note however,
14
+ * that if `updateInterval` is configured in this case, the component
15
+ * will initialize with the global value, but will afterwards update
16
+ * continuously based on the interval.
17
+ *
18
+ * For unit tests, this can be mocked to a constant value. For end-to-end
19
+ * testing, an environment parameter can be passed to the `now` parameter
20
+ * of the provider to mock this to a static value.
21
+ */
22
+ export default function useNow(options?: Options): Date;
23
+ export {};
@@ -0,0 +1,40 @@
1
+ import { useState, useEffect } from 'react';
2
+ import useIntlContext from './useIntlContext';
3
+ function getNow() {
4
+ return new Date();
5
+ }
6
+ /**
7
+ * Reading the current date via `new Date()` in components should be avoided, as
8
+ * it causes components to be impure and can lead to flaky tests. Instead, this
9
+ * hook can be used.
10
+ *
11
+ * By default, it returns the time when the component mounts. If `updateInterval`
12
+ * is specified, the value will be updated based on the interval.
13
+ *
14
+ * You can however also return a static value from this hook, if you
15
+ * configure the `now` parameter on the context provider. Note however,
16
+ * that if `updateInterval` is configured in this case, the component
17
+ * will initialize with the global value, but will afterwards update
18
+ * continuously based on the interval.
19
+ *
20
+ * For unit tests, this can be mocked to a constant value. For end-to-end
21
+ * testing, an environment parameter can be passed to the `now` parameter
22
+ * of the provider to mock this to a static value.
23
+ */
24
+ export default function useNow(options) {
25
+ const updateInterval = options?.updateInterval;
26
+ const { now: globalNow } = useIntlContext();
27
+ const [now, setNow] = useState(globalNow || getNow());
28
+ useEffect(() => {
29
+ if (!updateInterval)
30
+ return;
31
+ const intervalId = setInterval(() => {
32
+ setNow(getNow());
33
+ }, updateInterval);
34
+ return () => {
35
+ clearInterval(intervalId);
36
+ };
37
+ }, [globalNow, updateInterval]);
38
+ return now;
39
+ }
40
+ //# sourceMappingURL=useNow.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useNow.js","sourceRoot":"","sources":["../../../src/react/useNow.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAE,SAAS,EAAC,MAAM,OAAO,CAAC;AAC1C,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAM9C,SAAS,MAAM;IACb,OAAO,IAAI,IAAI,EAAE,CAAC;AACpB,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,OAAiB;IAC9C,MAAM,cAAc,GAAG,OAAO,EAAE,cAAc,CAAC;IAE/C,MAAM,EAAC,GAAG,EAAE,SAAS,EAAC,GAAG,cAAc,EAAE,CAAC;IAC1C,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,QAAQ,CAAC,SAAS,IAAI,MAAM,EAAE,CAAC,CAAC;IAEtD,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,cAAc;YAAE,OAAO;QAE5B,MAAM,UAAU,GAAG,WAAW,CAAC,GAAG,EAAE;YAClC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;QACnB,CAAC,EAAE,cAAc,CAAC,CAAC;QAEnB,OAAO,GAAG,EAAE;YACV,aAAa,CAAC,UAAU,CAAC,CAAC;QAC5B,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC,CAAC;IAEhC,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1 @@
1
+ export default function useTimeZone(): string | undefined;
@@ -0,0 +1,5 @@
1
+ import useIntlContext from './useIntlContext';
2
+ export default function useTimeZone() {
3
+ return useIntlContext().timeZone;
4
+ }
5
+ //# sourceMappingURL=useTimeZone.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTimeZone.js","sourceRoot":"","sources":["../../../src/react/useTimeZone.tsx"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAE9C,MAAM,CAAC,OAAO,UAAU,WAAW;IACjC,OAAO,cAAc,EAAE,CAAC,QAAQ,CAAC;AACnC,CAAC"}
@@ -0,0 +1,44 @@
1
+ import { ReactElement, ReactNodeArray } from 'react';
2
+ import Formats from '../core/Formats';
3
+ import TranslationValues, { RichTranslationValues } from '../core/TranslationValues';
4
+ import MessageKeys from '../core/utils/MessageKeys';
5
+ import NamespaceKeys from '../core/utils/NamespaceKeys';
6
+ import NestedKeyOf from '../core/utils/NestedKeyOf';
7
+ import NestedValueOf from '../core/utils/NestedValueOf';
8
+ /**
9
+ * Translates messages from the given namespace by using the ICU syntax.
10
+ * See https://formatjs.io/docs/core-concepts/icu-syntax.
11
+ *
12
+ * If no namespace is provided, all available messages are returned.
13
+ * The namespace can also indicate nesting by using a dot
14
+ * (e.g. `namespace.Component`).
15
+ */
16
+ export default function useTranslations<NestedKey extends NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> = never>(namespace?: NestedKey): {
17
+ <TargetKey extends MessageKeys<NestedValueOf<{
18
+ '!': IntlMessages;
19
+ }, [
20
+ NestedKey
21
+ ] extends [never] ? '!' : `!.${NestedKey}`>, NestedKeyOf<NestedValueOf<{
22
+ '!': IntlMessages;
23
+ }, [
24
+ NestedKey
25
+ ] extends [never] ? '!' : `!.${NestedKey}`>>>>(key: TargetKey, values?: TranslationValues, formats?: Partial<Formats>): string;
26
+ rich<TargetKey extends MessageKeys<NestedValueOf<{
27
+ '!': IntlMessages;
28
+ }, [
29
+ NestedKey
30
+ ] extends [never] ? '!' : `!.${NestedKey}`>, NestedKeyOf<NestedValueOf<{
31
+ '!': IntlMessages;
32
+ }, [
33
+ NestedKey
34
+ ] extends [never] ? '!' : `!.${NestedKey}`>>>>(key: TargetKey, values?: RichTranslationValues, formats?: Partial<Formats>): string | ReactElement | ReactNodeArray;
35
+ raw<TargetKey extends MessageKeys<NestedValueOf<{
36
+ '!': IntlMessages;
37
+ }, [
38
+ NestedKey
39
+ ] extends [never] ? '!' : `!.${NestedKey}`>, NestedKeyOf<NestedValueOf<{
40
+ '!': IntlMessages;
41
+ }, [
42
+ NestedKey
43
+ ] extends [never] ? '!' : `!.${NestedKey}`>>>>(key: TargetKey): any;
44
+ };
@@ -0,0 +1,21 @@
1
+ import useIntlContext from './useIntlContext';
2
+ import useTranslationsImpl from './useTranslationsImpl';
3
+ /**
4
+ * Translates messages from the given namespace by using the ICU syntax.
5
+ * See https://formatjs.io/docs/core-concepts/icu-syntax.
6
+ *
7
+ * If no namespace is provided, all available messages are returned.
8
+ * The namespace can also indicate nesting by using a dot
9
+ * (e.g. `namespace.Component`).
10
+ */
11
+ export default function useTranslations(namespace) {
12
+ const context = useIntlContext();
13
+ const messages = context.messages;
14
+ // We have to wrap the actual hook so the type inference for the optional
15
+ // namespace works correctly. See https://stackoverflow.com/a/71529575/343045
16
+ // The prefix ("!") is arbitrary.
17
+ return useTranslationsImpl({ '!': messages },
18
+ // @ts-ignore
19
+ namespace ? `!.${namespace}` : '!', '!');
20
+ }
21
+ //# sourceMappingURL=useTranslations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTranslations.js","sourceRoot":"","sources":["../../../src/react/useTranslations.tsx"],"names":[],"mappings":"AASA,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAC9C,OAAO,mBAAmB,MAAM,uBAAuB,CAAC;AAExD;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UAAU,eAAe,CAMrC,SAAqB;IA6DrB,MAAM,OAAO,GAAG,cAAc,EAAE,CAAC;IACjC,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAwB,CAAC;IAElD,yEAAyE;IACzE,6EAA6E;IAC7E,iCAAiC;IACjC,OAAO,mBAAmB,CAIxB,EAAC,GAAG,EAAE,QAAQ,EAAC;IACf,aAAa;IACb,SAAS,CAAC,CAAC,CAAC,KAAK,SAAS,EAAE,CAAC,CAAC,CAAC,GAAG,EAClC,GAAG,CACJ,CAAC;AACJ,CAAC"}
@@ -0,0 +1,8 @@
1
+ /// <reference types="react" />
2
+ import AbstractIntlMessages from '../core/AbstractIntlMessages';
3
+ import NestedKeyOf from '../core/utils/NestedKeyOf';
4
+ export default function useTranslationsImpl<Messages extends AbstractIntlMessages, NestedKey extends NestedKeyOf<Messages>>(allMessages: Messages, namespace: NestedKey, namespacePrefix: string): {
5
+ <TargetKey extends unknown>(key: TargetKey, values?: import("../core/TranslationValues").default | undefined, formats?: Partial<import("../core/Formats").default> | undefined): string;
6
+ rich: (key: string, values?: import("..").RichTranslationValues | undefined, formats?: Partial<import("../core/Formats").default> | undefined) => string | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | import("react").ReactNodeArray;
7
+ raw(key: string): any;
8
+ };
@@ -0,0 +1,35 @@
1
+ import { useMemo, useRef } from 'react';
2
+ import createBaseTranslator, { getMessagesOrError } from '../core/createBaseTranslator';
3
+ import resolveNamespace from '../core/resolveNamespace';
4
+ import useIntlContext from './useIntlContext';
5
+ export default function useTranslationsImpl(allMessages, namespace, namespacePrefix) {
6
+ const { defaultTranslationValues, formats: globalFormats, getMessageFallback, locale, onError, timeZone } = useIntlContext();
7
+ // The `namespacePrefix` is part of the type system.
8
+ // See the comment in the hook invocation.
9
+ allMessages = allMessages[namespacePrefix];
10
+ namespace = resolveNamespace(namespace, namespacePrefix);
11
+ const cachedFormatsByLocaleRef = useRef({});
12
+ const messagesOrError = useMemo(() => getMessagesOrError({ messages: allMessages, namespace, onError }), [allMessages, namespace, onError]);
13
+ const translate = useMemo(() => createBaseTranslator({
14
+ cachedFormatsByLocale: cachedFormatsByLocaleRef.current,
15
+ getMessageFallback,
16
+ messagesOrError,
17
+ defaultTranslationValues,
18
+ namespace,
19
+ onError,
20
+ formats: globalFormats,
21
+ locale,
22
+ timeZone
23
+ }), [
24
+ getMessageFallback,
25
+ messagesOrError,
26
+ defaultTranslationValues,
27
+ namespace,
28
+ onError,
29
+ globalFormats,
30
+ locale,
31
+ timeZone
32
+ ]);
33
+ return translate;
34
+ }
35
+ //# sourceMappingURL=useTranslationsImpl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTranslationsImpl.js","sourceRoot":"","sources":["../../../src/react/useTranslationsImpl.tsx"],"names":[],"mappings":"AACA,OAAO,EAAC,OAAO,EAAE,MAAM,EAAC,MAAM,OAAO,CAAC;AAEtC,OAAO,oBAAoB,EAAE,EAC3B,kBAAkB,EACnB,MAAM,8BAA8B,CAAC;AACtC,OAAO,gBAAgB,MAAM,0BAA0B,CAAC;AAExD,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAE9C,MAAM,CAAC,OAAO,UAAU,mBAAmB,CAGzC,WAAqB,EAAE,SAAoB,EAAE,eAAuB;IACpE,MAAM,EACJ,wBAAwB,EACxB,OAAO,EAAE,aAAa,EACtB,kBAAkB,EAClB,MAAM,EACN,OAAO,EACP,QAAQ,EACT,GAAG,cAAc,EAAE,CAAC;IAErB,oDAAoD;IACpD,0CAA0C;IAC1C,WAAW,GAAG,WAAW,CAAC,eAAe,CAAa,CAAC;IACvD,SAAS,GAAG,gBAAgB,CAAC,SAAS,EAAE,eAAe,CAAc,CAAC;IAEtE,MAAM,wBAAwB,GAAG,MAAM,CAErC,EAAE,CAAC,CAAC;IAEN,MAAM,eAAe,GAAG,OAAO,CAC7B,GAAG,EAAE,CAAC,kBAAkB,CAAC,EAAC,QAAQ,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAC,CAAC,EACrE,CAAC,WAAW,EAAE,SAAS,EAAE,OAAO,CAAC,CAClC,CAAC;IAEF,MAAM,SAAS,GAAG,OAAO,CACvB,GAAG,EAAE,CACH,oBAAoB,CAAC;QACnB,qBAAqB,EAAE,wBAAwB,CAAC,OAAO;QACvD,kBAAkB;QAClB,eAAe;QACf,wBAAwB;QACxB,SAAS;QACT,OAAO;QACP,OAAO,EAAE,aAAa;QACtB,MAAM;QACN,QAAQ;KACT,CAAC,EACJ;QACE,kBAAkB;QAClB,eAAe;QACf,wBAAwB;QACxB,SAAS;QACT,OAAO;QACP,aAAa;QACb,MAAM;QACN,QAAQ;KACT,CACF,CAAC;IAEF,OAAO,SAAS,CAAC;AACnB,CAAC"}
@@ -266,13 +266,13 @@ function getMessagesOrError(_ref) {
266
266
 
267
267
  try {
268
268
  if (!messages) {
269
- throw new Error("development" !== "production" ? "No messages were configured on the provider." : undefined);
269
+ throw new Error("development" !== 'production' ? "No messages were configured on the provider." : undefined);
270
270
  }
271
271
 
272
272
  var retrievedMessages = namespace ? resolvePath(messages, namespace) : messages;
273
273
 
274
274
  if (!retrievedMessages) {
275
- throw new Error("development" !== "production" ? "No messages for namespace `" + namespace + "` found." : undefined);
275
+ throw new Error("development" !== 'production' ? "No messages for namespace `" + namespace + "` found." : undefined);
276
276
  }
277
277
 
278
278
  return retrievedMessages;
@@ -366,7 +366,7 @@ function createBaseTranslator(_ref2) {
366
366
  prepareTranslationValues(_extends({}, defaultTranslationValues, values)));
367
367
 
368
368
  if (formattedMessage == null) {
369
- throw new Error("development" !== "production" ? "Unable to format `" + key + "` in " + (namespace ? "namespace `" + namespace + "`" : 'messages') : undefined);
369
+ throw new Error("development" !== 'production' ? "Unable to format `" + key + "` in " + (namespace ? "namespace `" + namespace + "`" : 'messages') : undefined);
370
370
  } // Limit the function signature to return strings or React elements
371
371
 
372
372
 
@@ -427,13 +427,13 @@ function resolveNamespace(namespace, namespacePrefix) {
427
427
  return namespace === namespacePrefix ? undefined : namespace.slice((namespacePrefix + '.').length);
428
428
  }
429
429
 
430
- var _excluded$2 = ["getMessageFallback", "messages", "namespace", "onError"];
430
+ var _excluded$3 = ["getMessageFallback", "messages", "namespace", "onError"];
431
431
  function createTranslatorImpl(_ref, namespacePrefix) {
432
432
  var getMessageFallback = _ref.getMessageFallback,
433
433
  messages = _ref.messages,
434
434
  namespace = _ref.namespace,
435
435
  onError = _ref.onError,
436
- rest = _objectWithoutPropertiesLoose(_ref, _excluded$2);
436
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded$3);
437
437
 
438
438
  // The `namespacePrefix` is part of the type system.
439
439
  // See the comment in the function invocation.
@@ -479,7 +479,7 @@ function createTranslatorImpl(_ref, namespacePrefix) {
479
479
  return base;
480
480
  }
481
481
 
482
- var _excluded$1 = ["onError", "getMessageFallback", "messages", "namespace"];
482
+ var _excluded$2 = ["onError", "getMessageFallback", "messages", "namespace"];
483
483
  /**
484
484
  * Translates messages from the given namespace by using the ICU syntax.
485
485
  * See https://formatjs.io/docs/core-concepts/icu-syntax.
@@ -496,7 +496,7 @@ function createTranslator(_ref) {
496
496
  getMessageFallback = _ref$getMessageFallba === void 0 ? defaultGetMessageFallback : _ref$getMessageFallba,
497
497
  messages = _ref.messages,
498
498
  namespace = _ref.namespace,
499
- rest = _objectWithoutPropertiesLoose(_ref, _excluded$1);
499
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded$2);
500
500
 
501
501
  // We have to wrap the actual function so the type inference for the optional
502
502
  // namespace works correctly. See https://stackoverflow.com/a/71529575/343045
@@ -633,7 +633,7 @@ function createIntl(_ref) {
633
633
  if (globalNow) {
634
634
  now = globalNow;
635
635
  } else {
636
- throw new Error("development" !== "production" ? "The `now` parameter wasn't provided to `formatRelativeTime` and there was no global fallback configured on the provider." : undefined);
636
+ throw new Error("development" !== 'production' ? "The `now` parameter wasn't provided to `formatRelativeTime` and there was no global fallback configured on the provider." : undefined);
637
637
  }
638
638
  }
639
639
 
@@ -661,6 +661,8 @@ function createIntl(_ref) {
661
661
  };
662
662
  }
663
663
 
664
+ var IntlContext = /*#__PURE__*/React.createContext(undefined);
665
+
664
666
  function validateMessagesSegment(messages, invalidKeyLabels, parentPath) {
665
667
  Object.entries(messages).forEach(function (_ref) {
666
668
  var key = _ref[0],
@@ -689,33 +691,40 @@ function validateMessages(messages, onError) {
689
691
  }
690
692
  }
691
693
 
692
- var IntlContext = /*#__PURE__*/React.createContext(undefined);
694
+ var _excluded$1 = ["getMessageFallback", "messages", "onError"];
695
+ /**
696
+ * Enhances the incoming props with defaults.
697
+ */
693
698
 
694
- var _excluded = ["children", "onError", "getMessageFallback", "messages"];
695
- function IntlProvider(_ref) {
696
- var children = _ref.children,
697
- _ref$onError = _ref.onError,
698
- onError = _ref$onError === void 0 ? defaultOnError : _ref$onError,
699
- _ref$getMessageFallba = _ref.getMessageFallback,
700
- getMessageFallback = _ref$getMessageFallba === void 0 ? defaultGetMessageFallback : _ref$getMessageFallba,
699
+ function getIntlContextValue(_ref) {
700
+ var getMessageFallback = _ref.getMessageFallback,
701
701
  messages = _ref.messages,
702
- contextValues = _objectWithoutPropertiesLoose(_ref, _excluded);
702
+ onError = _ref.onError,
703
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded$1);
704
+
705
+ var finalOnError = onError || defaultOnError;
706
+ var finalGetMessageFallback = getMessageFallback || defaultGetMessageFallback;
703
707
 
704
708
  {
705
- // eslint-disable-next-line react-hooks/rules-of-hooks
706
- React.useEffect(function () {
707
- if (messages) {
708
- validateMessages(messages, onError);
709
- }
710
- }, [messages, onError]);
709
+ if (messages) {
710
+ validateMessages(messages, finalOnError);
711
+ }
711
712
  }
712
713
 
714
+ return _extends({}, rest, {
715
+ messages: messages,
716
+ onError: finalOnError,
717
+ getMessageFallback: finalGetMessageFallback
718
+ });
719
+ }
720
+
721
+ var _excluded = ["children"];
722
+ function IntlProvider(_ref) {
723
+ var children = _ref.children,
724
+ props = _objectWithoutPropertiesLoose(_ref, _excluded);
725
+
713
726
  return React__default["default"].createElement(IntlContext.Provider, {
714
- value: _extends({}, contextValues, {
715
- messages: messages,
716
- onError: onError,
717
- getMessageFallback: getMessageFallback
718
- })
727
+ value: getIntlContextValue(props)
719
728
  }, children);
720
729
  }
721
730