@common.js/use-intl 4.13.1

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 (68) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +5 -0
  3. package/core.d.ts +2 -0
  4. package/dist/esm/development/core.js +174 -0
  5. package/dist/esm/development/format-message/format-only.js +314 -0
  6. package/dist/esm/development/format-message/index.js +238 -0
  7. package/dist/esm/development/formatters-r4aAmsMP.js +266 -0
  8. package/dist/esm/development/index.js +64 -0
  9. package/dist/esm/development/initializeConfig-CUsOI8u2.js +651 -0
  10. package/dist/esm/development/react.js +390 -0
  11. package/dist/esm/production/core.js +149 -0
  12. package/dist/esm/production/format-message/format-only.js +299 -0
  13. package/dist/esm/production/format-message/index.js +188 -0
  14. package/dist/esm/production/formatters-CJcico0N.js +244 -0
  15. package/dist/esm/production/index.js +64 -0
  16. package/dist/esm/production/initializeConfig-CHgjheii.js +399 -0
  17. package/dist/esm/production/react.js +270 -0
  18. package/dist/types/core/AbstractIntlMessages.d.ts +10 -0
  19. package/dist/types/core/AppConfig.d.ts +29 -0
  20. package/dist/types/core/DateTimeFormatOptions.d.ts +73 -0
  21. package/dist/types/core/Formats.d.ts +9 -0
  22. package/dist/types/core/ICUArgs.d.ts +3 -0
  23. package/dist/types/core/ICUTags.d.ts +2 -0
  24. package/dist/types/core/IntlConfig.d.ts +54 -0
  25. package/dist/types/core/IntlError.d.ts +6 -0
  26. package/dist/types/core/IntlErrorCode.d.ts +10 -0
  27. package/dist/types/core/MessageKeys.d.ts +10 -0
  28. package/dist/types/core/NumberFormatOptions.d.ts +3 -0
  29. package/dist/types/core/RelativeTimeFormatOptions.d.ts +7 -0
  30. package/dist/types/core/TimeZone.d.ts +2 -0
  31. package/dist/types/core/TranslationValues.d.ts +6 -0
  32. package/dist/types/core/convertFormatsToIntlMessageFormat.d.ts +11 -0
  33. package/dist/types/core/createBaseTranslator.d.ts +21 -0
  34. package/dist/types/core/createFormatter.d.ts +47 -0
  35. package/dist/types/core/createTranslator.d.ts +59 -0
  36. package/dist/types/core/createTranslatorImpl.d.ts +17 -0
  37. package/dist/types/core/defaults.d.ts +11 -0
  38. package/dist/types/core/format-message/compile-format.d.ts +12 -0
  39. package/dist/types/core/format-message/format-only.d.ts +13 -0
  40. package/dist/types/core/format-message/index.d.ts +5 -0
  41. package/dist/types/core/format-message/types.d.ts +15 -0
  42. package/dist/types/core/formatters.d.ts +25 -0
  43. package/dist/types/core/hasLocale.d.ts +7 -0
  44. package/dist/types/core/index.d.ts +22 -0
  45. package/dist/types/core/initializeConfig.d.ts +14 -0
  46. package/dist/types/core/joinPath.d.ts +1 -0
  47. package/dist/types/core/resolveNamespace.d.ts +5 -0
  48. package/dist/types/core/types.d.ts +6 -0
  49. package/dist/types/core/validateMessages.d.ts +3 -0
  50. package/dist/types/core.d.ts +1 -0
  51. package/dist/types/index.d.ts +2 -0
  52. package/dist/types/react/IntlContext.d.ts +8 -0
  53. package/dist/types/react/IntlProvider.d.ts +7 -0
  54. package/dist/types/react/index.d.ts +9 -0
  55. package/dist/types/react/useExtracted.d.ts +42 -0
  56. package/dist/types/react/useFormatter.d.ts +2 -0
  57. package/dist/types/react/useIntlContext.d.ts +2 -0
  58. package/dist/types/react/useLocale.d.ts +2 -0
  59. package/dist/types/react/useMessages.d.ts +2 -0
  60. package/dist/types/react/useNow.d.ts +8 -0
  61. package/dist/types/react/useTimeZone.d.ts +1 -0
  62. package/dist/types/react/useTranslations.d.ts +12 -0
  63. package/dist/types/react/useTranslationsImpl.d.ts +9 -0
  64. package/dist/types/react.d.ts +1 -0
  65. package/format-message/format-only.d.ts +2 -0
  66. package/format-message.d.ts +2 -0
  67. package/package.json +45 -0
  68. package/react.d.ts +2 -0
