use-intl 3.0.0-beta.2 → 3.0.0-rc.5

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 (204) hide show
  1. package/_IntlProvider.d.ts +1 -0
  2. package/_useLocale.d.ts +1 -0
  3. package/core.d.ts +1 -1
  4. package/dist/_IntlProvider.js +7 -0
  5. package/dist/_useLocale.js +7 -0
  6. package/dist/core.js +3 -4
  7. package/dist/development/IntlContext-b5cc6be8.js +8 -0
  8. package/dist/development/_IntlProvider.js +27 -0
  9. package/dist/development/_useLocale-321e619f.js +19 -0
  10. package/dist/development/_useLocale.js +11 -0
  11. package/dist/development/core.js +91 -0
  12. package/dist/development/createFormatter-bcc5a49f.js +430 -0
  13. package/dist/development/index.js +29 -0
  14. package/dist/development/initializeConfig-0a0b87a7.js +120 -0
  15. package/dist/development/react.js +145 -0
  16. package/dist/esm/IntlContext-381f3ce4.js +1 -0
  17. package/dist/esm/_IntlProvider.js +1 -0
  18. package/dist/esm/_useLocale-89b32eb9.js +1 -0
  19. package/dist/esm/_useLocale.js +1 -0
  20. package/dist/esm/core.js +1 -0
  21. package/dist/esm/createFormatter-cccbd794.js +1 -0
  22. package/dist/esm/index.js +1 -0
  23. package/dist/esm/initializeConfig-29e7ba4c.js +1 -0
  24. package/dist/esm/react.js +1 -0
  25. package/dist/index.js +3 -4
  26. package/dist/production/IntlContext-381f3ce4.js +1 -0
  27. package/dist/production/_IntlProvider.js +1 -0
  28. package/dist/production/_useLocale-8e23751a.js +1 -0
  29. package/dist/production/_useLocale.js +1 -0
  30. package/dist/production/core.js +1 -0
  31. package/dist/production/createFormatter-8c0b8eb2.js +1 -0
  32. package/dist/production/index.js +1 -0
  33. package/dist/production/initializeConfig-984a566d.js +1 -0
  34. package/dist/production/react.js +1 -0
  35. package/dist/react.js +3 -4
  36. package/dist/types/src/_IntlProvider.d.ts +1 -0
  37. package/dist/types/src/_useLocale.d.ts +1 -0
  38. package/dist/{core → types/src/core}/AbstractIntlMessages.d.ts +9 -9
  39. package/dist/{core → types/src/core}/DateTimeFormatOptions.d.ts +73 -73
  40. package/dist/{core → types/src/core}/Formats.d.ts +8 -8
  41. package/dist/{core → types/src/core}/IntlConfig.d.ts +54 -54
  42. package/dist/{core → types/src/core}/IntlError.d.ts +14 -13
  43. package/dist/{core → types/src/core}/MessageFormatCache.d.ts +5 -5
  44. package/dist/{core → types/src/core}/NumberFormatOptions.d.ts +2 -2
  45. package/dist/types/src/core/RelativeTimeFormatOptions.d.ts +5 -0
  46. package/dist/{core → types/src/core}/TimeZone.d.ts +2 -2
  47. package/dist/{core → types/src/core}/TranslationValues.d.ts +6 -6
  48. package/dist/{core → types/src/core}/convertFormatsToIntlMessageFormat.d.ts +11 -11
  49. package/dist/{core → types/src/core}/createBaseTranslator.d.ts +21 -21
  50. package/dist/{core → types/src/core}/createFormatter.d.ts +20 -19
  51. package/dist/{core → types/src/core}/createTranslator.d.ts +47 -47
  52. package/dist/{core → types/src/core}/createTranslatorImpl.d.ts +13 -13
  53. package/dist/{core → types/src/core}/defaults.d.ts +11 -11
  54. package/dist/{core → types/src/core}/index.d.ts +15 -16
  55. package/dist/{core → types/src/core}/initializeConfig.d.ts +14 -13
  56. package/dist/{core → types/src/core}/resolveNamespace.d.ts +5 -5
  57. package/dist/{core → types/src/core}/utils/MessageKeys.d.ts +5 -5
  58. package/dist/{core → types/src/core}/utils/NamespaceKeys.d.ts +5 -5
  59. package/dist/{core → types/src/core}/utils/NestedKeyOf.d.ts +4 -4
  60. package/dist/{core → types/src/core}/utils/NestedValueOf.d.ts +2 -2
  61. package/dist/{core → types/src/core}/validateMessages.d.ts +3 -3
  62. package/dist/{core.d.ts → types/src/core.d.ts} +1 -1
  63. package/dist/{index.d.ts → types/src/index.d.ts} +2 -2
  64. package/dist/{react → types/src/react}/IntlContext.d.ts +13 -13
  65. package/dist/{react → types/src/react}/IntlProvider.d.ts +7 -7
  66. package/dist/{react → types/src/react}/index.d.ts +7 -8
  67. package/dist/{react → types/src/react}/useFormatter.d.ts +6 -6
  68. package/dist/{react → types/src/react}/useIntlContext.d.ts +10 -10
  69. package/dist/{react → types/src/react}/useLocale.d.ts +1 -1
  70. package/dist/types/src/react/useMessages.d.ts +2 -0
  71. package/dist/{react → types/src/react}/useNow.d.ts +23 -23
  72. package/dist/{react → types/src/react}/useTimeZone.d.ts +1 -1
  73. package/dist/{react → types/src/react}/useTranslations.d.ts +44 -44
  74. package/dist/{react → types/src/react}/useTranslationsImpl.d.ts +8 -8
  75. package/dist/{react.d.ts → types/src/react.d.ts} +1 -1
  76. package/dist/types/test/core/createFormatter.test.d.ts +1 -0
  77. package/dist/types/test/core/createTranslator.test.d.ts +1 -0
  78. package/dist/types/test/react/useFormatter.test.d.ts +1 -0
  79. package/dist/types/test/react/useLocale.test.d.ts +1 -0
  80. package/dist/types/test/react/useMessages.test.d.ts +1 -0
  81. package/dist/types/test/react/useNow.test.d.ts +1 -0
  82. package/dist/types/test/react/useTimeZone.test.d.ts +1 -0
  83. package/dist/types/test/react/useTranslations.test.d.ts +1 -0
  84. package/dist/{test → types/test}/setup.d.ts +1 -1
  85. package/package.json +33 -21
  86. package/react.d.ts +1 -1
  87. package/dist/_virtual/_rollupPluginBabelHelpers.esm.js +0 -102
  88. package/dist/_virtual/_rollupPluginBabelHelpers.esm.js.map +0 -1
  89. package/dist/_virtual/use-intl.esm.js +0 -102
  90. package/dist/_virtual/use-intl.esm.js.map +0 -1
  91. package/dist/core/IntlError.esm.js +0 -33
  92. package/dist/core/IntlError.esm.js.map +0 -1
  93. package/dist/core/convertFormatsToIntlMessageFormat.esm.js +0 -37
  94. package/dist/core/convertFormatsToIntlMessageFormat.esm.js.map +0 -1
  95. package/dist/core/createBaseTranslator.esm.js +0 -210
  96. package/dist/core/createBaseTranslator.esm.js.map +0 -1
  97. package/dist/core/createFormatter.esm.js +0 -138
  98. package/dist/core/createFormatter.esm.js.map +0 -1
  99. package/dist/core/createIntl.d.ts +0 -7
  100. package/dist/core/createIntl.esm.js +0 -14
  101. package/dist/core/createIntl.esm.js.map +0 -1
  102. package/dist/core/createTranslator.esm.js +0 -37
  103. package/dist/core/createTranslator.esm.js.map +0 -1
  104. package/dist/core/createTranslatorImpl.esm.js +0 -50
  105. package/dist/core/createTranslatorImpl.esm.js.map +0 -1
  106. package/dist/core/defaults.esm.js +0 -15
  107. package/dist/core/defaults.esm.js.map +0 -1
  108. package/dist/core/initializeConfig.esm.js +0 -29
  109. package/dist/core/initializeConfig.esm.js.map +0 -1
  110. package/dist/core/resolveNamespace.esm.js +0 -10
  111. package/dist/core/resolveNamespace.esm.js.map +0 -1
  112. package/dist/core/use-intl.esm.js +0 -33
  113. package/dist/core/use-intl.esm.js.map +0 -1
  114. package/dist/core/use-intl.esm10.js +0 -28
  115. package/dist/core/use-intl.esm10.js.map +0 -1
  116. package/dist/core/use-intl.esm11.js +0 -10
  117. package/dist/core/use-intl.esm11.js.map +0 -1
  118. package/dist/core/use-intl.esm2.js +0 -210
  119. package/dist/core/use-intl.esm2.js.map +0 -1
  120. package/dist/core/use-intl.esm3.js +0 -37
  121. package/dist/core/use-intl.esm3.js.map +0 -1
  122. package/dist/core/use-intl.esm4.js +0 -14
  123. package/dist/core/use-intl.esm4.js.map +0 -1
  124. package/dist/core/use-intl.esm5.js +0 -29
  125. package/dist/core/use-intl.esm5.js.map +0 -1
  126. package/dist/core/use-intl.esm6.js +0 -138
  127. package/dist/core/use-intl.esm6.js.map +0 -1
  128. package/dist/core/use-intl.esm7.js +0 -37
  129. package/dist/core/use-intl.esm7.js.map +0 -1
  130. package/dist/core/use-intl.esm8.js +0 -15
  131. package/dist/core/use-intl.esm8.js.map +0 -1
  132. package/dist/core/use-intl.esm9.js +0 -50
  133. package/dist/core/use-intl.esm9.js.map +0 -1
  134. package/dist/core/validateMessages.esm.js +0 -28
  135. package/dist/core/validateMessages.esm.js.map +0 -1
  136. package/dist/core.cjs.development.js +0 -93
  137. package/dist/core.cjs.development.js.map +0 -1
  138. package/dist/core.cjs.production.min.js +0 -2
  139. package/dist/core.cjs.production.min.js.map +0 -1
  140. package/dist/core.esm.js +0 -7
  141. package/dist/core.esm.js.map +0 -1
  142. package/dist/createIntl-34d4281e.js +0 -592
  143. package/dist/createIntl-34d4281e.js.map +0 -1
  144. package/dist/createIntl-bc325740.js +0 -2
  145. package/dist/createIntl-bc325740.js.map +0 -1
  146. package/dist/react/IntlContext.esm.js +0 -6
  147. package/dist/react/IntlContext.esm.js.map +0 -1
  148. package/dist/react/IntlProvider.esm.js +0 -22
  149. package/dist/react/IntlProvider.esm.js.map +0 -1
  150. package/dist/react/getInitializedConfig.d.ts +0 -1
  151. package/dist/react/use-intl.esm.js +0 -26
  152. package/dist/react/use-intl.esm.js.map +0 -1
  153. package/dist/react/use-intl.esm10.js +0 -13
  154. package/dist/react/use-intl.esm10.js.map +0 -1
  155. package/dist/react/use-intl.esm11.js +0 -6
  156. package/dist/react/use-intl.esm11.js.map +0 -1
  157. package/dist/react/use-intl.esm2.js +0 -8
  158. package/dist/react/use-intl.esm2.js.map +0 -1
  159. package/dist/react/use-intl.esm3.js +0 -30
  160. package/dist/react/use-intl.esm3.js.map +0 -1
  161. package/dist/react/use-intl.esm4.js +0 -22
  162. package/dist/react/use-intl.esm4.js.map +0 -1
  163. package/dist/react/use-intl.esm5.js +0 -24
  164. package/dist/react/use-intl.esm5.js.map +0 -1
  165. package/dist/react/use-intl.esm6.js +0 -45
  166. package/dist/react/use-intl.esm6.js.map +0 -1
  167. package/dist/react/use-intl.esm7.js +0 -8
  168. package/dist/react/use-intl.esm7.js.map +0 -1
  169. package/dist/react/use-intl.esm8.js +0 -8
  170. package/dist/react/use-intl.esm8.js.map +0 -1
  171. package/dist/react/use-intl.esm9.js +0 -36
  172. package/dist/react/use-intl.esm9.js.map +0 -1
  173. package/dist/react/useFormatter.esm.js +0 -24
  174. package/dist/react/useFormatter.esm.js.map +0 -1
  175. package/dist/react/useIntl.d.ts +0 -6
  176. package/dist/react/useIntl.esm.js +0 -30
  177. package/dist/react/useIntl.esm.js.map +0 -1
  178. package/dist/react/useIntlContext.esm.js +0 -13
  179. package/dist/react/useIntlContext.esm.js.map +0 -1
  180. package/dist/react/useLocale.esm.js +0 -8
  181. package/dist/react/useLocale.esm.js.map +0 -1
  182. package/dist/react/useMessages.d.ts +0 -1
  183. package/dist/react/useMessages.esm.js +0 -8
  184. package/dist/react/useMessages.esm.js.map +0 -1
  185. package/dist/react/useNow.esm.js +0 -45
  186. package/dist/react/useNow.esm.js.map +0 -1
  187. package/dist/react/useTimeZone.esm.js +0 -8
  188. package/dist/react/useTimeZone.esm.js.map +0 -1
  189. package/dist/react/useTranslations.esm.js +0 -26
  190. package/dist/react/useTranslations.esm.js.map +0 -1
  191. package/dist/react/useTranslationsImpl.esm.js +0 -36
  192. package/dist/react/useTranslationsImpl.esm.js.map +0 -1
  193. package/dist/react.cjs.development.js +0 -190
  194. package/dist/react.cjs.development.js.map +0 -1
  195. package/dist/react.cjs.production.min.js +0 -2
  196. package/dist/react.cjs.production.min.js.map +0 -1
  197. package/dist/react.esm.js +0 -9
  198. package/dist/react.esm.js.map +0 -1
  199. package/dist/use-intl.cjs.development.js +0 -842
  200. package/dist/use-intl.cjs.development.js.map +0 -1
  201. package/dist/use-intl.cjs.production.min.js +0 -2
  202. package/dist/use-intl.cjs.production.min.js.map +0 -1
  203. package/dist/use-intl.esm.js +0 -15
  204. package/dist/use-intl.esm.js.map +0 -1
