use-intl 0.0.0-canary-5bbd7ad56b530e283b07cff950de61d6af81f00c

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 (91) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +83 -0
  3. package/_IntlProvider.d.ts +1 -0
  4. package/_useLocale.d.ts +1 -0
  5. package/core.d.ts +1 -0
  6. package/dist/_IntlProvider.js +7 -0
  7. package/dist/_useLocale.js +7 -0
  8. package/dist/core.js +7 -0
  9. package/dist/development/IntlContext-BKfsnzBx.js +7 -0
  10. package/dist/development/_IntlProvider.js +61 -0
  11. package/dist/development/_useLocale-0Rl9uR82.js +19 -0
  12. package/dist/development/_useLocale.js +11 -0
  13. package/dist/development/core.js +69 -0
  14. package/dist/development/createFormatter-TZTkYRKI.js +542 -0
  15. package/dist/development/index.js +31 -0
  16. package/dist/development/initializeConfig-o7L_y07P.js +185 -0
  17. package/dist/development/react.js +151 -0
  18. package/dist/esm/IntlContext-DoS4CDM3.js +1 -0
  19. package/dist/esm/_IntlProvider.js +1 -0
  20. package/dist/esm/_useLocale-v-ZT5JoE.js +1 -0
  21. package/dist/esm/_useLocale.js +1 -0
  22. package/dist/esm/core.js +1 -0
  23. package/dist/esm/createFormatter-D1WNHqdE.js +1 -0
  24. package/dist/esm/index.js +1 -0
  25. package/dist/esm/initializeConfig-D2A8plWf.js +1 -0
  26. package/dist/esm/react.js +1 -0
  27. package/dist/index.js +7 -0
  28. package/dist/production/IntlContext-DcFt0tgW.js +1 -0
  29. package/dist/production/_IntlProvider.js +1 -0
  30. package/dist/production/_useLocale-CpTrqBDt.js +1 -0
  31. package/dist/production/_useLocale.js +1 -0
  32. package/dist/production/core.js +1 -0
  33. package/dist/production/createFormatter-CTr0qKAI.js +1 -0
  34. package/dist/production/index.js +1 -0
  35. package/dist/production/initializeConfig-AbYTngyP.js +1 -0
  36. package/dist/production/react.js +1 -0
  37. package/dist/react.js +7 -0
  38. package/dist/types/src/_IntlProvider.d.ts +1 -0
  39. package/dist/types/src/_useLocale.d.ts +1 -0
  40. package/dist/types/src/core/AbstractIntlMessages.d.ts +9 -0
  41. package/dist/types/src/core/DateTimeFormatOptions.d.ts +73 -0
  42. package/dist/types/src/core/Formats.d.ts +8 -0
  43. package/dist/types/src/core/IntlConfig.d.ts +58 -0
  44. package/dist/types/src/core/IntlError.d.ts +14 -0
  45. package/dist/types/src/core/NumberFormatOptions.d.ts +3 -0
  46. package/dist/types/src/core/RelativeTimeFormatOptions.d.ts +7 -0
  47. package/dist/types/src/core/TimeZone.d.ts +2 -0
  48. package/dist/types/src/core/TranslationValues.d.ts +6 -0
  49. package/dist/types/src/core/convertFormatsToIntlMessageFormat.d.ts +11 -0
  50. package/dist/types/src/core/createBaseTranslator.d.ts +24 -0
  51. package/dist/types/src/core/createFormatter.d.ts +27 -0
  52. package/dist/types/src/core/createFormatter.test.d.ts +1 -0
  53. package/dist/types/src/core/createTranslator.d.ts +71 -0
  54. package/dist/types/src/core/createTranslator.test.d.ts +1 -0
  55. package/dist/types/src/core/createTranslatorImpl.d.ts +17 -0
  56. package/dist/types/src/core/defaults.d.ts +11 -0
  57. package/dist/types/src/core/formatters.d.ts +25 -0
  58. package/dist/types/src/core/index.d.ts +16 -0
  59. package/dist/types/src/core/initializeConfig.d.ts +13 -0
  60. package/dist/types/src/core/joinPath.d.ts +1 -0
  61. package/dist/types/src/core/resolveNamespace.d.ts +5 -0
  62. package/dist/types/src/core/utils/MessageKeys.d.ts +5 -0
  63. package/dist/types/src/core/utils/NamespaceKeys.d.ts +5 -0
  64. package/dist/types/src/core/utils/NestedKeyOf.d.ts +4 -0
  65. package/dist/types/src/core/utils/NestedValueOf.d.ts +2 -0
  66. package/dist/types/src/core/validateMessages.d.ts +3 -0
  67. package/dist/types/src/core.d.ts +1 -0
  68. package/dist/types/src/index.d.ts +2 -0
  69. package/dist/types/src/react/IntlContext.d.ts +8 -0
  70. package/dist/types/src/react/IntlProvider.d.ts +7 -0
  71. package/dist/types/src/react/IntlProvider.test.d.ts +1 -0
  72. package/dist/types/src/react/index.d.ts +7 -0
  73. package/dist/types/src/react/index.test.d.ts +1 -0
  74. package/dist/types/src/react/useFormatter.d.ts +2 -0
  75. package/dist/types/src/react/useFormatter.test.d.ts +1 -0
  76. package/dist/types/src/react/useIntlContext.d.ts +2 -0
  77. package/dist/types/src/react/useLocale.d.ts +1 -0
  78. package/dist/types/src/react/useLocale.test.d.ts +1 -0
  79. package/dist/types/src/react/useMessages.d.ts +2 -0
  80. package/dist/types/src/react/useMessages.test.d.ts +1 -0
  81. package/dist/types/src/react/useNow.d.ts +23 -0
  82. package/dist/types/src/react/useNow.test.d.ts +1 -0
  83. package/dist/types/src/react/useTimeZone.d.ts +1 -0
  84. package/dist/types/src/react/useTimeZone.test.d.ts +1 -0
  85. package/dist/types/src/react/useTranslations.d.ts +62 -0
  86. package/dist/types/src/react/useTranslations.test.d.ts +1 -0
  87. package/dist/types/src/react/useTranslationsImpl.d.ts +9 -0
  88. package/dist/types/src/react.d.ts +1 -0
  89. package/dist/types/test/setup.d.ts +1 -0
  90. package/package.json +73 -0
  91. package/react.d.ts +1 -0