@@ -0,0 +1,270 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ IntlProvider: function() {
13
+ return w;
14
+ },
15
+ "_useExtracted": function() {
16
+ return M;
17
+ },
18
+ useFormatter: function() {
19
+ return I;
20
+ },
21
+ useLocale: function() {
22
+ return Z;
23
+ },
24
+ useMessages: function() {
25
+ return F;
26
+ },
27
+ useNow: function() {
28
+ return b;
29
+ },
30
+ useTimeZone: function() {
31
+ return x;
32
+ },
33
+ useTranslations: function() {
34
+ return v;
35
+ }
36
+ });
37
+ var _react = require("react");
38
+ var _formattersCJcico0NJs = require("./formatters-CJcico0N.js");
39
+ var _initializeConfigCHgjheiiJs = require("./initializeConfig-CHgjheii.js");
40
+ var _jsxRuntime = require("react/jsx-runtime");
41
+ function _arrayLikeToArray(arr, len) {
42
+ if (len == null || len > arr.length) len = arr.length;
43
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
44
+ return arr2;
45
+ }
46
+ function _arrayWithHoles(arr) {
47
+ if (Array.isArray(arr)) return arr;
48
+ }
49
+ function _defineProperty(obj, key, value) {
50
+ if (key in obj) {
51
+ Object.defineProperty(obj, key, {
52
+ value: value,
53
+ enumerable: true,
54
+ configurable: true,
55
+ writable: true
56
+ });
57
+ } else {
58
+ obj[key] = value;
59
+ }
60
+ return obj;
61
+ }
62
+ function _iterableToArrayLimit(arr, i) {
63
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
64
+ if (_i == null) return;
65
+ var _arr = [];
66
+ var _n = true;
67
+ var _d = false;
68
+ var _s, _e;
69
+ try {
70
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
71
+ _arr.push(_s.value);
72
+ if (i && _arr.length === i) break;
73
+ }
74
+ } catch (err) {
75
+ _d = true;
76
+ _e = err;
77
+ } finally{
78
+ try {
79
+ if (!_n && _i["return"] != null) _i["return"]();
80
+ } finally{
81
+ if (_d) throw _e;
82
+ }
83
+ }
84
+ return _arr;
85
+ }
86
+ function _nonIterableRest() {
87
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
88
+ }
89
+ function _objectSpread(target) {
90
+ for(var i = 1; i < arguments.length; i++){
91
+ var source = arguments[i] != null ? arguments[i] : {};
92
+ var ownKeys = Object.keys(source);
93
+ if (typeof Object.getOwnPropertySymbols === "function") {
94
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
95
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
96
+ }));
97
+ }
98
+ ownKeys.forEach(function(key) {
99
+ _defineProperty(target, key, source[key]);
100
+ });
101
+ }
102
+ return target;
103
+ }
104
+ function ownKeys(object, enumerableOnly) {
105
+ var keys = Object.keys(object);
106
+ if (Object.getOwnPropertySymbols) {
107
+ var symbols = Object.getOwnPropertySymbols(object);
108
+ if (enumerableOnly) {
109
+ symbols = symbols.filter(function(sym) {
110
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
111
+ });
112
+ }
113
+ keys.push.apply(keys, symbols);
114
+ }
115
+ return keys;
116
+ }
117
+ function _objectSpreadProps(target, source) {
118
+ source = source != null ? source : {};
119
+ if (Object.getOwnPropertyDescriptors) {
120
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
121
+ } else {
122
+ ownKeys(Object(source)).forEach(function(key) {
123
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
124
+ });
125
+ }
126
+ return target;
127
+ }
128
+ function _slicedToArray(arr, i) {
129
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
130
+ }
131
+ function _unsupportedIterableToArray(o, minLen) {
132
+ if (!o) return;
133
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
134
+ var n = Object.prototype.toString.call(o).slice(8, -1);
135
+ if (n === "Object" && o.constructor) n = o.constructor.name;
136
+ if (n === "Map" || n === "Set") return Array.from(n);
137
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
138
+ }
139
+ var g = (0, _react.createContext)(void 0);
140
+ function w(param) {
141
+ var _$e = param.children, o = param.formats, a = param.getMessageFallback, c = param.locale, i = param.messages, l = param.now, f = param.onError, u = param.timeZone;
142
+ var w = (0, _react.useContext)(g), p = (0, _react.useMemo)(function() {
143
+ return (w === null || w === void 0 ? void 0 : w.cache) || (0, _formattersCJcico0NJs.b)();
144
+ }, [
145
+ c,
146
+ w === null || w === void 0 ? void 0 : w.cache
147
+ ]), E = (0, _react.useMemo)(function() {
148
+ return (w === null || w === void 0 ? void 0 : w.formatters) || (0, _formattersCJcico0NJs.c)(p);
149
+ }, [
150
+ p,
151
+ w === null || w === void 0 ? void 0 : w.formatters
152
+ ]), h = (0, _react.useMemo)(function() {
153
+ return _objectSpreadProps(_objectSpread({}, (0, _initializeConfigCHgjheiiJs.i)({
154
+ locale: c,
155
+ formats: void 0 === o ? w === null || w === void 0 ? void 0 : w.formats : o,
156
+ getMessageFallback: a || (w === null || w === void 0 ? void 0 : w.getMessageFallback),
157
+ messages: void 0 === i ? w === null || w === void 0 ? void 0 : w.messages : i,
158
+ now: l || (w === null || w === void 0 ? void 0 : w.now),
159
+ onError: f || (w === null || w === void 0 ? void 0 : w.onError),
160
+ timeZone: u || (w === null || w === void 0 ? void 0 : w.timeZone)
161
+ })), {
162
+ formatters: E,
163
+ cache: p
164
+ });
165
+ }, [
166
+ p,
167
+ o,
168
+ E,
169
+ a,
170
+ c,
171
+ i,
172
+ l,
173
+ f,
174
+ w,
175
+ u
176
+ ]);
177
+ return (0, _jsxRuntime.jsx)(g.Provider, {
178
+ value: h,
179
+ children: _$e
180
+ });
181
+ }
182
+ function p() {
183
+ var _$e = (0, _react.useContext)(g);
184
+ if (!_$e) throw new Error(void 0);
185
+ return _$e;
186
+ }
187
+ var E = !1;
188
+ var h = "undefined" == typeof window;
189
+ function v(e) {
190
+ return function(e, r, o) {
191
+ var ref = p(), a = ref.cache, n = ref.formats, s = ref.formatters, m = ref.getMessageFallback, u = ref.locale, d = ref.onError, g = ref.timeZone, w = e[o], v = (0, _initializeConfigCHgjheiiJs.r)(r, o);
192
+ return g || E || !h || (E = !0, d(new _formattersCJcico0NJs.I(_formattersCJcico0NJs.a.ENVIRONMENT_FALLBACK, void 0))), (0, _react.useMemo)(function() {
193
+ return (0, _initializeConfigCHgjheiiJs.a)({
194
+ cache: a,
195
+ formatters: s,
196
+ getMessageFallback: m,
197
+ messages: w,
198
+ namespace: v,
199
+ onError: d,
200
+ formats: n,
201
+ locale: u,
202
+ timeZone: g
203
+ });
204
+ }, [
205
+ a,
206
+ s,
207
+ m,
208
+ w,
209
+ v,
210
+ d,
211
+ n,
212
+ u,
213
+ g
214
+ ]);
215
+ }({
216
+ "!": p().messages
217
+ }, e ? "!.".concat(e) : "!", "!");
218
+ }
219
+ function Z() {
220
+ return p().locale;
221
+ }
222
+ function k() {
223
+ return new Date;
224
+ }
225
+ function b(e) {
226
+ var r = e === null || e === void 0 ? void 0 : e.updateInterval, ref = p(), t = ref.now, ref1 = _slicedToArray((0, _react.useState)(t || k()), 2), n = ref1[0], s = ref1[1];
227
+ return (0, _react.useEffect)(function() {
228
+ if (!r) return;
229
+ var _$e = setInterval(function() {
230
+ s(k());
231
+ }, r);
232
+ return function() {
233
+ clearInterval(_$e);
234
+ };
235
+ }, [
236
+ t,
237
+ r
238
+ ]), null == r && t ? t : n;
239
+ }
240
+ function x() {
241
+ return p().timeZone;
242
+ }
243
+ function F() {
244
+ var _$e = p();
245
+ if (!_$e.messages) throw new Error(void 0);
246
+ return _$e.messages;
247
+ }
248
+ function I() {
249
+ var ref = p(), _$e = ref.formats, r = ref.formatters, o = ref.locale, a = ref.now, n = ref.onError, s = ref.timeZone;
250
+ return (0, _react.useMemo)(function() {
251
+ return (0, _initializeConfigCHgjheiiJs.c)({
252
+ formats: _$e,
253
+ locale: o,
254
+ now: a,
255
+ onError: n,
256
+ timeZone: s,
257
+ _formatters: r
258
+ });
259
+ }, [
260
+ _$e,
261
+ r,
262
+ a,
263
+ o,
264
+ n,
265
+ s
266
+ ]);
267
+ }
268
+ function M(e) {
269
+ throw v(e), new Error("[next-intl] `useExtracted` was called in production without compilation. Include modules that call `useExtracted` in `srcPath` and use `transpilePackages` for 3rd-party packages.");
270
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * A generic type that describes the shape of messages.
3
+ *
4
+ * Optionally, messages can be strictly-typed in order to get type safety for message
5
+ * namespaces and keys. See https://next-intl.dev/docs/usage/typescript
6
+ */
7
+ type AbstractIntlMessages = {
8
+ [id: string]: AbstractIntlMessages | string;
9
+ };
10
+ export default AbstractIntlMessages;
@@ -0,0 +1,29 @@
1
+ export default interface AppConfig {
2
+ }
3
+ export type Locale = AppConfig extends {
4
+ Locale: infer AppLocale;
5
+ } ? AppLocale : string;
6
+ export type FormatNames = AppConfig extends {
7
+ Formats: infer AppFormats;
8
+ } ? {
9
+ dateTime: AppFormats extends {
10
+ dateTime: infer AppDateTimeFormats;
11
+ } ? keyof AppDateTimeFormats : string;
12
+ displayName: AppFormats extends {
13
+ displayName: infer AppDisplayNameFormats;
14
+ } ? keyof AppDisplayNameFormats : string;
15
+ list: AppFormats extends {
16
+ list: infer AppListFormats;
17
+ } ? keyof AppListFormats : string;
18
+ number: AppFormats extends {
19
+ number: infer AppNumberFormats;
20
+ } ? keyof AppNumberFormats : string;
21
+ } : {
22
+ dateTime: string;
23
+ displayName: string;
24
+ list: string;
25
+ number: string;
26
+ };
27
+ export type Messages = AppConfig extends {
28
+ Messages: infer AppMessages;
29
+ } ? AppMessages : Record<string, any>;
@@ -0,0 +1,73 @@
1
+ import type TimeZone from './TimeZone.js';
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,9 @@
1
+ import type DateTimeFormatOptions from './DateTimeFormatOptions.js';
2
+ import type NumberFormatOptions from './NumberFormatOptions.js';
3
+ type Formats = {
4
+ dateTime?: Record<string, DateTimeFormatOptions>;
5
+ displayName?: Record<string, Intl.DisplayNamesOptions>;
6
+ list?: Record<string, Intl.ListFormatOptions>;
7
+ number?: Record<string, NumberFormatOptions>;
8
+ };
9
+ export default Formats;
@@ -0,0 +1,3 @@
1
+ import type { GetICUArgs, GetICUArgsOptions } from '@schummar/icu-type-parser';
2
+ type ICUArgs<Message extends string, Options extends GetICUArgsOptions> = string extends Message ? {} : GetICUArgs<Message, Options>;
3
+ export default ICUArgs;
@@ -0,0 +1,2 @@
1
+ type ICUTags<MessageString extends string, TagsFn> = MessageString extends `${infer Prefix}<${infer TagName}>${infer Content}</${string}>${infer Tail}` ? Record<TagName, TagsFn> & ICUTags<`${Prefix}${Content}${Tail}`, TagsFn> : {};
2
+ export default ICUTags;
@@ -0,0 +1,54 @@
1
+ import type { Locale, Messages } from './AppConfig.js';
2
+ import type Formats from './Formats.js';
3
+ import type IntlError from './IntlError.js';
4
+ import type TimeZone from './TimeZone.js';
5
+ import type { DeepPartial } from './types.js';
6
+ /**
7
+ * Should be used for entry points that configure the library.
8
+ */
9
+ type IntlConfig = {
10
+ /** A valid Unicode locale tag (e.g. "en" or "en-GB"). */
11
+ locale: Locale;
12
+ /** Global formats can be provided to achieve consistent
13
+ * formatting across components. */
14
+ formats?: Formats | null;
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?: DeepPartial<Messages> | null;
42
+ };
43
+ /**
44
+ /**
45
+ * A stricter set of the configuration that should be used internally
46
+ * once defaults are assigned to `IntlConfiguration`.
47
+ */
48
+ export type InitializedIntlConfig = Omit<IntlConfig, 'formats' | 'messages' | 'onError' | 'getMessageFallback'> & {
49
+ formats?: NonNullable<IntlConfig['formats']>;
50
+ messages?: NonNullable<IntlConfig['messages']>;
51
+ onError: NonNullable<IntlConfig['onError']>;
52
+ getMessageFallback: NonNullable<IntlConfig['getMessageFallback']>;
53
+ };
54
+ export default IntlConfig;
@@ -0,0 +1,6 @@
1
+ import type IntlErrorCode from './IntlErrorCode.js';
2
+ export default class IntlError extends Error {
3
+ readonly code: IntlErrorCode;
4
+ readonly originalMessage: string | undefined;
5
+ constructor(code: IntlErrorCode, originalMessage?: string);
6
+ }
@@ -0,0 +1,10 @@
1
+ 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 IntlErrorCode;
@@ -0,0 +1,10 @@
1
+ export type NestedKeyOf<ObjectType> = ObjectType extends object ? {
2
+ [Property in keyof ObjectType]: `${Property & string}` | `${Property & string}.${NestedKeyOf<ObjectType[Property]>}`;
3
+ }[keyof ObjectType] : never;
4
+ export type NestedValueOf<ObjectType, Path extends string> = Path extends `${infer Cur}.${infer Rest}` ? Cur extends keyof ObjectType ? NestedValueOf<ObjectType[Cur], Rest> : never : Path extends keyof ObjectType ? ObjectType[Path] : never;
5
+ export type NamespaceKeys<ObjectType, AllKeys extends string> = {
6
+ [PropertyPath in AllKeys]: NestedValueOf<ObjectType, PropertyPath> extends string ? never : PropertyPath;
7
+ }[AllKeys];
8
+ export type MessageKeys<ObjectType, AllKeys extends string> = {
9
+ [PropertyPath in AllKeys]: NestedValueOf<ObjectType, PropertyPath> extends string ? PropertyPath : never;
10
+ }[AllKeys];
@@ -0,0 +1,3 @@
1
+ import type { Formats } from 'intl-messageformat';
2
+ type NumberFormatOptions = Formats['number'][string];
3
+ export default NumberFormatOptions;
@@ -0,0 +1,7 @@
1
+ type RelativeTimeFormatOptions = {
2
+ now?: number | Date;
3
+ unit?: Intl.RelativeTimeFormatUnit;
4
+ numberingSystem?: string;
5
+ style?: Intl.RelativeTimeFormatStyle;
6
+ };
7
+ export default RelativeTimeFormatOptions;
@@ -0,0 +1,2 @@
1
+ type TimeZone = 'Africa/Abidjan' | 'Africa/Accra' | 'Africa/Addis_Ababa' | 'Africa/Algiers' | 'Africa/Asmara' | 'Africa/Bamako' | 'Africa/Bangui' | 'Africa/Banjul' | 'Africa/Bissau' | 'Africa/Blantyre' | 'Africa/Brazzaville' | 'Africa/Bujumbura' | 'Africa/Cairo' | 'Africa/Casablanca' | 'Africa/Ceuta' | 'Africa/Conakry' | 'Africa/Dakar' | 'Africa/Dar_es_Salaam' | 'Africa/Djibouti' | 'Africa/Douala' | 'Africa/El_Aaiun' | 'Africa/Freetown' | 'Africa/Gaborone' | 'Africa/Harare' | 'Africa/Johannesburg' | 'Africa/Juba' | 'Africa/Kampala' | 'Africa/Khartoum' | 'Africa/Kigali' | 'Africa/Kinshasa' | 'Africa/Lagos' | 'Africa/Libreville' | 'Africa/Lome' | 'Africa/Luanda' | 'Africa/Lubumbashi' | 'Africa/Lusaka' | 'Africa/Malabo' | 'Africa/Maputo' | 'Africa/Maseru' | 'Africa/Mbabane' | 'Africa/Mogadishu' | 'Africa/Monrovia' | 'Africa/Nairobi' | 'Africa/Ndjamena' | 'Africa/Niamey' | 'Africa/Nouakchott' | 'Africa/Ouagadougou' | 'Africa/Porto-Novo' | 'Africa/Sao_Tome' | 'Africa/Tripoli' | 'Africa/Tunis' | 'Africa/Windhoek' | 'America/Adak' | 'America/Anchorage' | 'America/Anguilla' | 'America/Antigua' | 'America/Araguaina' | 'America/Argentina/Buenos_Aires' | 'America/Argentina/Catamarca' | 'America/Argentina/Cordoba' | 'America/Argentina/Jujuy' | 'America/Argentina/La_Rioja' | 'America/Argentina/Mendoza' | 'America/Argentina/Rio_Gallegos' | 'America/Argentina/Salta' | 'America/Argentina/San_Juan' | 'America/Argentina/San_Luis' | 'America/Argentina/Tucuman' | 'America/Argentina/Ushuaia' | 'America/Aruba' | 'America/Asuncion' | 'America/Atikokan' | 'America/Bahia' | 'America/Bahia_Banderas' | 'America/Barbados' | 'America/Belem' | 'America/Belize' | 'America/Blanc-Sablon' | 'America/Boa_Vista' | 'America/Bogota' | 'America/Boise' | 'America/Cambridge_Bay' | 'America/Campo_Grande' | 'America/Cancun' | 'America/Caracas' | 'America/Cayenne' | 'America/Cayman' | 'America/Chicago' | 'America/Chihuahua' | 'America/Costa_Rica' | 'America/Creston' | 'America/Cuiaba' | 'America/Curacao' | 'America/Danmarkshavn' | 'America/Dawson' | 'America/Dawson_Creek' | 'America/Denver' | 'America/Detroit' | 'America/Dominica' | 'America/Edmonton' | 'America/Eirunepe' | 'America/El_Salvador' | 'America/Fort_Nelson' | 'America/Fortaleza' | 'America/Glace_Bay' | 'America/Godthab' | 'America/Goose_Bay' | 'America/Grand_Turk' | 'America/Grenada' | 'America/Guadeloupe' | 'America/Guatemala' | 'America/Guayaquil' | 'America/Guyana' | 'America/Halifax' | 'America/Havana' | 'America/Hermosillo' | 'America/Indiana/Indianapolis' | 'America/Indiana/Knox' | 'America/Indiana/Marengo' | 'America/Indiana/Petersburg' | 'America/Indiana/Tell_City' | 'America/Indiana/Vevay' | 'America/Indiana/Vincennes' | 'America/Indiana/Winamac' | 'America/Inuvik' | 'America/Iqaluit' | 'America/Jamaica' | 'America/Juneau' | 'America/Kentucky/Louisville' | 'America/Kentucky/Monticello' | 'America/Kralendijk' | 'America/La_Paz' | 'America/Lima' | 'America/Los_Angeles' | 'America/Lower_Princes' | 'America/Maceio' | 'America/Managua' | 'America/Manaus' | 'America/Marigot' | 'America/Martinique' | 'America/Matamoros' | 'America/Mazatlan' | 'America/Menominee' | 'America/Merida' | 'America/Metlakatla' | 'America/Mexico_City' | 'America/Miquelon' | 'America/Moncton' | 'America/Monterrey' | 'America/Montevideo' | 'America/Montserrat' | 'America/Nassau' | 'America/New_York' | 'America/Nipigon' | 'America/Nome' | 'America/Noronha' | 'America/North_Dakota/Beulah' | 'America/North_Dakota/Center' | 'America/North_Dakota/New_Salem' | 'America/Ojinaga' | 'America/Panama' | 'America/Pangnirtung' | 'America/Paramaribo' | 'America/Phoenix' | 'America/Port-au-Prince' | 'America/Port_of_Spain' | 'America/Porto_Velho' | 'America/Puerto_Rico' | 'America/Punta_Arenas' | 'America/Rainy_River' | 'America/Rankin_Inlet' | 'America/Recife' | 'America/Regina' | 'America/Resolute' | 'America/Rio_Branco' | 'America/Santarem' | 'America/Santiago' | 'America/Santo_Domingo' | 'America/Sao_Paulo' | 'America/Scoresbysund' | 'America/Sitka' | 'America/St_Barthelemy' | 'America/St_Johns' | 'America/St_Kitts' | 'America/St_Lucia' | 'America/St_Thomas' | 'America/St_Vincent' | 'America/Swift_Current' | 'America/Tegucigalpa' | 'America/Thule' | 'America/Thunder_Bay' | 'America/Tijuana' | 'America/Toronto' | 'America/Tortola' | 'America/Vancouver' | 'America/Whitehorse' | 'America/Winnipeg' | 'America/Yakutat' | 'America/Yellowknife' | 'Antarctica/Casey' | 'Antarctica/Davis' | 'Antarctica/DumontDUrville' | 'Antarctica/Macquarie' | 'Antarctica/Mawson' | 'Antarctica/Palmer' | 'Antarctica/Rothera' | 'Antarctica/Syowa' | 'Antarctica/Troll' | 'Antarctica/Vostok' | 'Arctic/Longyearbyen' | 'Asia/Almaty' | 'Asia/Amman' | 'Asia/Anadyr' | 'Asia/Aqtau' | 'Asia/Aqtobe' | 'Asia/Ashgabat' | 'Asia/Atyrau' | 'Asia/Baghdad' | 'Asia/Baku' | 'Asia/Bangkok' | 'Asia/Barnaul' | 'Asia/Beirut' | 'Asia/Bishkek' | 'Asia/Brunei' | 'Asia/Chita' | 'Asia/Choibalsan' | 'Asia/Colombo' | 'Asia/Damascus' | 'Asia/Dhaka' | 'Asia/Dili' | 'Asia/Dubai' | 'Asia/Dushanbe' | 'Asia/Famagusta' | 'Asia/Gaza' | 'Asia/Hebron' | 'Asia/Ho_Chi_Minh' | 'Asia/Hong_Kong' | 'Asia/Hovd' | 'Asia/Irkutsk' | 'Asia/Jakarta' | 'Asia/Jayapura' | 'Asia/Jerusalem' | 'Asia/Kabul' | 'Asia/Kamchatka' | 'Asia/Karachi' | 'Asia/Kathmandu' | 'Asia/Khandyga' | 'Asia/Kolkata' | 'Asia/Krasnoyarsk' | 'Asia/Kuala_Lumpur' | 'Asia/Kuching' | 'Asia/Macau' | 'Asia/Magadan' | 'Asia/Makassar' | 'Asia/Manila' | 'Asia/Nicosia' | 'Asia/Novokuznetsk' | 'Asia/Novosibirsk' | 'Asia/Omsk' | 'Asia/Oral' | 'Asia/Phnom_Penh' | 'Asia/Pontianak' | 'Asia/Pyongyang' | 'Asia/Qatar' | 'Asia/Qostanay' | 'Asia/Qyzylorda' | 'Asia/Riyadh' | 'Asia/Sakhalin' | 'Asia/Samarkand' | 'Asia/Seoul' | 'Asia/Shanghai' | 'Asia/Singapore' | 'Asia/Srednekolymsk' | 'Asia/Taipei' | 'Asia/Tashkent' | 'Asia/Tbilisi' | 'Asia/Tehran' | 'Asia/Thimphu' | 'Asia/Tokyo' | 'Asia/Tomsk' | 'Asia/Ulaanbaatar' | 'Asia/Urumqi' | 'Asia/Ust-Nera' | 'Asia/Vladivostok' | 'Asia/Yakutsk' | 'Asia/Yangon' | 'Asia/Yekaterinburg' | 'Asia/Yerevan' | 'Atlantic/Azores' | 'Atlantic/Bermuda' | 'Atlantic/Canary' | 'Atlantic/Cape_Verde' | 'Atlantic/Faroe' | 'Atlantic/Madeira' | 'Atlantic/Reykjavik' | 'Atlantic/South_Georgia' | 'Atlantic/St_Helena' | 'Atlantic/Stanley' | 'Australia/Adelaide' | 'Australia/Brisbane' | 'Australia/Broken_Hill' | 'Australia/Currie' | 'Australia/Darwin' | 'Australia/Eucla' | 'Australia/Hobart' | 'Australia/Lindeman' | 'Australia/Lord_Howe' | 'Australia/Melbourne' | 'Australia/Perth' | 'Australia/Sydney' | 'Europe/Amsterdam' | 'Europe/Andorra' | 'Europe/Astrakhan' | 'Europe/Athens' | 'Europe/Belgrade' | 'Europe/Berlin' | 'Europe/Bratislava' | 'Europe/Brussels' | 'Europe/Bucharest' | 'Europe/Budapest' | 'Europe/Busingen' | 'Europe/Chisinau' | 'Europe/Copenhagen' | 'Europe/Dublin' | 'Europe/Gibraltar' | 'Europe/Guernsey' | 'Europe/Helsinki' | 'Europe/Isle_of_Man' | 'Europe/Istanbul' | 'Europe/Jersey' | 'Europe/Kaliningrad' | 'Europe/Kiev' | 'Europe/Kirov' | 'Europe/Lisbon' | 'Europe/Ljubljana' | 'Europe/London' | 'Europe/Luxembourg' | 'Europe/Madrid' | 'Europe/Malta' | 'Europe/Mariehamn' | 'Europe/Minsk' | 'Europe/Monaco' | 'Europe/Moscow' | 'Europe/Oslo' | 'Europe/Paris' | 'Europe/Podgorica' | 'Europe/Prague' | 'Europe/Riga' | 'Europe/Rome' | 'Europe/Samara' | 'Europe/San_Marino' | 'Europe/Sarajevo' | 'Europe/Saratov' | 'Europe/Simferopol' | 'Europe/Skopje' | 'Europe/Sofia' | 'Europe/Stockholm' | 'Europe/Tallinn' | 'Europe/Tirane' | 'Europe/Ulyanovsk' | 'Europe/Uzhgorod' | 'Europe/Vaduz' | 'Europe/Vatican' | 'Europe/Vienna' | 'Europe/Vilnius' | 'Europe/Volgograd' | 'Europe/Warsaw' | 'Europe/Zagreb' | 'Europe/Zaporozhye' | 'Europe/Zurich' | 'Indian/Antananarivo' | 'Indian/Chagos' | 'Indian/Christmas' | 'Indian/Cocos' | 'Indian/Comoro' | 'Indian/Kerguelen' | 'Indian/Mahe' | 'Indian/Maldives' | 'Indian/Mauritius' | 'Indian/Mayotte' | 'Indian/Reunion' | 'Pacific/Apia' | 'Pacific/Auckland' | 'Pacific/Bougainville' | 'Pacific/Chatham' | 'Pacific/Chuuk' | 'Pacific/Easter' | 'Pacific/Efate' | 'Pacific/Enderbury' | 'Pacific/Fakaofo' | 'Pacific/Fiji' | 'Pacific/Funafuti' | 'Pacific/Galapagos' | 'Pacific/Gambier' | 'Pacific/Guadalcanal' | 'Pacific/Guam' | 'Pacific/Honolulu' | 'Pacific/Kiritimati' | 'Pacific/Kosrae' | 'Pacific/Kwajalein' | 'Pacific/Majuro' | 'Pacific/Marquesas' | 'Pacific/Nauru' | 'Pacific/Niue' | 'Pacific/Norfolk' | 'Pacific/Noumea' | 'Pacific/Pago_Pago' | 'Pacific/Palau' | 'Pacific/Pitcairn' | 'Pacific/Pohnpei' | 'Pacific/Port_Moresby' | 'Pacific/Rarotonga' | 'Pacific/Tahiti' | 'Pacific/Tarawa' | 'Pacific/Tongatapu' | 'Pacific/Wake' | 'Pacific/Wallis' | 'UTC' | 'W-SU' | 'WET' | 'Zulu' | (string & {});
2
+ export default TimeZone;
@@ -0,0 +1,6 @@
1
+ import type { ReactNode } from 'react';
2
+ export type TranslationValues = Record<string, string | number | Date>;
3
+ export type RichTagsFunction = (chunks: ReactNode) => ReactNode;
4
+ export type MarkupTagsFunction = (chunks: string) => string;
5
+ export type RichTranslationValues = Record<string, TranslationValues[string] | RichTagsFunction>;
6
+ export type MarkupTranslationValues = Record<string, TranslationValues[string] | MarkupTagsFunction>;
@@ -0,0 +1,11 @@
1
+ import { type Formats as IntlFormats } from 'intl-messageformat';
2
+ import type Formats from './Formats.js';
3
+ import type TimeZone from './TimeZone.js';
4
+ /**
5
+ * `intl-messageformat` uses separate keys for `date` and `time`, but there's
6
+ * only one native API: `Intl.DateTimeFormat`. Additionally you might want to
7
+ * include both a time and a date in a value, therefore the separation doesn't
8
+ * seem so useful. We offer a single `dateTime` namespace instead, but we have
9
+ * to convert the format before `intl-messageformat` can be used.
10
+ */
11
+ export default function convertFormatsToIntlMessageFormat(globalFormats?: Formats, inlineFormats?: Formats, timeZone?: TimeZone): Partial<IntlFormats>;
@@ -0,0 +1,21 @@
1
+ import { type ReactNode } from 'react';
2
+ import type AbstractIntlMessages from './AbstractIntlMessages.js';
3
+ import type Formats from './Formats.js';
4
+ import type { InitializedIntlConfig } from './IntlConfig.js';
5
+ import IntlError from './IntlError.js';
6
+ import type { MessageKeys, NestedKeyOf, NestedValueOf } from './MessageKeys.js';
7
+ import type { MarkupTranslationValues, RichTranslationValues, TranslationValues } from './TranslationValues.js';
8
+ import type { Formatters, IntlCache } from './formatters.js';
9
+ export type CreateBaseTranslatorProps<Messages> = InitializedIntlConfig & {
10
+ cache: IntlCache;
11
+ formatters: Formatters;
12
+ namespace?: string;
13
+ messagesOrError: Messages | IntlError;
14
+ };
15
+ export default function createBaseTranslator<Messages extends AbstractIntlMessages, NestedKey extends NestedKeyOf<Messages>>(config: Omit<CreateBaseTranslatorProps<Messages>, 'messagesOrError'>): {
16
+ <TargetKey extends MessageKeys<NestedValueOf<Messages, NestedKey>, NestedKeyOf<NestedValueOf<Messages, NestedKey>>>>(key: TargetKey, values?: TranslationValues, formats?: Formats, _fallback?: never): string;
17
+ rich: (key: string, values?: RichTranslationValues, formats?: Formats, _fallback?: never) => ReactNode;
18
+ markup(key: Parameters<(key: string, values?: RichTranslationValues, formats?: Formats, _fallback?: never) => ReactNode>[0], values: MarkupTranslationValues, formats?: Parameters<(key: string, values?: RichTranslationValues, formats?: Formats, _fallback?: never) => ReactNode>[2], _fallback?: never): string;
19
+ raw(key: string): any;
20
+ has(key: string): boolean;
21
+ };
@@ -0,0 +1,47 @@
1
+ import type { ReactElement } from 'react';
2
+ import type { FormatNames, Locale } from './AppConfig.js';
3
+ import type DateTimeFormatOptions from './DateTimeFormatOptions.js';
4
+ import type Formats from './Formats.js';
5
+ import IntlError from './IntlError.js';
6
+ import type NumberFormatOptions from './NumberFormatOptions.js';
7
+ import type RelativeTimeFormatOptions from './RelativeTimeFormatOptions.js';
8
+ import type TimeZone from './TimeZone.js';
9
+ import { type Formatters, type IntlCache } from './formatters.js';
10
+ type Props = {
11
+ locale: Locale;
12
+ timeZone?: TimeZone;
13
+ onError?(error: IntlError): void;
14
+ formats?: Formats;
15
+ now?: Date;
16
+ /** @private */
17
+ _formatters?: Formatters;
18
+ /** @private */
19
+ _cache?: IntlCache;
20
+ };
21
+ export default function createFormatter(props: Props): {
22
+ dateTime: {
23
+ (value: Date | number, options?: DateTimeFormatOptions): string;
24
+ (value: Date | number, format?: FormatNames["dateTime"], options?: DateTimeFormatOptions): string;
25
+ };
26
+ number: {
27
+ (value: number | bigint, options?: NumberFormatOptions): string;
28
+ (value: number | bigint, format?: FormatNames["number"], options?: NumberFormatOptions): string;
29
+ };
30
+ relativeTime: {
31
+ (date: number | Date, now?: RelativeTimeFormatOptions["now"]): string;
32
+ (date: number | Date, options?: RelativeTimeFormatOptions): string;
33
+ };
34
+ list: {
35
+ <Value extends string | ReactElement<unknown, string | import("react").JSXElementConstructor<any>>>(value: Iterable<Value>, options?: Intl.ListFormatOptions): Value extends string ? string : Iterable<ReactElement>;
36
+ <Value extends string | ReactElement<unknown, string | import("react").JSXElementConstructor<any>>>(value: Iterable<Value>, format?: FormatNames["list"], options?: Intl.ListFormatOptions): Value extends string ? string : Iterable<ReactElement>;
37
+ };
38
+ dateTimeRange: {
39
+ (start: Date | number, end: Date | number, options?: DateTimeFormatOptions): string;
40
+ (start: Date | number, end: Date | number, format?: FormatNames["dateTime"], options?: DateTimeFormatOptions): string;
41
+ };
42
+ displayName: {
43
+ (value: string, options: Intl.DisplayNamesOptions): string;
44
+ (value: string, format: FormatNames["displayName"], options?: Intl.DisplayNamesOptions): string;
45
+ };
46
+ };
47
+ export {};