@@ -0,0 +1,120 @@
1
+ 'use strict';
2
+
3
+ function _defineProperty(obj, key, value) {
4
+ key = _toPropertyKey(key);
5
+ if (key in obj) {
6
+ Object.defineProperty(obj, key, {
7
+ value: value,
8
+ enumerable: true,
9
+ configurable: true,
10
+ writable: true
11
+ });
12
+ } else {
13
+ obj[key] = value;
14
+ }
15
+ return obj;
16
+ }
17
+ function _toPrimitive(input, hint) {
18
+ if (typeof input !== "object" || input === null) return input;
19
+ var prim = input[Symbol.toPrimitive];
20
+ if (prim !== undefined) {
21
+ var res = prim.call(input, hint || "default");
22
+ if (typeof res !== "object") return res;
23
+ throw new TypeError("@@toPrimitive must return a primitive value.");
24
+ }
25
+ return (hint === "string" ? String : Number)(input);
26
+ }
27
+ function _toPropertyKey(arg) {
28
+ var key = _toPrimitive(arg, "string");
29
+ return typeof key === "symbol" ? key : String(key);
30
+ }
31
+
32
+ let IntlErrorCode = /*#__PURE__*/function (IntlErrorCode) {
33
+ IntlErrorCode["MISSING_MESSAGE"] = "MISSING_MESSAGE";
34
+ IntlErrorCode["MISSING_FORMAT"] = "MISSING_FORMAT";
35
+ IntlErrorCode["ENVIRONMENT_FALLBACK"] = "ENVIRONMENT_FALLBACK";
36
+ IntlErrorCode["INSUFFICIENT_PATH"] = "INSUFFICIENT_PATH";
37
+ IntlErrorCode["INVALID_MESSAGE"] = "INVALID_MESSAGE";
38
+ IntlErrorCode["INVALID_KEY"] = "INVALID_KEY";
39
+ IntlErrorCode["FORMATTING_ERROR"] = "FORMATTING_ERROR";
40
+ return IntlErrorCode;
41
+ }({});
42
+ class IntlError extends Error {
43
+ constructor(code, originalMessage) {
44
+ let message = code;
45
+ if (originalMessage) {
46
+ message += ': ' + originalMessage;
47
+ }
48
+ super(message);
49
+ _defineProperty(this, "code", void 0);
50
+ _defineProperty(this, "originalMessage", void 0);
51
+ this.code = code;
52
+ if (originalMessage) {
53
+ this.originalMessage = originalMessage;
54
+ }
55
+ }
56
+ }
57
+
58
+ /**
59
+ * Contains defaults that are used for all entry points into the core.
60
+ * See also `InitializedIntlConfiguration`.
61
+ */
62
+
63
+ function defaultGetMessageFallback(props) {
64
+ return [props.namespace, props.key].filter(part => part != null).join('.');
65
+ }
66
+ function defaultOnError(error) {
67
+ console.error(error);
68
+ }
69
+
70
+ function validateMessagesSegment(messages, invalidKeyLabels, parentPath) {
71
+ Object.entries(messages).forEach(_ref => {
72
+ let [key, messageOrMessages] = _ref;
73
+ if (key.includes('.')) {
74
+ let keyLabel = key;
75
+ if (parentPath) keyLabel += " (at ".concat(parentPath, ")");
76
+ invalidKeyLabels.push(keyLabel);
77
+ }
78
+ if (messageOrMessages != null && typeof messageOrMessages === 'object') {
79
+ validateMessagesSegment(messageOrMessages, invalidKeyLabels, [parentPath, key].filter(part => part != null).join('.'));
80
+ }
81
+ });
82
+ }
83
+ function validateMessages(messages, onError) {
84
+ const invalidKeyLabels = [];
85
+ validateMessagesSegment(messages, invalidKeyLabels);
86
+ if (invalidKeyLabels.length > 0) {
87
+ 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 ".concat(invalidKeyLabels.length === 1 ? 'key' : 'keys', ": ").concat(invalidKeyLabels.join(', '), "\n\nIf you're migrating from a flat structure, you can convert your messages as follows:\n\nimport {set} from \"lodash\";\n\nconst input = {\n \"one.one\": \"1.1\",\n \"one.two\": \"1.2\",\n \"two.one.one\": \"2.1.1\"\n};\n\nconst output = Object.entries(input).reduce(\n (acc, [key, value]) => set(acc, key, value),\n {}\n);\n\n// Output:\n//\n// {\n// \"one\": {\n// \"one\": \"1.1\",\n// \"two\": \"1.2\"\n// },\n// \"two\": {\n// \"one\": {\n// \"one\": \"2.1.1\"\n// }\n// }\n// }\n") ));
88
+ }
89
+ }
90
+
91
+ /**
92
+ * Enhances the incoming props with defaults.
93
+ */
94
+ function initializeConfig(_ref) {
95
+ let {
96
+ getMessageFallback,
97
+ messages,
98
+ onError,
99
+ ...rest
100
+ } = _ref;
101
+ const finalOnError = onError || defaultOnError;
102
+ const finalGetMessageFallback = getMessageFallback || defaultGetMessageFallback;
103
+ {
104
+ if (messages) {
105
+ validateMessages(messages, finalOnError);
106
+ }
107
+ }
108
+ return {
109
+ ...rest,
110
+ messages,
111
+ onError: finalOnError,
112
+ getMessageFallback: finalGetMessageFallback
113
+ };
114
+ }
115
+
116
+ exports.IntlError = IntlError;
117
+ exports.IntlErrorCode = IntlErrorCode;
118
+ exports.defaultGetMessageFallback = defaultGetMessageFallback;
119
+ exports.defaultOnError = defaultOnError;
120
+ exports.initializeConfig = initializeConfig;
@@ -0,0 +1,145 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _IntlProvider = require('./_IntlProvider.js');
6
+ var _useLocale = require('./_useLocale-321e619f.js');
7
+ var React = require('react');
8
+ var createFormatter = require('./createFormatter-bcc5a49f.js');
9
+ var initializeConfig = require('./initializeConfig-0a0b87a7.js');
10
+ require('./IntlContext-b5cc6be8.js');
11
+ require('intl-messageformat');
12
+
13
+ let hasWarnedForMissingTimezone = false;
14
+ const isServer = typeof window === 'undefined';
15
+ function useTranslationsImpl(allMessages, namespace, namespacePrefix) {
16
+ const {
17
+ defaultTranslationValues,
18
+ formats: globalFormats,
19
+ getMessageFallback,
20
+ locale,
21
+ messageFormatCache,
22
+ onError,
23
+ timeZone
24
+ } = _useLocale.useIntlContext();
25
+
26
+ // The `namespacePrefix` is part of the type system.
27
+ // See the comment in the hook invocation.
28
+ allMessages = allMessages[namespacePrefix];
29
+ namespace = createFormatter.resolveNamespace(namespace, namespacePrefix);
30
+ if (!timeZone && !hasWarnedForMissingTimezone && isServer) {
31
+ hasWarnedForMissingTimezone = true;
32
+ onError(new initializeConfig.IntlError(initializeConfig.IntlErrorCode.ENVIRONMENT_FALLBACK, "There is no `timeZone` configured, this can lead to markup mismatches caused by environment differences. Consider adding a global default: https://next-intl-docs.vercel.app/docs/configuration#time-zone" ));
33
+ }
34
+ const translate = React.useMemo(() => createFormatter.createBaseTranslator({
35
+ messageFormatCache,
36
+ getMessageFallback,
37
+ messages: allMessages,
38
+ defaultTranslationValues,
39
+ namespace,
40
+ onError,
41
+ formats: globalFormats,
42
+ locale,
43
+ timeZone
44
+ }), [messageFormatCache, getMessageFallback, allMessages, namespace, onError, defaultTranslationValues, globalFormats, locale, timeZone]);
45
+ return translate;
46
+ }
47
+
48
+ /**
49
+ * Translates messages from the given namespace by using the ICU syntax.
50
+ * See https://formatjs.io/docs/core-concepts/icu-syntax.
51
+ *
52
+ * If no namespace is provided, all available messages are returned.
53
+ * The namespace can also indicate nesting by using a dot
54
+ * (e.g. `namespace.Component`).
55
+ */
56
+ function useTranslations(namespace) {
57
+ const context = _useLocale.useIntlContext();
58
+ const messages = context.messages;
59
+
60
+ // We have to wrap the actual hook so the type inference for the optional
61
+ // namespace works correctly. See https://stackoverflow.com/a/71529575/343045
62
+ // The prefix ("!") is arbitrary.
63
+ return useTranslationsImpl({
64
+ '!': messages
65
+ },
66
+ // @ts-expect-error
67
+ namespace ? "!.".concat(namespace) : '!', '!');
68
+ }
69
+
70
+ function getNow() {
71
+ return new Date();
72
+ }
73
+
74
+ /**
75
+ * Reading the current date via `new Date()` in components should be avoided, as
76
+ * it causes components to be impure and can lead to flaky tests. Instead, this
77
+ * hook can be used.
78
+ *
79
+ * By default, it returns the time when the component mounts. If `updateInterval`
80
+ * is specified, the value will be updated based on the interval.
81
+ *
82
+ * You can however also return a static value from this hook, if you
83
+ * configure the `now` parameter on the context provider. Note however,
84
+ * that if `updateInterval` is configured in this case, the component
85
+ * will initialize with the global value, but will afterwards update
86
+ * continuously based on the interval.
87
+ *
88
+ * For unit tests, this can be mocked to a constant value. For end-to-end
89
+ * testing, an environment parameter can be passed to the `now` parameter
90
+ * of the provider to mock this to a static value.
91
+ */
92
+ function useNow(options) {
93
+ const updateInterval = options === null || options === void 0 ? void 0 : options.updateInterval;
94
+ const {
95
+ now: globalNow
96
+ } = _useLocale.useIntlContext();
97
+ const [now, setNow] = React.useState(globalNow || getNow());
98
+ React.useEffect(() => {
99
+ if (!updateInterval) return;
100
+ const intervalId = setInterval(() => {
101
+ setNow(getNow());
102
+ }, updateInterval);
103
+ return () => {
104
+ clearInterval(intervalId);
105
+ };
106
+ }, [globalNow, updateInterval]);
107
+ return now;
108
+ }
109
+
110
+ function useTimeZone() {
111
+ return _useLocale.useIntlContext().timeZone;
112
+ }
113
+
114
+ function useMessages() {
115
+ const context = _useLocale.useIntlContext();
116
+ if (!context.messages) {
117
+ throw new Error('No messages found. Have you configured them correctly? See https://next-intl-docs.vercel.app/docs/configuration#messages' );
118
+ }
119
+ return context.messages;
120
+ }
121
+
122
+ function useFormatter() {
123
+ const {
124
+ formats,
125
+ locale,
126
+ now: globalNow,
127
+ onError,
128
+ timeZone
129
+ } = _useLocale.useIntlContext();
130
+ return React.useMemo(() => createFormatter.createFormatter({
131
+ formats,
132
+ locale,
133
+ now: globalNow,
134
+ onError,
135
+ timeZone
136
+ }), [formats, globalNow, locale, onError, timeZone]);
137
+ }
138
+
139
+ exports.IntlProvider = _IntlProvider.IntlProvider;
140
+ exports.useLocale = _useLocale.useLocale;
141
+ exports.useFormatter = useFormatter;
142
+ exports.useMessages = useMessages;
143
+ exports.useNow = useNow;
144
+ exports.useTimeZone = useTimeZone;
145
+ exports.useTranslations = useTranslations;
@@ -0,0 +1 @@
1
+ "use strict";var t=require("react").createContext(void 0);exports.IntlContext=t;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("./initializeConfig-29e7ba4c.js"),r=require("./IntlContext-381f3ce4.js");function i(e){return e&&e.__esModule?e:{default:e}}var n=i(e);exports.IntlProvider=function(i){let{children:a,...o}=i;const[u]=e.useState((()=>new Map));return n.default.createElement(r.IntlContext.Provider,{value:{...t.initializeConfig(o),messageFormatCache:u}},a)};
@@ -0,0 +1 @@
1
+ "use strict";var t=require("react"),e=require("./IntlContext-381f3ce4.js");function r(){const r=t.useContext(e.IntlContext);if(!r)throw new Error("No intl context found. Have you configured the provider?");return r}exports.useIntlContext=r,exports.useLocale=function(){return r().locale};
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./_useLocale-89b32eb9.js");require("react"),require("./IntlContext-381f3ce4.js"),exports.useLocale=e.useLocale;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./initializeConfig-29e7ba4c.js"),r=require("./createFormatter-cccbd794.js");require("intl-messageformat"),require("react"),exports.IntlError=e.IntlError,exports.IntlErrorCode=e.IntlErrorCode,exports.initializeConfig=e.initializeConfig,exports.createBaseTranslator=r.createBaseTranslator,exports.createFormatter=r.createFormatter,exports.createTranslator=function(t){let{getMessageFallback:a=e.defaultGetMessageFallback,messages:s,namespace:n,onError:o=e.defaultOnError,...c}=t;return function(t,a){let{getMessageFallback:s,messages:n,namespace:o,onError:c,...i}=t;n=n[a],o=r.resolveNamespace(o,a);const l=r.createBaseTranslator({...i,onError:c,getMessageFallback:s,messages:n,namespace:o}),g=l.rich;function u(){return l(...arguments)}return u.rich=(r,t,a)=>{const n=g(r,t,a);if("string"!=typeof n){const t=new e.IntlError(e.IntlErrorCode.FORMATTING_ERROR,"`createTranslator` only accepts functions for rich text formatting that receive and return strings.\n\nE.g. t.rich('rich', {b: (chunks) => `<b>${chunks}</b>`})");return c(t),s({error:t,key:r,namespace:o})}return n},u.raw=l.raw,u}({...c,onError:o,getMessageFallback:a,messages:{"!":s},namespace:n?"!.".concat(n):"!"},"!")};
@@ -0,0 +1 @@
1
+ "use strict";var e=require("intl-messageformat"),r=require("react"),t=require("./initializeConfig-29e7ba4c.js");function n(e){return e&&e.__esModule?e:{default:e}}var o=n(e);function a(e,r){return e?Object.keys(e).reduce(((t,n)=>(t[n]={timeZone:r,...e[n]},t)),{}):e}function s(e,r,t){if(!e)throw new Error("No messages available at `".concat(t,"`."));let n=e;return r.split(".").forEach((e=>{const o=n[e];if(null==e||null==o)throw new Error("Could not resolve `".concat(r,"` in ").concat(t?"`".concat(t,"`"):"messages","."));n=o})),n}const i=60,c=60*i,u=24*c,l=7*u,m=u*(365/12),d=3*m,f=365*u,g={second:1,seconds:1,minute:i,minutes:i,hour:c,hours:c,day:u,days:u,week:l,weeks:l,month:m,months:m,quarter:d,quarters:d,year:f,years:f};exports.createBaseTranslator=function(e){const n=function(e){let{messages:r,namespace:n,onError:o=t.defaultOnError}=e;try{if(!r)throw new Error("No messages were configured on the provider.");const e=n?s(r,n):r;if(!e)throw new Error("No messages for namespace `".concat(n,"` found."));return e}catch(e){const r=new t.IntlError(t.IntlErrorCode.MISSING_MESSAGE,e.message);return o(r),r}}({messages:e.messages,namespace:e.namespace,onError:e.onError});return function(e){let{defaultTranslationValues:n,formats:i,getMessageFallback:c=t.defaultGetMessageFallback,locale:u,messageFormatCache:l,messagesOrError:m,namespace:d,onError:f,timeZone:g}=e;function E(e,r,n){const o=new t.IntlError(r,n);return f(o),c({error:o,key:e,namespace:d})}function p(e,f,p){if(m instanceof t.IntlError)return c({error:m,key:e,namespace:d});const I=m;let h;try{h=s(I,e,d)}catch(r){return E(e,t.IntlErrorCode.MISSING_MESSAGE,r.message)}function w(e){return e.filter((e=>null!=e)).join(".")}const v=w([u,d,e,String(h)]);let y;if(null!=l&&l.has(v))y=l.get(v);else{if("object"==typeof h){let r,n;return Array.isArray(h)?(r=t.IntlErrorCode.INVALID_MESSAGE,n="Message at `".concat(w([d,e]),"` resolved to an array, but only strings are supported. See https://next-intl-docs.vercel.app/docs/usage/messages#arrays-of-messages")):(r=t.IntlErrorCode.INSUFFICIENT_PATH,n="Message at `".concat(w([d,e]),"` resolved to an object, but only strings are supported. Use a `.` to retrieve nested messages. See https://next-intl-docs.vercel.app/docs/usage/messages#structuring-messages")),E(e,r,n)}const r=function(e,r){if(r)return;const t=e.replace(/'([{}])/gi,"$1");return/<|{/.test(t)?void 0:t}(h,f);if(r)return r;try{y=new o.default(h,u,function(e,r){const t=r?{...e,dateTime:a(e.dateTime,r)}:e,n=o.default.formats.date,s=r?a(n,r):n,i=o.default.formats.time,c=r?a(i,r):i;return{...t,date:{...s,...null==t?void 0:t.dateTime},time:{...c,...null==t?void 0:t.dateTime}}}({...i,...p},g))}catch(r){return E(e,t.IntlErrorCode.INVALID_MESSAGE,r.message)}null==l||l.set(v,y)}try{const t=y.format(function(e){if(0===Object.keys(e).length)return;const t={};return Object.keys(e).forEach((n=>{let o=0;const a=e[n];let s;s="function"==typeof a?e=>{const t=a(e);return r.isValidElement(t)?r.cloneElement(t,{key:n+o++}):t}:a,t[n]=s})),t}({...n,...f}));if(null==t)throw new Error("Unable to format `".concat(e,"` in ").concat(d?"namespace `".concat(d,"`"):"messages"));return r.isValidElement(t)||Array.isArray(t)||"string"==typeof t?t:String(t)}catch(r){return E(e,t.IntlErrorCode.FORMATTING_ERROR,r.message)}}function I(e,r,n){const o=p(e,r,n);return"string"!=typeof o?E(e,t.IntlErrorCode.INVALID_MESSAGE,"The message `".concat(e,"` in ").concat(d?"namespace `".concat(d,"`"):"messages"," didn't resolve to a string. If you want to format rich text, use `t.rich` instead.")):o}return I.rich=p,I.raw=e=>{if(m instanceof t.IntlError)return c({error:m,key:e,namespace:d});const r=m;try{return s(r,e,d)}catch(r){return E(e,t.IntlErrorCode.MISSING_MESSAGE,r.message)}},I}({...e,messagesOrError:n})},exports.createFormatter=function(e){let{formats:r,locale:n,now:o,onError:a=t.defaultOnError,timeZone:s}=e;function d(e,r,n,o){let s;try{s=function(e,r){let n;if("string"==typeof r){const o=r;if(n=null==e?void 0:e[o],!n){const e=new t.IntlError(t.IntlErrorCode.MISSING_FORMAT,"Format `".concat(o,"` is not available. You can configure it on the provider or provide custom options."));throw a(e),e}}else n=r;return n}(n,r)}catch(r){return String(e)}try{return o(s)}catch(r){return a(new t.IntlError(t.IntlErrorCode.FORMATTING_ERROR,r.message)),String(e)}}function E(e){return e instanceof Date||"number"==typeof e?new Date(e):void 0!==(null==e?void 0:e.now)?new Date(e.now):o||(a(new t.IntlError(t.IntlErrorCode.ENVIRONMENT_FALLBACK,"The `now` 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-docs.vercel.app/docs/configuration#now")),new Date)}return{dateTime:function(e,o){return d(e,o,null==r?void 0:r.dateTime,(r=>{var o;return null!==(o=r)&&void 0!==o&&o.timeZone||(s?r={...r,timeZone:s}:a(new t.IntlError(t.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-docs.vercel.app/docs/configuration#time-zone"))),new Intl.DateTimeFormat(n,r).format(e)}))},number:function(e,t){return d(e,t,null==r?void 0:r.number,(r=>new Intl.NumberFormat(n,r).format(e)))},relativeTime:function(e,r){try{const t=new Date(e),o=E(r),a=(t.getTime()-o.getTime())/1e3,s="number"==typeof r||r instanceof Date||void 0===(null==r?void 0:r.unit)?function(e){const r=Math.abs(e);return r<i?"second":r<c?"minute":r<u?"hour":r<l?"day":r<m?"week":r<f?"month":"year"}(a):r.unit,d=function(e,r){return Math.round(e/g[r])}(a,s);return new Intl.RelativeTimeFormat(n,{numeric:"auto"}).format(d,s)}catch(r){return a(new t.IntlError(t.IntlErrorCode.FORMATTING_ERROR,r.message)),String(e)}},list:function(e,t){return d(e,t,null==r?void 0:r.list,(r=>new Intl.ListFormat(n,r).format(e)))}}},exports.resolveNamespace=function(e,r){return e===r?void 0:e.slice((r+".").length)};
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./initializeConfig-29e7ba4c.js"),r=require("./core.js"),t=require("./createFormatter-cccbd794.js"),s=require("./_IntlProvider.js"),o=require("./react.js"),a=require("./_useLocale-89b32eb9.js");require("intl-messageformat"),require("react"),require("./IntlContext-381f3ce4.js"),exports.IntlError=e.IntlError,exports.IntlErrorCode=e.IntlErrorCode,exports.initializeConfig=e.initializeConfig,exports.createTranslator=r.createTranslator,exports.createBaseTranslator=t.createBaseTranslator,exports.createFormatter=t.createFormatter,exports.IntlProvider=s.IntlProvider,exports.useFormatter=o.useFormatter,exports.useMessages=o.useMessages,exports.useNow=o.useNow,exports.useTimeZone=o.useTimeZone,exports.useTranslations=o.useTranslations,exports.useLocale=a.useLocale;
@@ -0,0 +1 @@
1
+ "use strict";function e(e,n,t){return(n=function(e){var n=function(e,n){if("object"!=typeof e||null===e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var r=t.call(e,n||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===n?String:Number)(e)}(e,"string");return"symbol"==typeof n?n:String(n)}(n))in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}let n=function(e){return e.MISSING_MESSAGE="MISSING_MESSAGE",e.MISSING_FORMAT="MISSING_FORMAT",e.ENVIRONMENT_FALLBACK="ENVIRONMENT_FALLBACK",e.INSUFFICIENT_PATH="INSUFFICIENT_PATH",e.INVALID_MESSAGE="INVALID_MESSAGE",e.INVALID_KEY="INVALID_KEY",e.FORMATTING_ERROR="FORMATTING_ERROR",e}({});class t extends Error{constructor(n,t){let r=n;t&&(r+=": "+t),super(r),e(this,"code",void 0),e(this,"originalMessage",void 0),this.code=n,t&&(this.originalMessage=t)}}function r(e){return[e.namespace,e.key].filter((e=>null!=e)).join(".")}function o(e){console.error(e)}function i(e,n,t){Object.entries(e).forEach((e=>{let[r,o]=e;if(r.includes(".")){let e=r;t&&(e+=" (at ".concat(t,")")),n.push(e)}null!=o&&"object"==typeof o&&i(o,n,[t,r].filter((e=>null!=e)).join("."))}))}function s(e,r){const o=[];i(e,o),o.length>0&&r(new t(n.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 '.concat(1===o.length?"key":"keys",": ").concat(o.join(", "),'\n\nIf you\'re migrating from a flat structure, you can convert your messages as follows:\n\nimport {set} from "lodash";\n\nconst input = {\n "one.one": "1.1",\n "one.two": "1.2",\n "two.one.one": "2.1.1"\n};\n\nconst output = Object.entries(input).reduce(\n (acc, [key, value]) => set(acc, key, value),\n {}\n);\n\n// Output:\n//\n// {\n// "one": {\n// "one": "1.1",\n// "two": "1.2"\n// },\n// "two": {\n// "one": {\n// "one": "2.1.1"\n// }\n// }\n// }\n')))}exports.IntlError=t,exports.IntlErrorCode=n,exports.defaultGetMessageFallback=r,exports.defaultOnError=o,exports.initializeConfig=function(e){let{getMessageFallback:n,messages:t,onError:i,...a}=e;const c=i||o,l=n||r;return t&&s(t,c),{...a,messages:t,onError:c,getMessageFallback:l}};
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./_IntlProvider.js"),t=require("./_useLocale-89b32eb9.js"),r=require("react"),o=require("./createFormatter-cccbd794.js"),n=require("./initializeConfig-29e7ba4c.js");require("./IntlContext-381f3ce4.js"),require("intl-messageformat");let s=!1;const a="undefined"==typeof window;function u(){return new Date}exports.IntlProvider=e.IntlProvider,exports.useLocale=t.useLocale,exports.useFormatter=function(){const{formats:e,locale:n,now:s,onError:a,timeZone:u}=t.useIntlContext();return r.useMemo((()=>o.createFormatter({formats:e,locale:n,now:s,onError:a,timeZone:u})),[e,s,n,a,u])},exports.useMessages=function(){const e=t.useIntlContext();if(!e.messages)throw new Error("No messages found. Have you configured them correctly? See https://next-intl-docs.vercel.app/docs/configuration#messages");return e.messages},exports.useNow=function(e){const o=null==e?void 0:e.updateInterval,{now:n}=t.useIntlContext(),[s,a]=r.useState(n||u());return r.useEffect((()=>{if(!o)return;const e=setInterval((()=>{a(u())}),o);return()=>{clearInterval(e)}}),[n,o]),s},exports.useTimeZone=function(){return t.useIntlContext().timeZone},exports.useTranslations=function(e){return function(e,u,i){const{defaultTranslationValues:l,formats:c,getMessageFallback:m,locale:f,messageFormatCache:d,onError:g,timeZone:p}=t.useIntlContext();return e=e[i],u=o.resolveNamespace(u,i),p||s||!a||(s=!0,g(new n.IntlError(n.IntlErrorCode.ENVIRONMENT_FALLBACK,"There is no `timeZone` configured, this can lead to markup mismatches caused by environment differences. Consider adding a global default: https://next-intl-docs.vercel.app/docs/configuration#time-zone"))),r.useMemo((()=>o.createBaseTranslator({messageFormatCache:d,getMessageFallback:m,messages:e,defaultTranslationValues:l,namespace:u,onError:g,formats:c,locale:f,timeZone:p})),[d,m,e,u,g,l,c,f,p])}({"!":t.useIntlContext().messages},e?"!.".concat(e):"!","!")};
package/dist/index.js CHANGED
@@ -1,8 +1,7 @@
1
-
2
- 'use strict'
1
+ 'use strict';
3
2
 
4
3
  if (process.env.NODE_ENV === 'production') {
5
- module.exports = require('./use-intl.cjs.production.min.js')
4
+ module.exports = require('./production/index.js');
6
5
  } else {
7
- module.exports = require('./use-intl.cjs.development.js')
6
+ module.exports = require('./development/index.js');
8
7
  }
@@ -0,0 +1 @@
1
+ "use strict";var t=require("react").createContext(void 0);exports.IntlContext=t;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("./initializeConfig-984a566d.js"),r=require("./IntlContext-381f3ce4.js");function i(e){return e&&e.__esModule?e:{default:e}}var n=i(e);exports.IntlProvider=function(i){let{children:a,...o}=i;const[u]=e.useState((()=>new Map));return n.default.createElement(r.IntlContext.Provider,{value:{...t.initializeConfig(o),messageFormatCache:u}},a)};
@@ -0,0 +1 @@
1
+ "use strict";var t=require("react"),e=require("./IntlContext-381f3ce4.js");function r(){const r=t.useContext(e.IntlContext);if(!r)throw new Error(void 0);return r}exports.useIntlContext=r,exports.useLocale=function(){return r().locale};
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./_useLocale-8e23751a.js");require("react"),require("./IntlContext-381f3ce4.js"),exports.useLocale=e.useLocale;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./createFormatter-8c0b8eb2.js"),r=require("./initializeConfig-984a566d.js");require("intl-messageformat"),require("react"),exports.IntlError=e.IntlError,exports.IntlErrorCode=e.IntlErrorCode,exports.createBaseTranslator=e.createBaseTranslator,exports.createFormatter=e.createFormatter,exports.initializeConfig=r.initializeConfig,exports.createTranslator=function(a){let{getMessageFallback:t=r.defaultGetMessageFallback,messages:s,namespace:o,onError:n=r.defaultOnError,...c}=a;return function(r,a){let{getMessageFallback:t,messages:s,namespace:o,onError:n,...c}=r;s=s[a],o=e.resolveNamespace(o,a);const l=e.createBaseTranslator({...c,onError:n,getMessageFallback:t,messages:s,namespace:o}),i=l.rich;function g(){return l(...arguments)}return g.rich=(r,a,s)=>{const c=i(r,a,s);if("string"!=typeof c){const a=new e.IntlError(e.IntlErrorCode.FORMATTING_ERROR,void 0);return n(a),t({error:a,key:r,namespace:o})}return c},g.raw=l.raw,g}({...c,onError:n,getMessageFallback:t,messages:{"!":s},namespace:o?"!.".concat(o):"!"},"!")};
@@ -0,0 +1 @@
1
+ "use strict";var e=require("intl-messageformat"),t=require("react"),r=require("./initializeConfig-984a566d.js");function n(e){return e&&e.__esModule?e:{default:e}}var o=n(e);function i(e,t,r){return(t=function(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:String(t)}(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}let a=function(e){return e.MISSING_MESSAGE="MISSING_MESSAGE",e.MISSING_FORMAT="MISSING_FORMAT",e.ENVIRONMENT_FALLBACK="ENVIRONMENT_FALLBACK",e.INSUFFICIENT_PATH="INSUFFICIENT_PATH",e.INVALID_MESSAGE="INVALID_MESSAGE",e.INVALID_KEY="INVALID_KEY",e.FORMATTING_ERROR="FORMATTING_ERROR",e}({});class s extends Error{constructor(e,t){let r=e;t&&(r+=": "+t),super(r),i(this,"code",void 0),i(this,"originalMessage",void 0),this.code=e,t&&(this.originalMessage=t)}}function u(e,t){return e?Object.keys(e).reduce(((r,n)=>(r[n]={timeZone:t,...e[n]},r)),{}):e}function c(e,t,r){if(!e)throw new Error(void 0);let n=e;return t.split(".").forEach((e=>{const t=n[e];if(null==e||null==t)throw new Error(void 0);n=t})),n}const l=60,f=60*l,m=24*f,E=7*m,d=m*(365/12),I=3*d,S=365*m,g={second:1,seconds:1,minute:l,minutes:l,hour:f,hours:f,day:m,days:m,week:E,weeks:E,month:d,months:d,quarter:I,quarters:I,year:S,years:S};exports.IntlError=s,exports.IntlErrorCode=a,exports.createBaseTranslator=function(e){const n=function(e){let{messages:t,namespace:n,onError:o=r.defaultOnError}=e;try{if(!t)throw new Error(void 0);const e=n?c(t,n):t;if(!e)throw new Error(void 0);return e}catch(e){const t=new s(a.MISSING_MESSAGE,e.message);return o(t),t}}({messages:e.messages,namespace:e.namespace,onError:e.onError});return function(e){let{defaultTranslationValues:n,formats:i,getMessageFallback:l=r.defaultGetMessageFallback,locale:f,messageFormatCache:m,messagesOrError:E,namespace:d,onError:I,timeZone:S}=e;function g(e,t,r){const n=new s(t,r);return I(n),l({error:n,key:e,namespace:d})}function N(e,r,I){if(E instanceof s)return l({error:E,key:e,namespace:d});const N=E;let A;try{A=c(N,e)}catch(t){return g(e,a.MISSING_MESSAGE,t.message)}function v(e){return e.filter((e=>null!=e)).join(".")}const y=v([f,d,e,String(A)]);let w;if(null!=m&&m.has(y))w=m.get(y);else{if("object"==typeof A){let t,r;return t=Array.isArray(A)?a.INVALID_MESSAGE:a.INSUFFICIENT_PATH,g(e,t,r)}const t=function(e,t){if(t)return;const r=e.replace(/'([{}])/gi,"$1");return/<|{/.test(r)?void 0:r}(A,r);if(t)return t;try{w=new o.default(A,f,function(e,t){const r=t?{...e,dateTime:u(e.dateTime,t)}:e,n=o.default.formats.date,i=t?u(n,t):n,a=o.default.formats.time,s=t?u(a,t):a;return{...r,date:{...i,...null==r?void 0:r.dateTime},time:{...s,...null==r?void 0:r.dateTime}}}({...i,...I},S))}catch(t){return g(e,a.INVALID_MESSAGE,t.message)}null==m||m.set(y,w)}try{const e=w.format(function(e){if(0===Object.keys(e).length)return;const r={};return Object.keys(e).forEach((n=>{let o=0;const i=e[n];let a;a="function"==typeof i?e=>{const r=i(e);return t.isValidElement(r)?t.cloneElement(r,{key:n+o++}):r}:i,r[n]=a})),r}({...n,...r}));if(null==e)throw new Error(void 0);return t.isValidElement(e)||Array.isArray(e)||"string"==typeof e?e:String(e)}catch(t){return g(e,a.FORMATTING_ERROR,t.message)}}function A(e,t,r){const n=N(e,t,r);return"string"!=typeof n?g(e,a.INVALID_MESSAGE,void 0):n}return A.rich=N,A.raw=e=>{if(E instanceof s)return l({error:E,key:e,namespace:d});const t=E;try{return c(t,e)}catch(t){return g(e,a.MISSING_MESSAGE,t.message)}},A}({...e,messagesOrError:n})},exports.createFormatter=function(e){let{formats:t,locale:n,now:o,onError:i=r.defaultOnError,timeZone:u}=e;function c(e,t,r,n){let o;try{o=function(e,t){let r;if("string"==typeof t){if(r=null==e?void 0:e[t],!r){const e=new s(a.MISSING_FORMAT,void 0);throw i(e),e}}else r=t;return r}(r,t)}catch(t){return String(e)}try{return n(o)}catch(t){return i(new s(a.FORMATTING_ERROR,t.message)),String(e)}}function I(e){return e instanceof Date||"number"==typeof e?new Date(e):void 0!==(null==e?void 0:e.now)?new Date(e.now):o||(i(new s(a.ENVIRONMENT_FALLBACK,void 0)),new Date)}return{dateTime:function(e,r){return c(e,r,null==t?void 0:t.dateTime,(t=>{var r;return null!==(r=t)&&void 0!==r&&r.timeZone||(u?t={...t,timeZone:u}:i(new s(a.ENVIRONMENT_FALLBACK,void 0))),new Intl.DateTimeFormat(n,t).format(e)}))},number:function(e,r){return c(e,r,null==t?void 0:t.number,(t=>new Intl.NumberFormat(n,t).format(e)))},relativeTime:function(e,t){try{const r=new Date(e),o=I(t),i=(r.getTime()-o.getTime())/1e3,a="number"==typeof t||t instanceof Date||void 0===(null==t?void 0:t.unit)?function(e){const t=Math.abs(e);return t<l?"second":t<f?"minute":t<m?"hour":t<E?"day":t<d?"week":t<S?"month":"year"}(i):t.unit,s=function(e,t){return Math.round(e/g[t])}(i,a);return new Intl.RelativeTimeFormat(n,{numeric:"auto"}).format(s,a)}catch(t){return i(new s(a.FORMATTING_ERROR,t.message)),String(e)}},list:function(e,r){return c(e,r,null==t?void 0:t.list,(t=>new Intl.ListFormat(n,t).format(e)))}}},exports.resolveNamespace=function(e,t){return e===t?void 0:e.slice((t+".").length)};
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./createFormatter-8c0b8eb2.js"),r=require("./core.js"),t=require("./initializeConfig-984a566d.js"),s=require("./_IntlProvider.js"),o=require("./react.js"),a=require("./_useLocale-8e23751a.js");require("intl-messageformat"),require("react"),require("./IntlContext-381f3ce4.js"),exports.IntlError=e.IntlError,exports.IntlErrorCode=e.IntlErrorCode,exports.createBaseTranslator=e.createBaseTranslator,exports.createFormatter=e.createFormatter,exports.createTranslator=r.createTranslator,exports.initializeConfig=t.initializeConfig,exports.IntlProvider=s.IntlProvider,exports.useFormatter=o.useFormatter,exports.useMessages=o.useMessages,exports.useNow=o.useNow,exports.useTimeZone=o.useTimeZone,exports.useTranslations=o.useTranslations,exports.useLocale=a.useLocale;
@@ -0,0 +1 @@
1
+ "use strict";function e(e){return[e.namespace,e.key].filter((e=>null!=e)).join(".")}function r(e){console.error(e)}exports.defaultGetMessageFallback=e,exports.defaultOnError=r,exports.initializeConfig=function(s){let{getMessageFallback:t,messages:n,onError:a,...o}=s;return{...o,messages:n,onError:a||r,getMessageFallback:t||e}};
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./_IntlProvider.js"),t=require("./_useLocale-8e23751a.js"),r=require("react"),o=require("./createFormatter-8c0b8eb2.js");require("./initializeConfig-984a566d.js"),require("./IntlContext-381f3ce4.js"),require("intl-messageformat");let n=!1;const s="undefined"==typeof window;function a(){return new Date}exports.IntlProvider=e.IntlProvider,exports.useLocale=t.useLocale,exports.useFormatter=function(){const{formats:e,locale:n,now:s,onError:a,timeZone:u}=t.useIntlContext();return r.useMemo((()=>o.createFormatter({formats:e,locale:n,now:s,onError:a,timeZone:u})),[e,s,n,a,u])},exports.useMessages=function(){const e=t.useIntlContext();if(!e.messages)throw new Error(void 0);return e.messages},exports.useNow=function(e){const o=null==e?void 0:e.updateInterval,{now:n}=t.useIntlContext(),[s,u]=r.useState(n||a());return r.useEffect((()=>{if(!o)return;const e=setInterval((()=>{u(a())}),o);return()=>{clearInterval(e)}}),[n,o]),s},exports.useTimeZone=function(){return t.useIntlContext().timeZone},exports.useTranslations=function(e){return function(e,a,u){const{defaultTranslationValues:l,formats:i,getMessageFallback:c,locale:m,messageFormatCache:f,onError:I,timeZone:d}=t.useIntlContext();return e=e[u],a=o.resolveNamespace(a,u),d||n||!s||(n=!0,I(new o.IntlError(o.IntlErrorCode.ENVIRONMENT_FALLBACK,void 0))),r.useMemo((()=>o.createBaseTranslator({messageFormatCache:f,getMessageFallback:c,messages:e,defaultTranslationValues:l,namespace:a,onError:I,formats:i,locale:m,timeZone:d})),[f,c,e,a,I,l,i,m,d])}({"!":t.useIntlContext().messages},e?"!.".concat(e):"!","!")};
package/dist/react.js CHANGED
@@ -1,8 +1,7 @@
1
-
2
- 'use strict'
1
+ 'use strict';
3
2
 
4
3
  if (process.env.NODE_ENV === 'production') {
5
- module.exports = require('./react.cjs.production.min.js')
4
+ module.exports = require('./production/react.js');
6
5
  } else {
7
- module.exports = require('./react.cjs.development.js')
6
+ module.exports = require('./development/react.js');
8
7
  }
@@ -0,0 +1 @@
1
+ export { default as IntlProvider } from './react/IntlProvider';
@@ -0,0 +1 @@
1
+ export { default as useLocale } from './react/useLocale';
@@ -1,9 +1,9 @@
1
- /** A generic type that describes the shape of messages.
2
- *
3
- * Optionally `IntlMessages` can be provided to get type safety for message
4
- * namespaces and keys. See https://next-intl-docs.vercel.app/docs/usage/typescript
5
- */
6
- type AbstractIntlMessages = {
7
- [id: string]: AbstractIntlMessages | string;
8
- };
9
- export default AbstractIntlMessages;
1
+ /** A generic type that describes the shape of messages.
2
+ *
3
+ * Optionally `IntlMessages` can be provided to get type safety for message
4
+ * namespaces and keys. See https://next-intl-docs.vercel.app/docs/usage/typescript
5
+ */
6
+ type AbstractIntlMessages = {
7
+ [id: string]: AbstractIntlMessages | string;
8
+ };
9
+ export default AbstractIntlMessages;
@@ -1,73 +1,73 @@
1
- import TimeZone from './TimeZone';
2
- /**
3
- * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat
4
- */
5
- type DateTimeFormatOptions = Intl.DateTimeFormatOptions & {
6
- /**
7
- * Examples:
8
- * - numeric: "2021"
9
- * - 2-digit: "21"
10
- */
11
- year?: 'numeric' | '2-digit';
12
- /** Examples:
13
- * - numeric: "3"
14
- * - 2-digit: "03"
15
- * - long: "March"
16
- * - short: "Mar"
17
- * - narrow: "M"
18
- */
19
- month?: 'numeric' | '2-digit' | 'long' | 'short' | 'narrow';
20
- /** Examples:
21
- * - numeric: "2"
22
- * - 2-digit: "02"
23
- */
24
- day?: 'numeric' | '2-digit';
25
- /** Examples:
26
- * - numeric: "2"
27
- * - 2-digit: "02"
28
- */
29
- hour?: 'numeric' | '2-digit';
30
- /** Examples:
31
- * - numeric: "2"
32
- * - 2-digit: "02"
33
- */
34
- minute?: 'numeric' | '2-digit';
35
- /** Examples:
36
- * - numeric: "2"
37
- * - 2-digit: "02"
38
- */
39
- second?: 'numeric' | '2-digit';
40
- /** Examples:
41
- * - long: "Thursday"
42
- * - short: "Thu"
43
- * - narrow: "T"
44
- */
45
- weekday?: 'long' | 'short' | 'narrow';
46
- /** Examples:
47
- * - long: "Anno Domini"
48
- * - short: "AD", narrow "A"
49
- */
50
- era?: 'long' | 'short' | 'narrow';
51
- /** If this is set to `true`, a 12-hour am/pm format is used. Otherwise a 24-hour time.
52
- *
53
- */
54
- hour12?: boolean;
55
- /** Examples:
56
- * - long: "Pacific Daylight Time"
57
- * - short: "PDT"
58
- */
59
- timeZoneName?: 'long' | 'short';
60
- /**
61
- * One of the [database names from the TZ database](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List).
62
- */
63
- timeZone?: TimeZone;
64
- localeMatcher?: 'best fit' | 'lookup';
65
- formatMatcher?: 'best fit' | 'basic';
66
- dateStyle?: 'full' | 'long' | 'medium' | 'short';
67
- timeStyle?: 'full' | 'long' | 'medium' | 'short';
68
- calendar?: 'buddhist' | 'chinese' | 'coptic' | 'ethiopia' | 'ethiopic' | 'gregory' | 'hebrew' | 'indian' | 'islamic' | 'iso8601' | 'japanese' | 'persian' | 'roc';
69
- dayPeriod?: 'narrow' | 'short' | 'long';
70
- numberingSystem?: 'arab' | 'arabext' | 'bali' | 'beng' | 'deva' | 'fullwide' | 'gujr' | 'guru' | 'hanidec' | 'khmr' | 'knda' | 'laoo' | 'latn' | 'limb' | 'mlym' | 'mong' | 'mymr' | 'orya' | 'tamldec' | 'telu' | 'thai' | 'tibt';
71
- hourCycle?: 'h11' | 'h12' | 'h23' | 'h24';
72
- };
73
- export default DateTimeFormatOptions;
1
+ import TimeZone from './TimeZone';
2
+ /**
3
+ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat
4
+ */
5
+ type DateTimeFormatOptions = Intl.DateTimeFormatOptions & {
6
+ /**
7
+ * Examples:
8
+ * - numeric: "2021"
9
+ * - 2-digit: "21"
10
+ */
11
+ year?: 'numeric' | '2-digit';
12
+ /** Examples:
13
+ * - numeric: "3"
14
+ * - 2-digit: "03"
15
+ * - long: "March"
16
+ * - short: "Mar"
17
+ * - narrow: "M"
18
+ */
19
+ month?: 'numeric' | '2-digit' | 'long' | 'short' | 'narrow';
20
+ /** Examples:
21
+ * - numeric: "2"
22
+ * - 2-digit: "02"
23
+ */
24
+ day?: 'numeric' | '2-digit';
25
+ /** Examples:
26
+ * - numeric: "2"
27
+ * - 2-digit: "02"
28
+ */
29
+ hour?: 'numeric' | '2-digit';
30
+ /** Examples:
31
+ * - numeric: "2"
32
+ * - 2-digit: "02"
33
+ */
34
+ minute?: 'numeric' | '2-digit';
35
+ /** Examples:
36
+ * - numeric: "2"
37
+ * - 2-digit: "02"
38
+ */
39
+ second?: 'numeric' | '2-digit';
40
+ /** Examples:
41
+ * - long: "Thursday"
42
+ * - short: "Thu"
43
+ * - narrow: "T"
44
+ */
45
+ weekday?: 'long' | 'short' | 'narrow';
46
+ /** Examples:
47
+ * - long: "Anno Domini"
48
+ * - short: "AD", narrow "A"
49
+ */
50
+ era?: 'long' | 'short' | 'narrow';
51
+ /** If this is set to `true`, a 12-hour am/pm format is used. Otherwise a 24-hour time.
52
+ *
53
+ */
54
+ hour12?: boolean;
55
+ /** Examples:
56
+ * - long: "Pacific Daylight Time"
57
+ * - short: "PDT"
58
+ */
59
+ timeZoneName?: 'long' | 'short';
60
+ /**
61
+ * One of the [database names from the TZ database](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List).
62
+ */
63
+ timeZone?: TimeZone;
64
+ localeMatcher?: 'best fit' | 'lookup';
65
+ formatMatcher?: 'best fit' | 'basic';
66
+ dateStyle?: 'full' | 'long' | 'medium' | 'short';
67
+ timeStyle?: 'full' | 'long' | 'medium' | 'short';
68
+ calendar?: 'buddhist' | 'chinese' | 'coptic' | 'ethiopia' | 'ethiopic' | 'gregory' | 'hebrew' | 'indian' | 'islamic' | 'iso8601' | 'japanese' | 'persian' | 'roc';
69
+ dayPeriod?: 'narrow' | 'short' | 'long';
70
+ numberingSystem?: 'arab' | 'arabext' | 'bali' | 'beng' | 'deva' | 'fullwide' | 'gujr' | 'guru' | 'hanidec' | 'khmr' | 'knda' | 'laoo' | 'latn' | 'limb' | 'mlym' | 'mong' | 'mymr' | 'orya' | 'tamldec' | 'telu' | 'thai' | 'tibt';
71
+ hourCycle?: 'h11' | 'h12' | 'h23' | 'h24';
72
+ };
73
+ export default DateTimeFormatOptions;
@@ -1,8 +1,8 @@
1
- import DateTimeFormatOptions from './DateTimeFormatOptions';
2
- import NumberFormatOptions from './NumberFormatOptions';
3
- type Formats = {
4
- number: Record<string, NumberFormatOptions>;
5
- dateTime: Record<string, DateTimeFormatOptions>;
6
- list: Record<string, Intl.ListFormatOptions>;
7
- };
8
- export default Formats;
1
+ import DateTimeFormatOptions from './DateTimeFormatOptions';
2
+ import NumberFormatOptions from './NumberFormatOptions';
3
+ type Formats = {
4
+ number: Record<string, NumberFormatOptions>;
5
+ dateTime: Record<string, DateTimeFormatOptions>;
6
+ list: Record<string, Intl.ListFormatOptions>;
7
+ };
8
+ export default Formats;