@@ -0,0 +1,185 @@
1
+ 'use strict';
2
+
3
+ var fastMemoize = require('@formatjs/fast-memoize');
4
+
5
+ function _defineProperty(e, r, t) {
6
+ return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
7
+ value: t,
8
+ enumerable: !0,
9
+ configurable: !0,
10
+ writable: !0
11
+ }) : e[r] = t, e;
12
+ }
13
+ function _toPrimitive(t, r) {
14
+ if ("object" != typeof t || !t) return t;
15
+ var e = t[Symbol.toPrimitive];
16
+ if (void 0 !== e) {
17
+ var i = e.call(t, r || "default");
18
+ if ("object" != typeof i) return i;
19
+ throw new TypeError("@@toPrimitive must return a primitive value.");
20
+ }
21
+ return ("string" === r ? String : Number)(t);
22
+ }
23
+ function _toPropertyKey(t) {
24
+ var i = _toPrimitive(t, "string");
25
+ return "symbol" == typeof i ? i : i + "";
26
+ }
27
+
28
+ let IntlErrorCode = /*#__PURE__*/function (IntlErrorCode) {
29
+ IntlErrorCode["MISSING_MESSAGE"] = "MISSING_MESSAGE";
30
+ IntlErrorCode["MISSING_FORMAT"] = "MISSING_FORMAT";
31
+ IntlErrorCode["ENVIRONMENT_FALLBACK"] = "ENVIRONMENT_FALLBACK";
32
+ IntlErrorCode["INSUFFICIENT_PATH"] = "INSUFFICIENT_PATH";
33
+ IntlErrorCode["INVALID_MESSAGE"] = "INVALID_MESSAGE";
34
+ IntlErrorCode["INVALID_KEY"] = "INVALID_KEY";
35
+ IntlErrorCode["FORMATTING_ERROR"] = "FORMATTING_ERROR";
36
+ return IntlErrorCode;
37
+ }({});
38
+ class IntlError extends Error {
39
+ constructor(code, originalMessage) {
40
+ let message = code;
41
+ if (originalMessage) {
42
+ message += ': ' + originalMessage;
43
+ }
44
+ super(message);
45
+ _defineProperty(this, "code", void 0);
46
+ _defineProperty(this, "originalMessage", void 0);
47
+ this.code = code;
48
+ if (originalMessage) {
49
+ this.originalMessage = originalMessage;
50
+ }
51
+ }
52
+ }
53
+
54
+ function joinPath() {
55
+ for (var _len = arguments.length, parts = new Array(_len), _key = 0; _key < _len; _key++) {
56
+ parts[_key] = arguments[_key];
57
+ }
58
+ return parts.filter(Boolean).join('.');
59
+ }
60
+
61
+ /**
62
+ * Contains defaults that are used for all entry points into the core.
63
+ * See also `InitializedIntlConfiguration`.
64
+ */
65
+
66
+ function defaultGetMessageFallback(props) {
67
+ return joinPath(props.namespace, props.key);
68
+ }
69
+ function defaultOnError(error) {
70
+ console.error(error);
71
+ }
72
+
73
+ // eslint-disable-next-line import/no-named-as-default -- False positive
74
+
75
+ function createCache() {
76
+ return {
77
+ dateTime: {},
78
+ number: {},
79
+ message: {},
80
+ relativeTime: {},
81
+ pluralRules: {},
82
+ list: {},
83
+ displayNames: {}
84
+ };
85
+ }
86
+ function createMemoCache(store) {
87
+ return {
88
+ create() {
89
+ return {
90
+ get(key) {
91
+ return store[key];
92
+ },
93
+ set(key, value) {
94
+ store[key] = value;
95
+ }
96
+ };
97
+ }
98
+ };
99
+ }
100
+ function memoFn(fn, cache) {
101
+ return fastMemoize.memoize(fn, {
102
+ cache: createMemoCache(cache),
103
+ strategy: fastMemoize.strategies.variadic
104
+ });
105
+ }
106
+ function memoConstructor(ConstructorFn, cache) {
107
+ return memoFn(function () {
108
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
109
+ args[_key] = arguments[_key];
110
+ }
111
+ return new ConstructorFn(...args);
112
+ }, cache);
113
+ }
114
+ function createIntlFormatters(cache) {
115
+ const getDateTimeFormat = memoConstructor(Intl.DateTimeFormat, cache.dateTime);
116
+ const getNumberFormat = memoConstructor(Intl.NumberFormat, cache.number);
117
+ const getPluralRules = memoConstructor(Intl.PluralRules, cache.pluralRules);
118
+ const getRelativeTimeFormat = memoConstructor(Intl.RelativeTimeFormat, cache.relativeTime);
119
+ const getListFormat = memoConstructor(Intl.ListFormat, cache.list);
120
+ const getDisplayNames = memoConstructor(Intl.DisplayNames, cache.displayNames);
121
+ return {
122
+ getDateTimeFormat,
123
+ getNumberFormat,
124
+ getPluralRules,
125
+ getRelativeTimeFormat,
126
+ getListFormat,
127
+ getDisplayNames
128
+ };
129
+ }
130
+
131
+ function validateMessagesSegment(messages, invalidKeyLabels, parentPath) {
132
+ Object.entries(messages).forEach(_ref => {
133
+ let [key, messageOrMessages] = _ref;
134
+ if (key.includes('.')) {
135
+ let keyLabel = key;
136
+ if (parentPath) keyLabel += " (at ".concat(parentPath, ")");
137
+ invalidKeyLabels.push(keyLabel);
138
+ }
139
+ if (messageOrMessages != null && typeof messageOrMessages === 'object') {
140
+ validateMessagesSegment(messageOrMessages, invalidKeyLabels, joinPath(parentPath, key));
141
+ }
142
+ });
143
+ }
144
+ function validateMessages(messages, onError) {
145
+ const invalidKeyLabels = [];
146
+ validateMessagesSegment(messages, invalidKeyLabels);
147
+ if (invalidKeyLabels.length > 0) {
148
+ 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") ));
149
+ }
150
+ }
151
+
152
+ /**
153
+ * Enhances the incoming props with defaults.
154
+ */
155
+ function initializeConfig(_ref) {
156
+ let {
157
+ getMessageFallback,
158
+ messages,
159
+ onError,
160
+ ...rest
161
+ } = _ref;
162
+ const finalOnError = onError || defaultOnError;
163
+ const finalGetMessageFallback = getMessageFallback || defaultGetMessageFallback;
164
+ {
165
+ if (messages) {
166
+ validateMessages(messages, finalOnError);
167
+ }
168
+ }
169
+ return {
170
+ ...rest,
171
+ messages,
172
+ onError: finalOnError,
173
+ getMessageFallback: finalGetMessageFallback
174
+ };
175
+ }
176
+
177
+ exports.IntlError = IntlError;
178
+ exports.IntlErrorCode = IntlErrorCode;
179
+ exports.createCache = createCache;
180
+ exports.createIntlFormatters = createIntlFormatters;
181
+ exports.defaultGetMessageFallback = defaultGetMessageFallback;
182
+ exports.defaultOnError = defaultOnError;
183
+ exports.initializeConfig = initializeConfig;
184
+ exports.joinPath = joinPath;
185
+ exports.memoFn = memoFn;
@@ -0,0 +1,151 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _IntlProvider = require('./_IntlProvider.js');
6
+ var _useLocale = require('./_useLocale-0Rl9uR82.js');
7
+ var React = require('react');
8
+ var createFormatter = require('./createFormatter-TZTkYRKI.js');
9
+ var initializeConfig = require('./initializeConfig-o7L_y07P.js');
10
+ require('./IntlContext-BKfsnzBx.js');
11
+ require('intl-messageformat');
12
+ require('@formatjs/fast-memoize');
13
+
14
+ let hasWarnedForMissingTimezone = false;
15
+ const isServer = typeof window === 'undefined';
16
+ function useTranslationsImpl(allMessagesPrefixed, namespacePrefixed, namespacePrefix) {
17
+ const {
18
+ cache,
19
+ defaultTranslationValues,
20
+ formats: globalFormats,
21
+ formatters,
22
+ getMessageFallback,
23
+ locale,
24
+ onError,
25
+ timeZone
26
+ } = _useLocale.useIntlContext();
27
+
28
+ // The `namespacePrefix` is part of the type system.
29
+ // See the comment in the hook invocation.
30
+ const allMessages = allMessagesPrefixed[namespacePrefix];
31
+ const namespace = createFormatter.resolveNamespace(namespacePrefixed, namespacePrefix);
32
+ if (!timeZone && !hasWarnedForMissingTimezone && isServer) {
33
+ // eslint-disable-next-line react-compiler/react-compiler
34
+ hasWarnedForMissingTimezone = true;
35
+ 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" ));
36
+ }
37
+ const translate = React.useMemo(() => createFormatter.createBaseTranslator({
38
+ cache,
39
+ formatters,
40
+ getMessageFallback,
41
+ messages: allMessages,
42
+ defaultTranslationValues,
43
+ namespace,
44
+ onError,
45
+ formats: globalFormats,
46
+ locale,
47
+ timeZone
48
+ }), [cache, formatters, getMessageFallback, allMessages, defaultTranslationValues, namespace, onError, globalFormats, locale, timeZone]);
49
+ return translate;
50
+ }
51
+
52
+ /**
53
+ * Translates messages from the given namespace by using the ICU syntax.
54
+ * See https://formatjs.io/docs/core-concepts/icu-syntax.
55
+ *
56
+ * If no namespace is provided, all available messages are returned.
57
+ * The namespace can also indicate nesting by using a dot
58
+ * (e.g. `namespace.Component`).
59
+ */
60
+ function useTranslations(namespace) {
61
+ const context = _useLocale.useIntlContext();
62
+ const messages = context.messages;
63
+
64
+ // We have to wrap the actual hook so the type inference for the optional
65
+ // namespace works correctly. See https://stackoverflow.com/a/71529575/343045
66
+ // The prefix ("!") is arbitrary.
67
+ return useTranslationsImpl({
68
+ '!': messages
69
+ },
70
+ // @ts-expect-error
71
+ namespace ? "!.".concat(namespace) : '!', '!');
72
+ }
73
+
74
+ function getNow() {
75
+ return new Date();
76
+ }
77
+
78
+ /**
79
+ * Reading the current date via `new Date()` in components should be avoided, as
80
+ * it causes components to be impure and can lead to flaky tests. Instead, this
81
+ * hook can be used.
82
+ *
83
+ * By default, it returns the time when the component mounts. If `updateInterval`
84
+ * is specified, the value will be updated based on the interval.
85
+ *
86
+ * You can however also return a static value from this hook, if you
87
+ * configure the `now` parameter on the context provider. Note however,
88
+ * that if `updateInterval` is configured in this case, the component
89
+ * will initialize with the global value, but will afterwards update
90
+ * continuously based on the interval.
91
+ *
92
+ * For unit tests, this can be mocked to a constant value. For end-to-end
93
+ * testing, an environment parameter can be passed to the `now` parameter
94
+ * of the provider to mock this to a static value.
95
+ */
96
+ function useNow(options) {
97
+ const updateInterval = options === null || options === void 0 ? void 0 : options.updateInterval;
98
+ const {
99
+ now: globalNow
100
+ } = _useLocale.useIntlContext();
101
+ const [now, setNow] = React.useState(globalNow || getNow());
102
+ React.useEffect(() => {
103
+ if (!updateInterval) return;
104
+ const intervalId = setInterval(() => {
105
+ setNow(getNow());
106
+ }, updateInterval);
107
+ return () => {
108
+ clearInterval(intervalId);
109
+ };
110
+ }, [globalNow, updateInterval]);
111
+ return updateInterval == null && globalNow ? globalNow : now;
112
+ }
113
+
114
+ function useTimeZone() {
115
+ return _useLocale.useIntlContext().timeZone;
116
+ }
117
+
118
+ function useMessages() {
119
+ const context = _useLocale.useIntlContext();
120
+ if (!context.messages) {
121
+ throw new Error('No messages found. Have you configured them correctly? See https://next-intl-docs.vercel.app/docs/configuration#messages' );
122
+ }
123
+ return context.messages;
124
+ }
125
+
126
+ function useFormatter() {
127
+ const {
128
+ formats,
129
+ formatters,
130
+ locale,
131
+ now: globalNow,
132
+ onError,
133
+ timeZone
134
+ } = _useLocale.useIntlContext();
135
+ return React.useMemo(() => createFormatter.createFormatter({
136
+ formats,
137
+ locale,
138
+ now: globalNow,
139
+ onError,
140
+ timeZone,
141
+ _formatters: formatters
142
+ }), [formats, formatters, globalNow, locale, onError, timeZone]);
143
+ }
144
+
145
+ exports.IntlProvider = _IntlProvider.IntlProvider;
146
+ exports.useLocale = _useLocale.useLocale;
147
+ exports.useFormatter = useFormatter;
148
+ exports.useMessages = useMessages;
149
+ exports.useNow = useNow;
150
+ exports.useTimeZone = useTimeZone;
151
+ exports.useTranslations = useTranslations;
@@ -0,0 +1 @@
1
+ import{createContext as o}from"react";const r=o(void 0);export{r as I};
@@ -0,0 +1 @@
1
+ import e,{useMemo as a}from"react";import{b as o,c as t,i as r}from"./initializeConfig-D2A8plWf.js";import{I as s}from"./IntlContext-DoS4CDM3.js";import"@formatjs/fast-memoize";function l(l){let{children:n,defaultTranslationValues:i,formats:m,getMessageFallback:c,locale:f,messages:g,now:u,onError:p,timeZone:d}=l;const b=a((()=>o()),[f]),j=a((()=>t(b)),[b]),E=a((()=>({...r({locale:f,defaultTranslationValues:i,formats:m,getMessageFallback:c,messages:g,now:u,onError:p,timeZone:d}),formatters:j,cache:b})),[b,i,m,j,c,f,g,u,p,d]);return e.createElement(s.Provider,{value:E},n)}export{l as IntlProvider};
@@ -0,0 +1 @@
1
+ import{useContext as o}from"react";import{I as t}from"./IntlContext-DoS4CDM3.js";function e(){const e=o(t);if(!e)throw new Error("No intl context found. Have you configured the provider? See https://next-intl-docs.vercel.app/docs/usage/configuration#client-server-components");return e}function n(){return e().locale}export{e as a,n as u};
@@ -0,0 +1 @@
1
+ export{u as useLocale}from"./_useLocale-v-ZT5JoE.js";import"react";import"./IntlContext-DoS4CDM3.js";
@@ -0,0 +1 @@
1
+ import{b as e,c as r,e as t,d as s}from"./initializeConfig-D2A8plWf.js";export{I as IntlError,a as IntlErrorCode,i as initializeConfig}from"./initializeConfig-D2A8plWf.js";import{r as o,a as m}from"./createFormatter-D1WNHqdE.js";export{c as createFormatter}from"./createFormatter-D1WNHqdE.js";import"@formatjs/fast-memoize";import"intl-messageformat";import"react";function n(a){let{_cache:i=e(),_formatters:c=r(i),getMessageFallback:n=t,messages:f,namespace:l,onError:g=s,...p}=a;return function(e,a){let{messages:r,namespace:t,...s}=e;return r=r[a],t=o(t,a),m({...s,messages:r,namespace:t})}({...p,onError:g,cache:i,formatters:c,getMessageFallback:n,messages:{"!":f},namespace:l?"!.".concat(l):"!"},"!")}export{e as _createCache,r as _createIntlFormatters,n as createTranslator};
@@ -0,0 +1 @@
1
+ import e from"intl-messageformat";import{isValidElement as t,cloneElement as n}from"react";import{I as r,a as o,j as a,d as s,e as i,m as c,b as u,c as m}from"./initializeConfig-D2A8plWf.js";function l(e,t){return e?Object.keys(e).reduce(((n,r)=>(n[r]={timeZone:t,...e[r]},n)),{}):e}function f(e,t,n,r){const o=a(r,n);if(!t)throw new Error("No messages available at `".concat(r,"`."));let s=t;return n.split(".").forEach((t=>{const n=s[t];if(null==t||null==n)throw new Error("Could not resolve `".concat(o,"` in messages for locale `").concat(e,"`."));s=n})),s}function g(u){const m=function(e,t,n){let a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:s;try{if(!t)throw new Error("No messages were configured on the provider.");const r=n?f(e,t,n):t;if(!r)throw new Error("No messages for namespace `".concat(n,"` found."));return r}catch(e){const t=new r(o.MISSING_MESSAGE,e.message);return a(t),t}}(u.locale,u.messages,u.namespace,u.onError);return function(s){let{cache:u,defaultTranslationValues:m,formats:g,formatters:d,getMessageFallback:p=i,locale:h,messagesOrError:y,namespace:v,onError:w,timeZone:E}=s;const T=y instanceof r;function S(e,t,n){const o=new r(t,n);return w(o),p({error:o,key:e,namespace:v})}function b(r,s,i){if(T)return p({error:y,key:r,namespace:v});const w=y;let b,M;try{b=f(h,w,r,v)}catch(e){return S(r,o.MISSING_MESSAGE,e.message)}if("object"==typeof b){let e,t;return Array.isArray(b)?(e=o.INVALID_MESSAGE,t="Message at `".concat(a(v,r),"` resolved to an array, but only strings are supported. See https://next-intl-docs.vercel.app/docs/usage/messages#arrays-of-messages")):(e=o.INSUFFICIENT_PATH,t="Message at `".concat(a(v,r),"` 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")),S(r,e,t)}const I=function(e,t){if(t)return;const n=e.replace(/'([{}])/gi,"$1");return/<|{/.test(n)?void 0:n}(b,s);if(I)return I;d.getMessageFormat||(d.getMessageFormat=function(t,n){const r=c((function(){return new e(arguments.length<=0?void 0:arguments[0],arguments.length<=1?void 0:arguments[1],arguments.length<=2?void 0:arguments[2],{formatters:n,...arguments.length<=3?void 0:arguments[3]})}),t.message);return r}(u,d));try{M=d.getMessageFormat(b,h,function(t,n){const r=n?{...t,dateTime:l(t.dateTime,n)}:t,o=e.formats.date,a=n?l(o,n):o,s=e.formats.time,i=n?l(s,n):s;return{...r,date:{...a,...null==r?void 0:r.dateTime},time:{...i,...null==r?void 0:r.dateTime}}}({...g,...i},E),{formatters:{...d,getDateTimeFormat:(e,t)=>d.getDateTimeFormat(e,{timeZone:E,...t})}})}catch(e){const t=e;return S(r,o.INVALID_MESSAGE,t.message+("originalMessage"in t?" (".concat(t.originalMessage,")"):""))}try{const e=M.format(function(e){if(0===Object.keys(e).length)return;const r={};return Object.keys(e).forEach((o=>{let a=0;const s=e[o];let i;i="function"==typeof s?e=>{const r=s(e);return t(r)?n(r,{key:o+a++}):r}:s,r[o]=i})),r}({...m,...s}));if(null==e)throw new Error("Unable to format `".concat(r,"` in ").concat(v?"namespace `".concat(v,"`"):"messages"));return t(e)||Array.isArray(e)||"string"==typeof e?e:String(e)}catch(e){return S(r,o.FORMATTING_ERROR,e.message)}}function M(e,t,n){const r=b(e,t,n);return"string"!=typeof r?S(e,o.INVALID_MESSAGE,"The message `".concat(e,"` in ").concat(v?"namespace `".concat(v,"`"):"messages"," didn't resolve to a string. If you want to format rich text, use `t.rich` instead.")):r}return M.rich=b,M.markup=(e,t,n)=>{const a=b(e,t,n);if("string"!=typeof a){const t=new r(o.FORMATTING_ERROR,"`t.markup` only accepts functions for formatting that receive and return strings.\n\nE.g. t.markup('markup', {b: (chunks) => `<b>${chunks}</b>`})");return w(t),p({error:t,key:e,namespace:v})}return a},M.raw=e=>{if(T)return p({error:y,key:e,namespace:v});const t=y;try{return f(h,t,e,v)}catch(t){return S(e,o.MISSING_MESSAGE,t.message)}},M.has=e=>{if(T)return!1;try{return f(h,y,e,v),!0}catch(e){return!1}},M}({...u,messagesOrError:m})}function d(e,t){return e===t?void 0:e.slice((t+".").length)}const p=60,h=60*p,y=24*h,v=7*y,w=y*(365/12),E=3*w,T=365*y,S={second:1,seconds:1,minute:p,minutes:p,hour:h,hours:h,day:y,days:y,week:v,weeks:v,month:w,months:w,quarter:E,quarters:E,year:T,years:T};function b(e){let{_cache:t=u(),_formatters:n=m(t),formats:a,locale:i,now:c,onError:l=s,timeZone:f}=e;function g(e){var t;return null!==(t=e)&&void 0!==t&&t.timeZone||(f?e={...e,timeZone:f}:l(new r(o.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"))),e}function d(e,t,n,a){let s;try{s=function(e,t){let n;if("string"==typeof t){const a=t;if(n=null==e?void 0:e[a],!n){const e=new r(o.MISSING_FORMAT,"Format `".concat(a,"` is not available. You can configure it on the provider or provide custom options."));throw l(e),e}}else n=t;return n}(t,e)}catch(e){return a()}try{return n(s)}catch(e){return l(new r(o.FORMATTING_ERROR,e.message)),a()}}function E(e,t){return d(t,null==a?void 0:a.dateTime,(t=>(t=g(t),n.getDateTimeFormat(i,t).format(e))),(()=>String(e)))}function b(){return c||(l(new r(o.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:E,number:function(e,t){return d(t,null==a?void 0:a.number,(t=>n.getNumberFormat(i,t).format(e)),(()=>String(e)))},relativeTime:function(e,t){try{let r,o;const a={};t instanceof Date||"number"==typeof t?r=new Date(t):t&&(r=null!=t.now?new Date(t.now):b(),o=t.unit,a.style=t.style,a.numberingSystem=t.numberingSystem),r||(r=b());const s=(new Date(e).getTime()-r.getTime())/1e3;o||(o=function(e){const t=Math.abs(e);return t<p?"second":t<h?"minute":t<y?"hour":t<v?"day":t<w?"week":t<T?"month":"year"}(s)),a.numeric="second"===o?"auto":"always";const c=function(e,t){return Math.round(e/S[t])}(s,o);return n.getRelativeTimeFormat(i,a).format(c,o)}catch(t){return l(new r(o.FORMATTING_ERROR,t.message)),String(e)}},list:function(e,t){const r=[],o=new Map;let s=0;for(const t of e){let e;"object"==typeof t?(e=String(s),o.set(e,t)):e=String(t),r.push(e),s++}return d(t,null==a?void 0:a.list,(e=>{const t=n.getListFormat(i,e).formatToParts(r).map((e=>"literal"===e.type?e.value:o.get(e.value)||e.value));return o.size>0?t:t.join("")}),(()=>String(e)))},dateTimeRange:function(e,t,r){return d(r,null==a?void 0:a.dateTime,(r=>(r=g(r),n.getDateTimeFormat(i,r).formatRange(e,t))),(()=>[E(e),E(t)].join(" – ")))}}}export{g as a,b as c,d as r};
@@ -0,0 +1 @@
1
+ export{I as IntlError,a as IntlErrorCode,b as _createCache,c as _createIntlFormatters,i as initializeConfig}from"./initializeConfig-D2A8plWf.js";export{createTranslator}from"./core.js";export{c as createFormatter}from"./createFormatter-D1WNHqdE.js";export{IntlProvider}from"./_IntlProvider.js";export{useFormatter,useMessages,useNow,useTimeZone,useTranslations}from"./react.js";export{u as useLocale}from"./_useLocale-v-ZT5JoE.js";import"@formatjs/fast-memoize";import"intl-messageformat";import"react";import"./IntlContext-DoS4CDM3.js";
@@ -0,0 +1 @@
1
+ import{memoize as e,strategies as t}from"@formatjs/fast-memoize";function n(e,t,n){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}let r=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 a extends Error{constructor(e,t){let r=e;t&&(r+=": "+t),super(r),n(this,"code",void 0),n(this,"originalMessage",void 0),this.code=e,t&&(this.originalMessage=t)}}function o(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return t.filter(Boolean).join(".")}function i(e){return o(e.namespace,e.key)}function s(e){console.error(e)}function l(){return{dateTime:{},number:{},message:{},relativeTime:{},pluralRules:{},list:{},displayNames:{}}}function u(n,r){return e(n,{cache:(a=r,{create:()=>({get:e=>a[e],set(e,t){a[e]=t}})}),strategy:t.variadic});var a}function c(e,t){return u((function(){for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];return new e(...n)}),t)}function m(e){return{getDateTimeFormat:c(Intl.DateTimeFormat,e.dateTime),getNumberFormat:c(Intl.NumberFormat,e.number),getPluralRules:c(Intl.PluralRules,e.pluralRules),getRelativeTimeFormat:c(Intl.RelativeTimeFormat,e.relativeTime),getListFormat:c(Intl.ListFormat,e.list),getDisplayNames:c(Intl.DisplayNames,e.displayNames)}}function f(e,t,n){Object.entries(e).forEach((e=>{let[r,a]=e;if(r.includes(".")){let e=r;n&&(e+=" (at ".concat(n,")")),t.push(e)}null!=a&&"object"==typeof a&&f(a,t,o(n,r))}))}function I(e,t){const n=[];f(e,n),n.length>0&&t(new a(r.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===n.length?"key":"keys",": ").concat(n.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')))}function g(e){let{getMessageFallback:t,messages:n,onError:r,...a}=e;const o=r||s,l=t||i;return n&&I(n,o),{...a,messages:n,onError:o,getMessageFallback:l}}export{a as I,r as a,l as b,m as c,s as d,i as e,g as i,o as j,u as m};
@@ -0,0 +1 @@
1
+ export{IntlProvider}from"./_IntlProvider.js";import{a as e}from"./_useLocale-v-ZT5JoE.js";export{u as useLocale}from"./_useLocale-v-ZT5JoE.js";import{useMemo as t,useState as o,useEffect as r}from"react";import{r as n,a,c as s}from"./createFormatter-D1WNHqdE.js";import{I as i,a as c}from"./initializeConfig-D2A8plWf.js";import"./IntlContext-DoS4CDM3.js";import"intl-messageformat";import"@formatjs/fast-memoize";let m=!1;const l="undefined"==typeof window;function f(o){return function(o,r,s){const{cache:f,defaultTranslationValues:u,formats:d,formatters:p,getMessageFallback:g,locale:v,onError:h,timeZone:w}=e(),I=o[s],j=n(r,s);return w||m||!l||(m=!0,h(new i(c.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"))),t((()=>a({cache:f,formatters:p,getMessageFallback:g,messages:I,defaultTranslationValues:u,namespace:j,onError:h,formats:d,locale:v,timeZone:w})),[f,p,g,I,u,j,h,d,v,w])}({"!":e().messages},o?"!.".concat(o):"!","!")}function d(){return new Date}function p(t){const n=null==t?void 0:t.updateInterval,{now:a}=e(),[s,i]=o(a||d());return r((()=>{if(!n)return;const e=setInterval((()=>{i(d())}),n);return()=>{clearInterval(e)}}),[a,n]),null==n&&a?a:s}function g(){return e().timeZone}function v(){const t=e();if(!t.messages)throw new Error("No messages found. Have you configured them correctly? See https://next-intl-docs.vercel.app/docs/configuration#messages");return t.messages}function h(){const{formats:o,formatters:r,locale:n,now:a,onError:i,timeZone:c}=e();return t((()=>s({formats:o,locale:n,now:a,onError:i,timeZone:c,_formatters:r})),[o,r,a,n,i,c])}export{h as useFormatter,v as useMessages,p as useNow,g as useTimeZone,f as useTranslations};
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ if (process.env.NODE_ENV === 'production') {
4
+ module.exports = require('./production/index.js');
5
+ } else {
6
+ module.exports = require('./development/index.js');
7
+ }
@@ -0,0 +1 @@
1
+ "use strict";const 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-AbYTngyP.js"),r=require("./IntlContext-DcFt0tgW.js");function a(e){return e&&e.__esModule?e:{default:e}}require("@formatjs/fast-memoize");var o=a(e);exports.IntlProvider=function(a){let{children:s,defaultTranslationValues:n,formats:l,getMessageFallback:i,locale:u,messages:c,now:m,onError:f,timeZone:d}=a;const g=e.useMemo((()=>t.createCache()),[u]),M=e.useMemo((()=>t.createIntlFormatters(g)),[g]),v=e.useMemo((()=>({...t.initializeConfig({locale:u,defaultTranslationValues:n,formats:l,getMessageFallback:i,messages:c,now:m,onError:f,timeZone:d}),formatters:M,cache:g})),[g,n,l,M,i,u,c,m,f,d]);return o.default.createElement(r.IntlContext.Provider,{value:v},s)};
@@ -0,0 +1 @@
1
+ "use strict";var t=require("react"),e=require("./IntlContext-DcFt0tgW.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-CpTrqBDt.js");require("react"),require("./IntlContext-DcFt0tgW.js"),exports.useLocale=e.useLocale;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./createFormatter-CTr0qKAI.js"),r=require("./initializeConfig-AbYTngyP.js");require("intl-messageformat"),require("react"),require("@formatjs/fast-memoize"),exports.IntlError=e.IntlError,exports.IntlErrorCode=e.IntlErrorCode,exports.createFormatter=e.createFormatter,exports._createCache=r.createCache,exports._createIntlFormatters=r.createIntlFormatters,exports.initializeConfig=r.initializeConfig,exports.createTranslator=function(t){let{_cache:a=r.createCache(),_formatters:s=r.createIntlFormatters(a),getMessageFallback:o=r.defaultGetMessageFallback,messages:c,namespace:n,onError:i=r.defaultOnError,...l}=t;return function(r,t){let{messages:a,namespace:s,...o}=r;return a=a[t],s=e.resolveNamespace(s,t),e.createBaseTranslator({...o,messages:a,namespace:s})}({...l,onError:i,cache:a,formatters:s,getMessageFallback:o,messages:{"!":c},namespace:n?"!.".concat(n):"!"},"!")};
@@ -0,0 +1 @@
1
+ "use strict";var e=require("intl-messageformat"),t=require("react"),r=require("./initializeConfig-AbYTngyP.js");function n(e){return e&&e.__esModule?e:{default:e}}var o=n(e);function a(e,t,r){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!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:t+""}(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}let i=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),a(this,"code",void 0),a(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,n,o){const a=r.joinPath(o,n);if(!t)throw new Error(a);let i=t;return n.split(".").forEach((t=>{const r=i[t];if(null==t||null==r)throw new Error(a+" (".concat(e,")"));i=r})),i}const l=60,m=60*l,f=24*m,g=7*f,d=f*(365/12),E=3*d,I=365*f,S={second:1,seconds:1,minute:l,minutes:l,hour:m,hours:m,day:f,days:f,week:g,weeks:g,month:d,months:d,quarter:E,quarters:E,year:I,years:I};exports.IntlError=s,exports.IntlErrorCode=i,exports.createBaseTranslator=function(e){const n=function(e,t,n){let o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:r.defaultOnError;try{if(!t)throw new Error(void 0);const r=n?c(e,t,n):t;if(!r)throw new Error(n);return r}catch(e){const t=new s(i.MISSING_MESSAGE,e.message);return o(t),t}}(e.locale,e.messages,e.namespace,e.onError);return function(e){let{cache:n,defaultTranslationValues:a,formats:l,formatters:m,getMessageFallback:f=r.defaultGetMessageFallback,locale:g,messagesOrError:d,namespace:E,onError:I,timeZone:S}=e;const y=d instanceof s;function T(e,t,r){const n=new s(t,r);return I(n),f({error:n,key:e,namespace:E})}function h(e,s,I){if(y)return f({error:d,key:e,namespace:E});const h=d;let v,M;try{v=c(g,h,e,E)}catch(t){return T(e,i.MISSING_MESSAGE,t.message)}if("object"==typeof v){let t,r;return t=Array.isArray(v)?i.INVALID_MESSAGE:i.INSUFFICIENT_PATH,T(e,t,r)}const N=function(e,t){if(t)return;const r=e.replace(/'([{}])/gi,"$1");return/<|{/.test(r)?void 0:r}(v,s);if(N)return N;m.getMessageFormat||(m.getMessageFormat=function(e,t){const n=r.memoFn((function(){return new o.default(arguments.length<=0?void 0:arguments[0],arguments.length<=1?void 0:arguments[1],arguments.length<=2?void 0:arguments[2],{formatters:t,...arguments.length<=3?void 0:arguments[3]})}),e.message);return n}(n,m));try{M=m.getMessageFormat(v,g,function(e,t){const r=t?{...e,dateTime:u(e.dateTime,t)}:e,n=o.default.formats.date,a=t?u(n,t):n,i=o.default.formats.time,s=t?u(i,t):i;return{...r,date:{...a,...null==r?void 0:r.dateTime},time:{...s,...null==r?void 0:r.dateTime}}}({...l,...I},S),{formatters:{...m,getDateTimeFormat:(e,t)=>m.getDateTimeFormat(e,{timeZone:S,...t})}})}catch(t){const r=t;return T(e,i.INVALID_MESSAGE,r.message)}try{const e=M.format(function(e){if(0===Object.keys(e).length)return;const r={};return Object.keys(e).forEach((n=>{let o=0;const a=e[n];let i;i="function"==typeof a?e=>{const r=a(e);return t.isValidElement(r)?t.cloneElement(r,{key:n+o++}):r}:a,r[n]=i})),r}({...a,...s}));if(null==e)throw new Error(void 0);return t.isValidElement(e)||Array.isArray(e)||"string"==typeof e?e:String(e)}catch(t){return T(e,i.FORMATTING_ERROR,t.message)}}function v(e,t,r){const n=h(e,t,r);return"string"!=typeof n?T(e,i.INVALID_MESSAGE,void 0):n}return v.rich=h,v.markup=(e,t,r)=>{const n=h(e,t,r);if("string"!=typeof n){const t=new s(i.FORMATTING_ERROR,void 0);return I(t),f({error:t,key:e,namespace:E})}return n},v.raw=e=>{if(y)return f({error:d,key:e,namespace:E});const t=d;try{return c(g,t,e,E)}catch(t){return T(e,i.MISSING_MESSAGE,t.message)}},v.has=e=>{if(y)return!1;try{return c(g,d,e,E),!0}catch(e){return!1}},v}({...e,messagesOrError:n})},exports.createFormatter=function(e){let{_cache:t=r.createCache(),_formatters:n=r.createIntlFormatters(t),formats:o,locale:a,now:u,onError:c=r.defaultOnError,timeZone:E}=e;function y(e){var t;return null!==(t=e)&&void 0!==t&&t.timeZone||(E?e={...e,timeZone:E}:c(new s(i.ENVIRONMENT_FALLBACK,void 0))),e}function T(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(i.MISSING_FORMAT,void 0);throw c(e),e}}else r=t;return r}(t,e)}catch(e){return n()}try{return r(o)}catch(e){return c(new s(i.FORMATTING_ERROR,e.message)),n()}}function h(e,t){return T(t,null==o?void 0:o.dateTime,(t=>(t=y(t),n.getDateTimeFormat(a,t).format(e))),(()=>String(e)))}function v(){return u||(c(new s(i.ENVIRONMENT_FALLBACK,void 0)),new Date)}return{dateTime:h,number:function(e,t){return T(t,null==o?void 0:o.number,(t=>n.getNumberFormat(a,t).format(e)),(()=>String(e)))},relativeTime:function(e,t){try{let r,o;const i={};t instanceof Date||"number"==typeof t?r=new Date(t):t&&(r=null!=t.now?new Date(t.now):v(),o=t.unit,i.style=t.style,i.numberingSystem=t.numberingSystem),r||(r=v());const s=(new Date(e).getTime()-r.getTime())/1e3;o||(o=function(e){const t=Math.abs(e);return t<l?"second":t<m?"minute":t<f?"hour":t<g?"day":t<d?"week":t<I?"month":"year"}(s)),i.numeric="second"===o?"auto":"always";const u=function(e,t){return Math.round(e/S[t])}(s,o);return n.getRelativeTimeFormat(a,i).format(u,o)}catch(t){return c(new s(i.FORMATTING_ERROR,t.message)),String(e)}},list:function(e,t){const r=[],i=new Map;let s=0;for(const t of e){let e;"object"==typeof t?(e=String(s),i.set(e,t)):e=String(t),r.push(e),s++}return T(t,null==o?void 0:o.list,(e=>{const t=n.getListFormat(a,e).formatToParts(r).map((e=>"literal"===e.type?e.value:i.get(e.value)||e.value));return i.size>0?t:t.join("")}),(()=>String(e)))},dateTimeRange:function(e,t,r){return T(r,null==o?void 0:o.dateTime,(r=>(r=y(r),n.getDateTimeFormat(a,r).formatRange(e,t))),(()=>[h(e),h(t)].join(" – ")))}}},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-CTr0qKAI.js"),r=require("./core.js"),t=require("./initializeConfig-AbYTngyP.js"),s=require("./_IntlProvider.js"),o=require("./react.js"),a=require("./_useLocale-CpTrqBDt.js");require("intl-messageformat"),require("react"),require("@formatjs/fast-memoize"),require("./IntlContext-DcFt0tgW.js"),exports.IntlError=e.IntlError,exports.IntlErrorCode=e.IntlErrorCode,exports.createFormatter=e.createFormatter,exports.createTranslator=r.createTranslator,exports._createCache=t.createCache,exports._createIntlFormatters=t.createIntlFormatters,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";var e=require("@formatjs/fast-memoize");function t(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return t.filter(Boolean).join(".")}function r(e){return t(e.namespace,e.key)}function a(e){console.error(e)}function n(t,r){return e.memoize(t,{cache:(a=r,{create:()=>({get:e=>a[e],set(e,t){a[e]=t}})}),strategy:e.strategies.variadic});var a}function s(e,t){return n((function(){for(var t=arguments.length,r=new Array(t),a=0;a<t;a++)r[a]=arguments[a];return new e(...r)}),t)}exports.createCache=function(){return{dateTime:{},number:{},message:{},relativeTime:{},pluralRules:{},list:{},displayNames:{}}},exports.createIntlFormatters=function(e){return{getDateTimeFormat:s(Intl.DateTimeFormat,e.dateTime),getNumberFormat:s(Intl.NumberFormat,e.number),getPluralRules:s(Intl.PluralRules,e.pluralRules),getRelativeTimeFormat:s(Intl.RelativeTimeFormat,e.relativeTime),getListFormat:s(Intl.ListFormat,e.list),getDisplayNames:s(Intl.DisplayNames,e.displayNames)}},exports.defaultGetMessageFallback=r,exports.defaultOnError=a,exports.initializeConfig=function(e){let{getMessageFallback:t,messages:n,onError:s,...i}=e;return{...i,messages:n,onError:s||a,getMessageFallback:t||r}},exports.joinPath=t,exports.memoFn=n;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./_IntlProvider.js"),t=require("./_useLocale-CpTrqBDt.js"),r=require("react"),o=require("./createFormatter-CTr0qKAI.js");require("./initializeConfig-AbYTngyP.js"),require("@formatjs/fast-memoize"),require("./IntlContext-DcFt0tgW.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,formatters:n,locale:s,now:a,onError:u,timeZone:l}=t.useIntlContext();return r.useMemo((()=>o.createFormatter({formats:e,locale:s,now:a,onError:u,timeZone:l,_formatters:n})),[e,n,a,s,u,l])},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]),null==o&&n?n:s},exports.useTimeZone=function(){return t.useIntlContext().timeZone},exports.useTranslations=function(e){return function(e,a,u){const{cache:l,defaultTranslationValues:i,formats:c,formatters:m,getMessageFallback:f,locale:I,onError:d,timeZone:x}=t.useIntlContext(),p=e[u],v=o.resolveNamespace(a,u);return x||n||!s||(n=!0,d(new o.IntlError(o.IntlErrorCode.ENVIRONMENT_FALLBACK,void 0))),r.useMemo((()=>o.createBaseTranslator({cache:l,formatters:m,getMessageFallback:f,messages:p,defaultTranslationValues:i,namespace:v,onError:d,formats:c,locale:I,timeZone:x})),[l,m,f,p,i,v,d,c,I,x])}({"!":t.useIntlContext().messages},e?"!.".concat(e):"!","!")};
package/dist/react.js ADDED
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ if (process.env.NODE_ENV === 'production') {
4
+ module.exports = require('./production/react.js');
5
+ } else {
6
+ module.exports = require('./development/react.js');
7
+ }
@@ -0,0 +1 @@
1
+ export { default as IntlProvider } from './react/IntlProvider';
@@ -0,0 +1 @@
1
+ export { default as useLocale } from './react/useLocale';
@@ -0,0 +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;
@@ -0,0 +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;
@@ -0,0 +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;
@@ -0,0 +1,58 @@
1
+ import type AbstractIntlMessages from './AbstractIntlMessages';
2
+ import type Formats from './Formats';
3
+ import type IntlError from './IntlError';
4
+ import type TimeZone from './TimeZone';
5
+ import type { RichTranslationValues } from './TranslationValues';
6
+ /**
7
+ * Should be used for entry points that configure the library.
8
+ */
9
+ type IntlConfig<Messages = AbstractIntlMessages> = {
10
+ /** A valid Unicode locale tag (e.g. "en" or "en-GB"). */
11
+ locale: string;
12
+ /** Global formats can be provided to achieve consistent
13
+ * formatting across components. */
14
+ formats?: Formats;
15
+ /** A time zone as defined in [the tz database](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) which will be applied when formatting dates and times. If this is absent, the user time zone will be used. You can override this by supplying an explicit time zone to `formatDateTime`. */
16
+ timeZone?: TimeZone;
17
+ /** This callback will be invoked when an error is encountered during
18
+ * resolving a message or formatting it. This defaults to `console.error` to
19
+ * keep your app running. You can customize the handling by taking
20
+ * `error.code` into account. */
21
+ onError?(error: IntlError): void;
22
+ /** Will be called when a message couldn't be resolved or formatting it led to
23
+ * an error. This defaults to `${namespace}.${key}` You can use this to
24
+ * customize what will be rendered in this case. */
25
+ getMessageFallback?(info: {
26
+ error: IntlError;
27
+ key: string;
28
+ namespace?: string;
29
+ }): string;
30
+ /**
31
+ * Providing this value will have two effects:
32
+ * 1. It will be used as the default for the `now` argument of
33
+ * `useFormatter().formatRelativeTime` if no explicit value is provided.
34
+ * 2. It will be returned as a static value from the `useNow` hook. Note
35
+ * however that when `updateInterval` is configured on the `useNow` hook,
36
+ * the global `now` value will only be used for the initial render, but
37
+ * afterwards the current date will be returned continuously.
38
+ */
39
+ now?: Date;
40
+ /** All messages that will be available. */
41
+ messages?: Messages;
42
+ /** Global default values for translation values and rich text elements.
43
+ * Can be used for consistent usage or styling of rich text elements.
44
+ * Defaults will be overidden by locally provided values.
45
+ *
46
+ * @deprecated See https://next-intl-docs.vercel.app/docs/usage/messages#rich-text-reuse-tags
47
+ * */
48
+ defaultTranslationValues?: RichTranslationValues;
49
+ };
50
+ /**
51
+ * A stricter set of the configuration that should be used internally
52
+ * once defaults are assigned to `IntlConfiguration`.
53
+ */
54
+ export type InitializedIntlConfig<Messages = AbstractIntlMessages> = IntlConfig<Messages> & {
55
+ onError: NonNullable<IntlConfig<Messages>['onError']>;
56
+ getMessageFallback: NonNullable<IntlConfig<Messages>['getMessageFallback']>;
57
+ };
58
+ export default IntlConfig;
@@ -0,0 +1,14 @@
1
+ export declare enum IntlErrorCode {
2
+ MISSING_MESSAGE = "MISSING_MESSAGE",
3
+ MISSING_FORMAT = "MISSING_FORMAT",
4
+ ENVIRONMENT_FALLBACK = "ENVIRONMENT_FALLBACK",
5
+ INSUFFICIENT_PATH = "INSUFFICIENT_PATH",
6
+ INVALID_MESSAGE = "INVALID_MESSAGE",
7
+ INVALID_KEY = "INVALID_KEY",
8
+ FORMATTING_ERROR = "FORMATTING_ERROR"
9
+ }
10
+ export default class IntlError extends Error {
11
+ readonly code: IntlErrorCode;
12
+ readonly originalMessage: string | undefined;
13
+ constructor(code: IntlErrorCode, originalMessage?: string);
14
+ }
@@ -0,0 +1,3 @@
1
+ import type { Formats } from 'intl-messageformat';
2
+ type NumberFormatOptions = Formats['number'][string];
3
+ export default NumberFormatOptions;