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
@@ -1,33 +0,0 @@
1
- import { inheritsLoose as _inheritsLoose, wrapNativeSuper as _wrapNativeSuper } from '../_virtual/_rollupPluginBabelHelpers.esm.js';
2
-
3
- var IntlErrorCode;
4
- (function (IntlErrorCode) {
5
- IntlErrorCode["MISSING_MESSAGE"] = "MISSING_MESSAGE";
6
- IntlErrorCode["MISSING_FORMAT"] = "MISSING_FORMAT";
7
- IntlErrorCode["INSUFFICIENT_PATH"] = "INSUFFICIENT_PATH";
8
- IntlErrorCode["INVALID_MESSAGE"] = "INVALID_MESSAGE";
9
- IntlErrorCode["INVALID_KEY"] = "INVALID_KEY";
10
- IntlErrorCode["FORMATTING_ERROR"] = "FORMATTING_ERROR";
11
- })(IntlErrorCode || (IntlErrorCode = {}));
12
- var IntlError = /*#__PURE__*/function (_Error) {
13
- _inheritsLoose(IntlError, _Error);
14
- function IntlError(code, originalMessage) {
15
- var _this;
16
- var message = code;
17
- if (originalMessage) {
18
- message += ': ' + originalMessage;
19
- }
20
- _this = _Error.call(this, message) || this;
21
- _this.code = void 0;
22
- _this.originalMessage = void 0;
23
- _this.code = code;
24
- if (originalMessage) {
25
- _this.originalMessage = originalMessage;
26
- }
27
- return _this;
28
- }
29
- return IntlError;
30
- }( /*#__PURE__*/_wrapNativeSuper(Error));
31
-
32
- export { IntlErrorCode, IntlError as default };
33
- //# sourceMappingURL=IntlError.esm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"IntlError.esm.js","sources":["../../src/core/IntlError.tsx"],"sourcesContent":["export enum IntlErrorCode {\n MISSING_MESSAGE = 'MISSING_MESSAGE',\n MISSING_FORMAT = 'MISSING_FORMAT',\n INSUFFICIENT_PATH = 'INSUFFICIENT_PATH',\n INVALID_MESSAGE = 'INVALID_MESSAGE',\n INVALID_KEY = 'INVALID_KEY',\n FORMATTING_ERROR = 'FORMATTING_ERROR'\n}\n\nexport default class IntlError extends Error {\n public readonly code: IntlErrorCode;\n public readonly originalMessage: string | undefined;\n\n constructor(code: IntlErrorCode, originalMessage?: string) {\n let message: string = code;\n if (originalMessage) {\n message += ': ' + originalMessage;\n }\n super(message);\n\n this.code = code;\n if (originalMessage) {\n this.originalMessage = originalMessage;\n }\n }\n}\n"],"names":["IntlErrorCode","IntlError","_Error","_inheritsLoose","code","originalMessage","_this","message","call","_wrapNativeSuper","Error"],"mappings":";;IAAYA,cAOX;AAPD,CAAA,UAAYA,aAAa,EAAA;AACvBA,EAAAA,aAAA,CAAA,iBAAA,CAAA,GAAA,iBAAmC,CAAA;AACnCA,EAAAA,aAAA,CA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';
3
-
4
- function setTimeZoneInFormats(formats, timeZone) {
5
- if (!formats) return formats;
6
- // The only way to set a time zone with `intl-messageformat` is to merge it into the formats
7
- // https://github.com/formatjs/formatjs/blob/8256c5271505cf2606e48e3c97ecdd16ede4f1b5/packages/intl/src/message.ts#L15
8
- return Object.keys(formats).reduce(function (acc, key) {
9
- acc[key] = _extends({
10
- timeZone: timeZone
11
- }, formats[key]);
12
- return acc;
13
- }, {});
14
- }
15
- /**
16
- * `intl-messageformat` uses separate keys for `date` and `time`, but there's
17
- * only one native API: `Intl.DateTimeFormat`. Additionally you might want to
18
- * include both a time and a date in a value, therefore the separation doesn't
19
- * seem so useful. We offer a single `dateTime` namespace instead, but we have
20
- * to convert the format before `intl-messageformat` can be used.
21
- */
22
- function convertFormatsToIntlMessageFormat(formats, timeZone) {
23
- var formatsWithTimeZone = timeZone ? _extends({}, formats, {
24
- dateTime: setTimeZoneInFormats(formats.dateTime, timeZone)
25
- }) : formats;
26
- var mfDateDefaults = IntlMessageFormat.formats.date;
27
- var defaultDateFormats = timeZone ? setTimeZoneInFormats(mfDateDefaults, timeZone) : mfDateDefaults;
28
- var mfTimeDefaults = IntlMessageFormat.formats.time;
29
- var defaultTimeFormats = timeZone ? setTimeZoneInFormats(mfTimeDefaults, timeZone) : mfTimeDefaults;
30
- return _extends({}, formatsWithTimeZone, {
31
- date: _extends({}, defaultDateFormats, formatsWithTimeZone == null ? void 0 : formatsWithTimeZone.dateTime),
32
- time: _extends({}, defaultTimeFormats, formatsWithTimeZone == null ? void 0 : formatsWithTimeZone.dateTime)
33
- });
34
- }
35
-
36
- export { convertFormatsToIntlMessageFormat as default };
37
- //# sourceMappingURL=convertFormatsToIntlMessageFormat.esm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"convertFormatsToIntlMessageFormat.esm.js","sources":["../../src/core/convertFormatsToIntlMessageFormat.tsx"],"sourcesContent":["// eslint-disable-next-line import/no-named-as-default -- False positive\nimport IntlMessageFormat, {Formats as IntlFormats} from 'intl-messageformat';\nimport DateTimeFormatOptions from './DateTimeFormatOptions';\nimport Formats from './Formats';\nimport TimeZone from './TimeZone';\n\nfunction setTimeZoneInFormats(\n formats: Record<string, DateTimeFormatOptions> | undefined,\n timeZone: TimeZone\n) {\n if (!formats) return formats;\n\n // The only way to set a time zone with `intl-messageformat` is to merge it into the formats\n // https://github.com/formatjs/formatjs/blob/8256c5271505cf2606e48e3c97ecdd16ede4f1b5/packages/intl/src/message.ts#L15\n return Object.keys(formats).reduce(\n (acc: Record<string, DateTimeFormatOptions>, key) => {\n acc[key] = {\n timeZone,\n ...formats[key]\n };\n return acc;\n },\n {}\n );\n}\n\n/**\n * `intl-messageformat` uses separate keys for `date` and `time`, but there's\n * only one native API: `Intl.DateTimeFormat`. Additionally you might want to\n * include both a time and a date in a value, therefore the separation doesn't\n * seem so useful. We offer a single `dateTime` namespace instead, but we have\n * to convert the format before `intl-messageformat` can be used.\n */\nexport default function convertFormatsToIntlMessageFormat(\n formats: Partial<Formats>,\n timeZone?: TimeZone\n): Partial<IntlFormats> {\n const formatsWithTimeZone = timeZone\n ? {...formats, dateTime: setTimeZoneInFormats(formats.dateTime, timeZone)}\n : formats;\n\n const mfDateDefaults = IntlMessageFormat.formats.date as Formats['dateTime'];\n const defaultDateFormats = timeZone\n ? setTimeZoneInFormats(mfDateDefaults, timeZone)\n : mfDateDefaults;\n\n const mfTimeDefaults = IntlMessageFormat.formats.time as Formats['dateTime'];\n const defaultTimeFormats = timeZone\n ? setTimeZoneInFormats(mfTimeDefaults, timeZone)\n : mfTimeDefaults;\n\n return {\n ...formatsWithTimeZone,\n date: {\n ...defaultDateFormats,\n ...formatsWithTimeZone?.dateTime\n },\n time: {\n ...defaultTimeFormats,\n ...formatsWithTimeZone?.dateTime\n }\n };\n}\n"],"names":["setTimeZoneInFormats","formats","timeZone","Object","keys","reduce","acc","key","_extends","convertFormatsToIntlMessageFormat","formatsWithTimeZone","dateTime","mfDateDefaults","IntlMessageFormat","date","defaultDateF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AAnBA,IAAAA,GAAAA,KAAAA,CAAAA,GAAAA,mBAAmB,CAAEC,QAAQ,CACjC;IACDM,IAAI,EAAAT,QAAA,CACCU,EAAAA,EAAAA,kBAAkB,EAClBR,mBAAmB,IAAA,IAAA,GAAA,KAAA,CAAA,GAAnBA,mBAAmB,CAAEC,QAAQ,CAAA;AACjC,GAAA,CAAA,CAAA;AAEL;;;;"}
@@ -1,210 +0,0 @@
1
- import { extends as _extends } from '../_virtual/_rollupPluginBabelHelpers.esm.js';
2
- import IntlMessageFormat from 'intl-messageformat';
3
- import { isValidElement, cloneElement } from 'react';
4
- import IntlError, { IntlErrorCode } from './IntlError.esm.js';
5
- import convertFormatsToIntlMessageFormat from './convertFormatsToIntlMessageFormat.esm.js';
6
- import { defaultOnError, defaultGetMessageFallback } from './defaults.esm.js';
7
-
8
- function resolvePath(messages, key, namespace) {
9
- if (!messages) {
10
- throw new Error(process.env.NODE_ENV !== 'production' ? "No messages available at `" + namespace + "`." : undefined);
11
- }
12
- var message = messages;
13
- key.split('.').forEach(function (part) {
14
- var next = message[part];
15
- if (part == null || next == null) {
16
- throw new Error(process.env.NODE_ENV !== 'production' ? "Could not resolve `" + key + "` in " + (namespace ? "`" + namespace + "`" : 'messages') + "." : undefined);
17
- }
18
- message = next;
19
- });
20
- return message;
21
- }
22
- function prepareTranslationValues(values) {
23
- if (Object.keys(values).length === 0) return undefined;
24
- // Workaround for https://github.com/formatjs/formatjs/issues/1467
25
- var transformedValues = {};
26
- Object.keys(values).forEach(function (key) {
27
- var index = 0;
28
- var value = values[key];
29
- var transformed;
30
- if (typeof value === 'function') {
31
- transformed = function transformed(chunks) {
32
- var result = value(chunks);
33
- return isValidElement(result) ? cloneElement(result, {
34
- key: key + index++
35
- }) : result;
36
- };
37
- } else {
38
- transformed = value;
39
- }
40
- transformedValues[key] = transformed;
41
- });
42
- return transformedValues;
43
- }
44
- function getMessagesOrError(_ref) {
45
- var messages = _ref.messages,
46
- namespace = _ref.namespace,
47
- _ref$onError = _ref.onError,
48
- onError = _ref$onError === void 0 ? defaultOnError : _ref$onError;
49
- try {
50
- if (!messages) {
51
- throw new Error(process.env.NODE_ENV !== 'production' ? "No messages were configured on the provider." : undefined);
52
- }
53
- var retrievedMessages = namespace ? resolvePath(messages, namespace) : messages;
54
- if (!retrievedMessages) {
55
- throw new Error(process.env.NODE_ENV !== 'production' ? "No messages for namespace `" + namespace + "` found." : undefined);
56
- }
57
- return retrievedMessages;
58
- } catch (error) {
59
- var intlError = new IntlError(IntlErrorCode.MISSING_MESSAGE, error.message);
60
- onError(intlError);
61
- return intlError;
62
- }
63
- }
64
- function getPlainMessage(candidate, values) {
65
- if (values) return undefined;
66
- var unescapedMessage = candidate.replace(/'([{}])/gi, '$1');
67
- // Placeholders can be in the message if there are default values,
68
- // or if the user has forgotten to provide values. In the latter
69
- // case we need to compile the message to receive an error.
70
- var hasPlaceholders = /<|{/.test(unescapedMessage);
71
- if (!hasPlaceholders) {
72
- return unescapedMessage;
73
- }
74
- return undefined;
75
- }
76
- function createBaseTranslator(config) {
77
- var messagesOrError = getMessagesOrError({
78
- messages: config.messages,
79
- namespace: config.namespace,
80
- onError: config.onError
81
- });
82
- return createBaseTranslatorImpl(_extends({}, config, {
83
- messagesOrError: messagesOrError
84
- }));
85
- }
86
- function createBaseTranslatorImpl(_ref2) {
87
- var defaultTranslationValues = _ref2.defaultTranslationValues,
88
- globalFormats = _ref2.formats,
89
- _ref2$getMessageFallb = _ref2.getMessageFallback,
90
- getMessageFallback = _ref2$getMessageFallb === void 0 ? defaultGetMessageFallback : _ref2$getMessageFallb,
91
- locale = _ref2.locale,
92
- messageFormatCache = _ref2.messageFormatCache,
93
- messagesOrError = _ref2.messagesOrError,
94
- namespace = _ref2.namespace,
95
- onError = _ref2.onError,
96
- timeZone = _ref2.timeZone;
97
- function getFallbackFromErrorAndNotify(key, code, message) {
98
- var error = new IntlError(code, message);
99
- onError(error);
100
- return getMessageFallback({
101
- error: error,
102
- key: key,
103
- namespace: namespace
104
- });
105
- }
106
- function translateBaseFn( /** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */
107
- key, /** Key value pairs for values to interpolate into the message. */
108
- values, /** Provide custom formats for numbers, dates and times. */
109
- formats) {
110
- if (messagesOrError instanceof IntlError) {
111
- // We have already warned about this during render
112
- return getMessageFallback({
113
- error: messagesOrError,
114
- key: key,
115
- namespace: namespace
116
- });
117
- }
118
- var messages = messagesOrError;
119
- var message;
120
- try {
121
- message = resolvePath(messages, key, namespace);
122
- } catch (error) {
123
- return getFallbackFromErrorAndNotify(key, IntlErrorCode.MISSING_MESSAGE, error.message);
124
- }
125
- function joinPath(parts) {
126
- return parts.filter(function (part) {
127
- return part != null;
128
- }).join('.');
129
- }
130
- var cacheKey = joinPath([locale, namespace, key, String(message)]);
131
- var messageFormat;
132
- if (messageFormatCache != null && messageFormatCache.has(cacheKey)) {
133
- messageFormat = messageFormatCache.get(cacheKey);
134
- } else {
135
- if (typeof message === 'object') {
136
- var code, errorMessage;
137
- if (Array.isArray(message)) {
138
- code = IntlErrorCode.INVALID_MESSAGE;
139
- if (process.env.NODE_ENV !== 'production') {
140
- errorMessage = "Message at `" + joinPath([namespace, key]) + "` resolved to an array, but only strings are supported. See https://next-intl-docs.vercel.app/docs/usage/messages#arrays-of-messages";
141
- }
142
- } else {
143
- code = IntlErrorCode.INSUFFICIENT_PATH;
144
- if (process.env.NODE_ENV !== 'production') {
145
- errorMessage = "Message at `" + joinPath([namespace, key]) + "` 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";
146
- }
147
- }
148
- return getFallbackFromErrorAndNotify(key, code, errorMessage);
149
- }
150
- // Hot path that avoids creating an `IntlMessageFormat` instance
151
- var plainMessage = getPlainMessage(message, values);
152
- if (plainMessage) return plainMessage;
153
- try {
154
- messageFormat = new IntlMessageFormat(message, locale, convertFormatsToIntlMessageFormat(_extends({}, globalFormats, formats), timeZone));
155
- } catch (error) {
156
- return getFallbackFromErrorAndNotify(key, IntlErrorCode.INVALID_MESSAGE, error.message);
157
- }
158
- messageFormatCache == null ? void 0 : messageFormatCache.set(cacheKey, messageFormat);
159
- }
160
- try {
161
- var formattedMessage = messageFormat.format(
162
- // @ts-ignore `intl-messageformat` expects a different format
163
- // for rich text elements since a recent minor update. This
164
- // needs to be evaluated in detail, possibly also in regards
165
- // to be able to format to parts.
166
- prepareTranslationValues(_extends({}, defaultTranslationValues, values)));
167
- if (formattedMessage == null) {
168
- throw new Error(process.env.NODE_ENV !== 'production' ? "Unable to format `" + key + "` in " + (namespace ? "namespace `" + namespace + "`" : 'messages') : undefined);
169
- }
170
- // Limit the function signature to return strings or React elements
171
- return isValidElement(formattedMessage) ||
172
- // Arrays of React elements
173
- Array.isArray(formattedMessage) || typeof formattedMessage === 'string' ? formattedMessage : String(formattedMessage);
174
- } catch (error) {
175
- return getFallbackFromErrorAndNotify(key, IntlErrorCode.FORMATTING_ERROR, error.message);
176
- }
177
- }
178
- function translateFn( /** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */
179
- key, /** Key value pairs for values to interpolate into the message. */
180
- values, /** Provide custom formats for numbers, dates and times. */
181
- formats) {
182
- var result = translateBaseFn(key, values, formats);
183
- if (typeof result !== 'string') {
184
- return getFallbackFromErrorAndNotify(key, IntlErrorCode.INVALID_MESSAGE, process.env.NODE_ENV !== 'production' ? "The message `" + key + "` in " + (namespace ? "namespace `" + namespace + "`" : 'messages') + " didn't resolve to a string. If you want to format rich text, use `t.rich` instead." : undefined);
185
- }
186
- return result;
187
- }
188
- translateFn.rich = translateBaseFn;
189
- translateFn.raw = function ( /** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */
190
- key) {
191
- if (messagesOrError instanceof IntlError) {
192
- // We have already warned about this during render
193
- return getMessageFallback({
194
- error: messagesOrError,
195
- key: key,
196
- namespace: namespace
197
- });
198
- }
199
- var messages = messagesOrError;
200
- try {
201
- return resolvePath(messages, key, namespace);
202
- } catch (error) {
203
- return getFallbackFromErrorAndNotify(key, IntlErrorCode.MISSING_MESSAGE, error.message);
204
- }
205
- };
206
- return translateFn;
207
- }
208
-
209
- export { createBaseTranslator as default };
210
- //# sourceMappingURL=createBaseTranslator.esm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createBaseTranslator.esm.js","sources":["../../src/core/createBaseTranslator.tsx"],"sourcesContent":["// eslint-disable-next-line import/no-named-as-default -- False positive\nimport IntlMessageFormat from 'intl-messageformat';\nimport {\n cloneElement,\n isValidElement,\n ReactElement,\n ReactNode,\n ReactNodeArray\n} from 'react';\nimport AbstractIntlMessages from './AbstractIntlMessages';\nimport Formats from './Formats';\nimport {InitializedIntlConfig} from './IntlConfig';\nimport IntlError, {IntlErrorCode} from './IntlError';\nimport MessageFormatCache from './MessageFormatCache';\nimport TranslationValues, {RichTranslationValues} from './TranslationValues';\nimport convertFormatsToIntlMessageFormat from './convertFormatsToIntlMessageFormat';\nimport {defaultGetMessageFallback, defaultOnError} from './defaults';\nimport MessageKeys from './utils/MessageKeys';\nimport NestedKeyOf from './utils/NestedKeyOf';\nimport NestedValueOf from './utils/NestedValueOf';\n\nfunction resolvePath(\n messages: AbstractIntlMessages | undefined,\n key: string,\n namespace?: string\n) {\n if (!messages) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? `No messages available at \\`${namespace}\\`.`\n : undefined\n );\n }\n\n let message = messages;\n\n key.split('.').forEach((part) => {\n const next = (message as any)[part];\n\n if (part == null || next == null) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? `Could not resolve \\`${key}\\` in ${\n namespace ? `\\`${namespace}\\`` : 'messages'\n }.`\n : undefined\n );\n }\n\n message = next;\n });\n\n return message;\n}\n\nfunction prepareTranslationValues(values: RichTranslationValues) {\n if (Object.keys(values).length === 0) return undefined;\n\n // Workaround for https://github.com/formatjs/formatjs/issues/1467\n const transformedValues: RichTranslationValues = {};\n Object.keys(values).forEach((key) => {\n let index = 0;\n const value = values[key];\n\n let transformed;\n if (typeof value === 'function') {\n transformed = (chunks: ReactNode) => {\n const result = value(chunks);\n\n return isValidElement(result)\n ? cloneElement(result, {key: key + index++})\n : result;\n };\n } else {\n transformed = value;\n }\n\n transformedValues[key] = transformed;\n });\n\n return transformedValues;\n}\n\nfunction getMessagesOrError<Messages extends AbstractIntlMessages>({\n messages,\n namespace,\n onError = defaultOnError\n}: {\n messages?: Messages;\n namespace?: string;\n onError?(error: IntlError): void;\n}) {\n try {\n if (!messages) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? `No messages were configured on the provider.`\n : undefined\n );\n }\n\n const retrievedMessages = namespace\n ? resolvePath(messages, namespace)\n : messages;\n\n if (!retrievedMessages) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? `No messages for namespace \\`${namespace}\\` found.`\n : undefined\n );\n }\n\n return retrievedMessages;\n } catch (error) {\n const intlError = new IntlError(\n IntlErrorCode.MISSING_MESSAGE,\n (error as Error).message\n );\n onError(intlError);\n return intlError;\n }\n}\n\nexport type CreateBaseTranslatorProps<Messages> = InitializedIntlConfig & {\n messageFormatCache?: MessageFormatCache;\n defaultTranslationValues?: RichTranslationValues;\n namespace?: string;\n messagesOrError: Messages | IntlError;\n};\n\nfunction getPlainMessage(candidate: string, values?: unknown) {\n if (values) return undefined;\n\n const unescapedMessage = candidate.replace(/'([{}])/gi, '$1');\n\n // Placeholders can be in the message if there are default values,\n // or if the user has forgotten to provide values. In the latter\n // case we need to compile the message to receive an error.\n const hasPlaceholders = /<|{/.test(unescapedMessage);\n\n if (!hasPlaceholders) {\n return unescapedMessage;\n }\n\n return undefined;\n}\n\nexport default function createBaseTranslator<\n Messages extends AbstractIntlMessages,\n NestedKey extends NestedKeyOf<Messages>\n>(config: Omit<CreateBaseTranslatorProps<Messages>, 'messagesOrError'>) {\n const messagesOrError = getMessagesOrError({\n messages: config.messages,\n namespace: config.namespace,\n onError: config.onError\n }) as Messages | IntlError;\n\n return createBaseTranslatorImpl<Messages, NestedKey>({\n ...config,\n messagesOrError\n });\n}\n\nfunction createBaseTranslatorImpl<\n Messages extends AbstractIntlMessages,\n NestedKey extends NestedKeyOf<Messages>\n>({\n defaultTranslationValues,\n formats: globalFormats,\n getMessageFallback = defaultGetMessageFallback,\n locale,\n messageFormatCache,\n messagesOrError,\n namespace,\n onError,\n timeZone\n}: CreateBaseTranslatorProps<Messages>) {\n function getFallbackFromErrorAndNotify(\n key: string,\n code: IntlErrorCode,\n message?: string\n ) {\n const error = new IntlError(code, message);\n onError(error);\n return getMessageFallback({error, key, namespace});\n }\n\n function translateBaseFn(\n /** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */\n key: string,\n /** Key value pairs for values to interpolate into the message. */\n values?: RichTranslationValues,\n /** Provide custom formats for numbers, dates and times. */\n formats?: Partial<Formats>\n ): string | ReactElement | ReactNodeArray {\n if (messagesOrError instanceof IntlError) {\n // We have already warned about this during render\n return getMessageFallback({\n error: messagesOrError,\n key,\n namespace\n });\n }\n const messages = messagesOrError;\n\n let message;\n try {\n message = resolvePath(messages, key, namespace);\n } catch (error) {\n return getFallbackFromErrorAndNotify(\n key,\n IntlErrorCode.MISSING_MESSAGE,\n (error as Error).message\n );\n }\n\n function joinPath(parts: Array<string | undefined>) {\n return parts.filter((part) => part != null).join('.');\n }\n\n const cacheKey = joinPath([locale, namespace, key, String(message)]);\n\n let messageFormat: IntlMessageFormat;\n if (messageFormatCache?.has(cacheKey)) {\n messageFormat = messageFormatCache.get(cacheKey)!;\n } else {\n if (typeof message === 'object') {\n let code, errorMessage;\n if (Array.isArray(message)) {\n code = IntlErrorCode.INVALID_MESSAGE;\n if (process.env.NODE_ENV !== 'production') {\n errorMessage = `Message at \\`${joinPath([\n namespace,\n key\n ])}\\` resolved to an array, but only strings are supported. See https://next-intl-docs.vercel.app/docs/usage/messages#arrays-of-messages`;\n }\n } else {\n code = IntlErrorCode.INSUFFICIENT_PATH;\n if (process.env.NODE_ENV !== 'production') {\n errorMessage = `Message at \\`${joinPath([\n namespace,\n key\n ])}\\` 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`;\n }\n }\n\n return getFallbackFromErrorAndNotify(key, code, errorMessage);\n }\n\n // Hot path that avoids creating an `IntlMessageFormat` instance\n const plainMessage = getPlainMessage(message as string, values);\n if (plainMessage) return plainMessage;\n\n try {\n messageFormat = new IntlMessageFormat(\n message,\n locale,\n convertFormatsToIntlMessageFormat(\n {...globalFormats, ...formats},\n timeZone\n )\n );\n } catch (error) {\n return getFallbackFromErrorAndNotify(\n key,\n IntlErrorCode.INVALID_MESSAGE,\n (error as Error).message\n );\n }\n\n messageFormatCache?.set(cacheKey, messageFormat);\n }\n\n try {\n const formattedMessage = messageFormat.format(\n // @ts-ignore `intl-messageformat` expects a different format\n // for rich text elements since a recent minor update. This\n // needs to be evaluated in detail, possibly also in regards\n // to be able to format to parts.\n prepareTranslationValues({...defaultTranslationValues, ...values})\n );\n\n if (formattedMessage == null) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? `Unable to format \\`${key}\\` in ${\n namespace ? `namespace \\`${namespace}\\`` : 'messages'\n }`\n : undefined\n );\n }\n\n // Limit the function signature to return strings or React elements\n return isValidElement(formattedMessage) ||\n // Arrays of React elements\n Array.isArray(formattedMessage) ||\n typeof formattedMessage === 'string'\n ? formattedMessage\n : String(formattedMessage);\n } catch (error) {\n return getFallbackFromErrorAndNotify(\n key,\n IntlErrorCode.FORMATTING_ERROR,\n (error as Error).message\n );\n }\n }\n\n function translateFn<\n TargetKey extends MessageKeys<\n NestedValueOf<Messages, NestedKey>,\n NestedKeyOf<NestedValueOf<Messages, NestedKey>>\n >\n >(\n /** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */\n key: TargetKey,\n /** Key value pairs for values to interpolate into the message. */\n values?: TranslationValues,\n /** Provide custom formats for numbers, dates and times. */\n formats?: Partial<Formats>\n ): string {\n const result = translateBaseFn(key, values, formats);\n\n if (typeof result !== 'string') {\n return getFallbackFromErrorAndNotify(\n key,\n IntlErrorCode.INVALID_MESSAGE,\n process.env.NODE_ENV !== 'production'\n ? `The message \\`${key}\\` in ${\n namespace ? `namespace \\`${namespace}\\`` : 'messages'\n } didn't resolve to a string. If you want to format rich text, use \\`t.rich\\` instead.`\n : undefined\n );\n }\n\n return result;\n }\n\n translateFn.rich = translateBaseFn;\n\n translateFn.raw = (\n /** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */\n key: string\n ): any => {\n if (messagesOrError instanceof IntlError) {\n // We have already warned about this during render\n return getMessageFallback({\n error: messagesOrError,\n key,\n namespace\n });\n }\n const messages = messagesOrError;\n\n try {\n return resolvePath(messages, key, namespace);\n } catch (error) {\n return getFallbackFromErrorAndNotify(\n key,\n IntlErrorCode.MISSING_MESSAGE,\n (error as Error).message\n );\n }\n };\n\n return translateFn;\n}\n"],"names":["resolvePath","messages","key","namespace","Error","process","env","NODE_ENV","undefined","message","split","forEach","part","next","prepareTranslationValues","values","Object","keys","length","transformedValues","index","value","transformed","chunks","result","isValidElement","cloneElement","getMessagesOrError","_ref","_ref$onError","onError","defaultOnError","retrievedMessages","error","intlError","IntlError","IntlErrorCode","MISSING_MESSAGE","getPlainMessage","candidate","unescapedMessage","replace","hasPlaceholders","test","createBaseTranslator","config","messagesOrError","createBaseTranslatorImpl","_extends","_ref2","defaultTranslationValues","globalFormats","formats","_ref2$getMessageFallb","getMessageFallback","defaultGetMessageFallback","locale","messageFormatCache","timeZone","getFallbackFromErrorAndNotify","code","translateBaseFn","joinPath","parts","filter","join","cacheKey","String","messageFormat","has","get","errorMessage","Array","isArray","INVALID_MESSAGE","INSUFFICIENT_PATH","plainMessage","IntlMessageFormat","convertFormatsToIntlMessageFormat","set","formattedMessage","format","FORMATTING_ERROR","translateFn","rich","raw"],"mappings":";;;;;;;AAqBA,SAASA,WAAWA,CAClBC,QAA0C,EAC1CC,GAAW,EACXC,SAAkB,EAAA;E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WAAW,CAACC,QAAQ,EAAEC,GAAG,EAAEC,SAAS,CAAC,CAAA;KAC7C,CAAC,OAAO8B,KAAK,EAAE;MACd,OAAO0B,6BAA6B,CAClCzD,GAAG,EACHkC,aAAa,CAACC,eAAe,EAC5BJ,KAAe,CAACxB,OAAO,CACzB,CAAA;AACF,KAAA;GACF,CAAA;AAED,EAAA,OAAO0E,WAAW,CAAA;AACpB;;;;"}
@@ -1,138 +0,0 @@
1
- import { extends as _extends } from '../_virtual/_rollupPluginBabelHelpers.esm.js';
2
- import IntlError, { IntlErrorCode } from './IntlError.esm.js';
3
- import { defaultOnError } from './defaults.esm.js';
4
-
5
- var MINUTE = 60;
6
- var HOUR = MINUTE * 60;
7
- var DAY = HOUR * 24;
8
- var WEEK = DAY * 7;
9
- var MONTH = DAY * (365 / 12); // Approximation
10
- var YEAR = DAY * 365;
11
- function getRelativeTimeFormatConfig(seconds) {
12
- var absValue = Math.abs(seconds);
13
- var value, unit;
14
- // We have to round the resulting values, as `Intl.RelativeTimeFormat`
15
- // will include fractions like '2.1 hours ago'.
16
- if (absValue < MINUTE) {
17
- unit = 'second';
18
- value = Math.round(seconds);
19
- } else if (absValue < HOUR) {
20
- unit = 'minute';
21
- value = Math.round(seconds / MINUTE);
22
- } else if (absValue < DAY) {
23
- unit = 'hour';
24
- value = Math.round(seconds / HOUR);
25
- } else if (absValue < WEEK) {
26
- unit = 'day';
27
- value = Math.round(seconds / DAY);
28
- } else if (absValue < MONTH) {
29
- unit = 'week';
30
- value = Math.round(seconds / WEEK);
31
- } else if (absValue < YEAR) {
32
- unit = 'month';
33
- value = Math.round(seconds / MONTH);
34
- } else {
35
- unit = 'year';
36
- value = Math.round(seconds / YEAR);
37
- }
38
- return {
39
- value: value,
40
- unit: unit
41
- };
42
- }
43
- function createFormatter(_ref) {
44
- var formats = _ref.formats,
45
- locale = _ref.locale,
46
- globalNow = _ref.now,
47
- _ref$onError = _ref.onError,
48
- onError = _ref$onError === void 0 ? defaultOnError : _ref$onError,
49
- timeZone = _ref.timeZone;
50
- function resolveFormatOrOptions(typeFormats, formatOrOptions) {
51
- var options;
52
- if (typeof formatOrOptions === 'string') {
53
- var formatName = formatOrOptions;
54
- options = typeFormats == null ? void 0 : typeFormats[formatName];
55
- if (!options) {
56
- var error = new IntlError(IntlErrorCode.MISSING_FORMAT, process.env.NODE_ENV !== 'production' ? "Format `" + formatName + "` is not available. You can configure it on the provider or provide custom options." : undefined);
57
- onError(error);
58
- throw error;
59
- }
60
- } else {
61
- options = formatOrOptions;
62
- }
63
- return options;
64
- }
65
- function getFormattedValue(value, formatOrOptions, typeFormats, formatter) {
66
- var options;
67
- try {
68
- options = resolveFormatOrOptions(typeFormats, formatOrOptions);
69
- } catch (error) {
70
- return String(value);
71
- }
72
- try {
73
- return formatter(options);
74
- } catch (error) {
75
- onError(new IntlError(IntlErrorCode.FORMATTING_ERROR, error.message));
76
- return String(value);
77
- }
78
- }
79
- function dateTime( /** If a number is supplied, this is interpreted as a UTC timestamp. */
80
- value,
81
- /** If a time zone is supplied, the `value` is converted to that time zone.
82
- * Otherwise the user time zone will be used. */
83
- formatOrOptions) {
84
- return getFormattedValue(value, formatOrOptions, formats == null ? void 0 : formats.dateTime, function (options) {
85
- var _options;
86
- if (timeZone && !((_options = options) != null && _options.timeZone)) {
87
- options = _extends({}, options, {
88
- timeZone: timeZone
89
- });
90
- }
91
- return new Intl.DateTimeFormat(locale, options).format(value);
92
- });
93
- }
94
- function number(value, formatOrOptions) {
95
- return getFormattedValue(value, formatOrOptions, formats == null ? void 0 : formats.number, function (options) {
96
- return new Intl.NumberFormat(locale, options).format(value);
97
- });
98
- }
99
- function relativeTime( /** The date time that needs to be formatted. */
100
- date, /** The reference point in time to which `date` will be formatted in relation to. */
101
- now) {
102
- try {
103
- if (!now) {
104
- if (globalNow) {
105
- now = globalNow;
106
- } else {
107
- throw new Error(process.env.NODE_ENV !== 'production' ? "The `now` parameter wasn't provided and there was no global fallback configured on the provider." : undefined);
108
- }
109
- }
110
- var dateDate = date instanceof Date ? date : new Date(date);
111
- var nowDate = now instanceof Date ? now : new Date(now);
112
- var seconds = (dateDate.getTime() - nowDate.getTime()) / 1000;
113
- var _getRelativeTimeForma = getRelativeTimeFormatConfig(seconds),
114
- unit = _getRelativeTimeForma.unit,
115
- value = _getRelativeTimeForma.value;
116
- return new Intl.RelativeTimeFormat(locale, {
117
- numeric: 'auto'
118
- }).format(value, unit);
119
- } catch (error) {
120
- onError(new IntlError(IntlErrorCode.FORMATTING_ERROR, error.message));
121
- return String(date);
122
- }
123
- }
124
- function list(value, formatOrOptions) {
125
- return getFormattedValue(value, formatOrOptions, formats == null ? void 0 : formats.list, function (options) {
126
- return new Intl.ListFormat(locale, options).format(value);
127
- });
128
- }
129
- return {
130
- dateTime: dateTime,
131
- number: number,
132
- relativeTime: relativeTime,
133
- list: list
134
- };
135
- }
136
-
137
- export { createFormatter as default };
138
- //# sourceMappingURL=createFormatter.esm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createFormatter.esm.js","sources":["../../src/core/createFormatter.tsx"],"sourcesContent":["import DateTimeFormatOptions from './DateTimeFormatOptions';\nimport Formats from './Formats';\nimport IntlError, {IntlErrorCode} from './IntlError';\nimport NumberFormatOptions from './NumberFormatOptions';\nimport TimeZone from './TimeZone';\nimport {defaultOnError} from './defaults';\n\nconst MINUTE = 60;\nconst HOUR = MINUTE * 60;\nconst DAY = HOUR * 24;\nconst WEEK = DAY * 7;\nconst MONTH = DAY * (365 / 12); // Approximation\nconst YEAR = DAY * 365;\n\nfunction getRelativeTimeFormatConfig(seconds: number) {\n const absValue = Math.abs(seconds);\n let value, unit: Intl.RelativeTimeFormatUnit;\n\n // We have to round the resulting values, as `Intl.RelativeTimeFormat`\n // will include fractions like '2.1 hours ago'.\n\n if (absValue < MINUTE) {\n unit = 'second';\n value = Math.round(seconds);\n } else if (absValue < HOUR) {\n unit = 'minute';\n value = Math.round(seconds / MINUTE);\n } else if (absValue < DAY) {\n unit = 'hour';\n value = Math.round(seconds / HOUR);\n } else if (absValue < WEEK) {\n unit = 'day';\n value = Math.round(seconds / DAY);\n } else if (absValue < MONTH) {\n unit = 'week';\n value = Math.round(seconds / WEEK);\n } else if (absValue < YEAR) {\n unit = 'month';\n value = Math.round(seconds / MONTH);\n } else {\n unit = 'year';\n value = Math.round(seconds / YEAR);\n }\n\n return {value, unit};\n}\n\ntype Props = {\n locale: string;\n timeZone?: TimeZone;\n onError?(error: IntlError): void;\n formats?: Partial<Formats>;\n now?: Date;\n};\n\nexport default function createFormatter({\n formats,\n locale,\n now: globalNow,\n onError = defaultOnError,\n timeZone\n}: Props) {\n function resolveFormatOrOptions<Options>(\n typeFormats: Record<string, Options> | undefined,\n formatOrOptions?: string | Options\n ) {\n let options;\n if (typeof formatOrOptions === 'string') {\n const formatName = formatOrOptions;\n options = typeFormats?.[formatName];\n\n if (!options) {\n const error = new IntlError(\n IntlErrorCode.MISSING_FORMAT,\n process.env.NODE_ENV !== 'production'\n ? `Format \\`${formatName}\\` is not available. You can configure it on the provider or provide custom options.`\n : undefined\n );\n onError(error);\n throw error;\n }\n } else {\n options = formatOrOptions;\n }\n\n return options;\n }\n\n function getFormattedValue<Value, Options>(\n value: Value,\n formatOrOptions: string | Options | undefined,\n typeFormats: Record<string, Options> | undefined,\n formatter: (options?: Options) => string\n ) {\n let options;\n try {\n options = resolveFormatOrOptions(typeFormats, formatOrOptions);\n } catch (error) {\n return String(value);\n }\n\n try {\n return formatter(options);\n } catch (error) {\n onError(\n new IntlError(IntlErrorCode.FORMATTING_ERROR, (error as Error).message)\n );\n return String(value);\n }\n }\n\n function dateTime(\n /** If a number is supplied, this is interpreted as a UTC timestamp. */\n value: Date | number,\n /** If a time zone is supplied, the `value` is converted to that time zone.\n * Otherwise the user time zone will be used. */\n formatOrOptions?: string | DateTimeFormatOptions\n ) {\n return getFormattedValue(\n value,\n formatOrOptions,\n formats?.dateTime,\n (options) => {\n if (timeZone && !options?.timeZone) {\n options = {...options, timeZone};\n }\n\n return new Intl.DateTimeFormat(locale, options).format(value);\n }\n );\n }\n\n function number(\n value: number | bigint,\n formatOrOptions?: string | NumberFormatOptions\n ) {\n return getFormattedValue(\n value,\n formatOrOptions,\n formats?.number,\n (options) => new Intl.NumberFormat(locale, options).format(value)\n );\n }\n\n function relativeTime(\n /** The date time that needs to be formatted. */\n date: number | Date,\n /** The reference point in time to which `date` will be formatted in relation to. */\n now?: number | Date\n ) {\n try {\n if (!now) {\n if (globalNow) {\n now = globalNow;\n } else {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? `The \\`now\\` parameter wasn't provided and there was no global fallback configured on the provider.`\n : undefined\n );\n }\n }\n\n const dateDate = date instanceof Date ? date : new Date(date);\n const nowDate = now instanceof Date ? now : new Date(now);\n\n const seconds = (dateDate.getTime() - nowDate.getTime()) / 1000;\n const {unit, value} = getRelativeTimeFormatConfig(seconds);\n\n return new Intl.RelativeTimeFormat(locale, {\n numeric: 'auto'\n }).format(value, unit);\n } catch (error) {\n onError(\n new IntlError(IntlErrorCode.FORMATTING_ERROR, (error as Error).message)\n );\n return String(date);\n }\n }\n\n function list(\n value: Iterable<string>,\n formatOrOptions?: string | Intl.ListFormatOptions\n ) {\n return getFormattedValue(value, formatOrOptions, formats?.list, (options) =>\n new Intl.ListFormat(locale, options).format(value)\n );\n }\n\n return {dateTime, number, relativeTime, list};\n}\n"],"names":["MINUTE","HOUR","DAY","WEEK","MONTH","YEAR","getRelativeTimeFormatConfig","seconds","absValue","Math","abs","value","unit","round","createFormatter","_ref","formats","locale","globalNow","now","_ref$onError","onError","defaultOnError","timeZone","resolveFormatOrOptions","typeFormats","formatOrOptions","options","formatName","error","IntlError","IntlErrorCode","MISSING_FORMAT","process","env","NODE_ENV","undefined","getFormattedValue","formatter","String","FORMATTING_ERROR","message","dateTime","_options","_extends","Intl","DateTimeFormat","format","number","NumberFormat","relativeTime","date","Error","dateDate","Date","nowDate","getTime","_getRelativeTimeForma","RelativeTimeFormat","numeric","list","ListFormat"],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AAO,CAACC,OAAO,EAAE,IAAI,IAAI,CAAA;AAC/D,MAAA,IAAAC,qBAAA,GAAsBnD,2BAA2B,CAACC,OAAO,CAAC;QAAnDK,IAAI,GAAA6C,qBAAA,CAAJ7C,IAAI;QAAED,KAAK,GAAA8C,qBAAA,CAAL9C,KAAK,CAAA;AAElB,MAAA,OAAO,IAAIkC,IAAI,CAACa,kBAAkB,CAACzC,MAAM,EAAE;AACzC0C,QAAAA,OAAO,EAAE,MAAA;AACV,OAAA,CAAC,CAACZ,MAAM,CAACpC,KAAK,EAAEC,IAAI,CAAC,CAAA;KACvB,CAAC,OAAOiB,KAAK,EAAE;AACdR,MAAAA,OAAO,CACL,IAAIS,SAAS,CAACC,aAAa,CAACS,gBAAgB,EAAGX,KAAe,CAACY,OAAO,CAAC,CACxE,CAAA;MACD,OAAOF,MAAM,CAACY,IAAI,CAAC,CAAA;AACpB,KAAA;AACH,GAAA;AAEA,EAAA,SAASS,IAAIA,CACXjD,KAAuB,EACvBe,eAAiD,EAAA;AAEjD,IAAA,OAAOW,iBAAiB,CAAC1B,KAAK,EAAEe,eAAe,EAAEV,OAAO,IAAA,IAAA,GAAA,KAAA,CAAA,GAAPA,OAAO,CAAE4C,IAAI,EAAE,UAACjC,OAAO,EAAA;AAAA,MAAA,OACtE,IAAIkB,IAAI,CAACgB,UAAU,CAAC5C,MAAM,EAAEU,OAAO,CAAC,CAACoB,MAAM,CAACpC,KAAK,CAAC,CAAA;KACnD,CAAA,CAAA;AACH,GAAA;EAEA,OAAO;AAAC+B,IAAAA,QAAQ,EAARA,QAAQ;AAAEM,IAAAA,MAAM,EAANA,MAAM;AAAEE,IAAAA,YAAY,EAAZA,YAAY;AAAEU,IAAAA,IAAI,EAAJA,IAAAA;GAAK,CAAA;AAC/C;;;;"}
@@ -1,7 +0,0 @@
1
- import createFormatter from './createFormatter';
2
- /** @deprecated Switch to `createFormatter` */
3
- export default function createIntl(...args: Parameters<typeof createFormatter>): {
4
- formatDateTime: (value: number | Date, formatOrOptions?: string | import("./DateTimeFormatOptions").default | undefined) => string;
5
- formatNumber: (value: number | bigint, formatOrOptions?: string | import("@formatjs/ecma402-abstract/types/number").NumberFormatOptions | undefined) => string;
6
- formatRelativeTime: (date: number | Date, now?: number | Date | undefined) => string;
7
- };
@@ -1,14 +0,0 @@
1
- import createFormatter from './createFormatter.esm.js';
2
-
3
- /** @deprecated Switch to `createFormatter` */
4
- function createIntl() {
5
- var formatter = createFormatter.apply(void 0, arguments);
6
- return {
7
- formatDateTime: formatter.dateTime,
8
- formatNumber: formatter.number,
9
- formatRelativeTime: formatter.relativeTime
10
- };
11
- }
12
-
13
- export { createIntl as default };
14
- //# sourceMappingURL=createIntl.esm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createIntl.esm.js","sources":["../../src/core/createIntl.tsx"],"sourcesContent":["import createFormatter from './createFormatter';\n\n/** @deprecated Switch to `createFormatter` */\nexport default function createIntl(\n ...args: Parameters<typeof createFormatter>\n) {\n const formatter = createFormatter(...args);\n return {\n formatDateTime: formatter.dateTime,\n formatNumber: formatter.number,\n formatRelativeTime: formatter.relativeTime\n };\n}\n"],"names":["createIntl","formatter","createFormatter","apply","arguments","formatDateTime","dateTime","formatNumber","number","formatRelativeTime","relativeTime"],"mappings":";;AAEA;AACc,SAAUA,UAAUA,GACW;AAE3C,EAAA,IAAMC,SAAS,GAAGC,eAAe,CAAAC,KAAA,CAAA,KAAA,CAAA,EAAAC,SAAQ,CAAC,CAAA;EAC1C,OAAO;IACLC,cAAc,EAAEJ,SAAS,CAACK,QAAQ;IAClCC,YAAY,EAAEN,SAAS,CAACO,MAAM;IAC9BC,kBAAkB,EAAER,SAAS,CAACS,YAAAA;GAC/B,CAAA;AACH;;;;"}
@@ -1,37 +0,0 @@
1
- import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose, extends as _extends } from '../_virtual/_rollupPluginBabelHelpers.esm.js';
2
- import createTranslatorImpl from './createTranslatorImpl.esm.js';
3
- import { defaultGetMessageFallback, defaultOnError } from './defaults.esm.js';
4
-
5
- var _excluded = ["getMessageFallback", "messages", "namespace", "onError"];
6
- /**
7
- * Translates messages from the given namespace by using the ICU syntax.
8
- * See https://formatjs.io/docs/core-concepts/icu-syntax.
9
- *
10
- * If no namespace is provided, all available messages are returned.
11
- * The namespace can also indicate nesting by using a dot
12
- * (e.g. `namespace.Component`).
13
- */
14
- function createTranslator(_ref) {
15
- var _ref$getMessageFallba = _ref.getMessageFallback,
16
- getMessageFallback = _ref$getMessageFallba === void 0 ? defaultGetMessageFallback : _ref$getMessageFallba,
17
- messages = _ref.messages,
18
- namespace = _ref.namespace,
19
- _ref$onError = _ref.onError,
20
- onError = _ref$onError === void 0 ? defaultOnError : _ref$onError,
21
- rest = _objectWithoutPropertiesLoose(_ref, _excluded);
22
- // We have to wrap the actual function so the type inference for the optional
23
- // namespace works correctly. See https://stackoverflow.com/a/71529575/343045
24
- // The prefix ("!") is arbitrary.
25
- return createTranslatorImpl(_extends({}, rest, {
26
- onError: onError,
27
- getMessageFallback: getMessageFallback,
28
- messages: {
29
- '!': messages
30
- },
31
- // @ts-ignore
32
- namespace: namespace ? "!." + namespace : '!'
33
- }), '!');
34
- }
35
-
36
- export { createTranslator as default };
37
- //# sourceMappingURL=createTranslator.esm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createTranslator.esm.js","sources":["../../src/core/createTranslator.tsx"],"sourcesContent":["import Formats from './Formats';\nimport IntlConfig from './IntlConfig';\nimport TranslationValues, {\n RichTranslationValuesPlain\n} from './TranslationValues';\nimport createTranslatorImpl from './createTranslatorImpl';\nimport {defaultGetMessageFallback, defaultOnError} from './defaults';\nimport MessageKeys from './utils/MessageKeys';\nimport NamespaceKeys from './utils/NamespaceKeys';\nimport NestedKeyOf from './utils/NestedKeyOf';\nimport NestedValueOf from './utils/NestedValueOf';\n\n/**\n * Translates messages from the given namespace by using the ICU syntax.\n * See https://formatjs.io/docs/core-concepts/icu-syntax.\n *\n * If no namespace is provided, all available messages are returned.\n * The namespace can also indicate nesting by using a dot\n * (e.g. `namespace.Component`).\n */\nexport default function createTranslator<\n NestedKey extends NamespaceKeys<\n IntlMessages,\n NestedKeyOf<IntlMessages>\n > = never\n>({\n getMessageFallback = defaultGetMessageFallback,\n messages,\n namespace,\n onError = defaultOnError,\n ...rest\n}: Omit<IntlConfig<IntlMessages>, 'defaultTranslationValues' | 'messages'> & {\n messages: NonNullable<IntlConfig<IntlMessages>['messages']>;\n namespace?: NestedKey;\n}): // Explicitly defining the return type is necessary as TypeScript would get it wrong\n{\n // Default invocation\n <\n TargetKey extends MessageKeys<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >\n >\n >\n >(\n key: TargetKey,\n values?: TranslationValues,\n formats?: Partial<Formats>\n ): string;\n\n // `rich`\n rich<\n TargetKey extends MessageKeys<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >\n >\n >\n >(\n key: TargetKey,\n values?: RichTranslationValuesPlain,\n formats?: Partial<Formats>\n ): string;\n\n // `raw`\n raw<\n TargetKey extends MessageKeys<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >\n >\n >\n >(\n key: TargetKey\n ): any;\n} {\n // We have to wrap the actual function so the type inference for the optional\n // namespace works correctly. See https://stackoverflow.com/a/71529575/343045\n // The prefix (\"!\") is arbitrary.\n return createTranslatorImpl<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >(\n {\n ...rest,\n onError,\n getMessageFallback,\n messages: {'!': messages},\n // @ts-ignore\n namespace: namespace ? `!.${namespace}` : '!'\n },\n '!'\n );\n}\n"],"names":["createTranslator","_ref","_ref$getMessageFallba","getMessageFallback","defaultGetMessageFallback","messages","namespace","_ref$onError","onError","defaultOnError","rest","_objectWithoutPropertiesLoose","_excluded","createTranslatorImpl","_extends"],"mappings":";;;;;AAYA;;;;;;;AAOG;AACqB,SAAAA,gBAAgBA,CAAAC,IAAA,EAcvC;AAAA,EAAA,IAAAC,qBAAA,GAAAD,IAAA,CARCE,kBAAkB;AAAlBA,IAAAA,kBAAkB,GAAAD,qBAAA,KAAGE,KAAAA,CAAAA,GAAAA,yBAAyB,GAAAF,qBAAA;IAC9CG,QAAQ,GAAAJ,IAAA,CAARI,QAAQ;IACRC,SAAS,GAAAL,IAAA,CAATK,SAAS;IAAAC,YAAA,GAAAN,IAAA,CACTO,OAAO;AAAPA,IAAAA,OAAO,GAAAD,YAAA,KAAGE,KAAAA,CAAAA,GAAAA,cAAc,GAAAF,YAAA;AACrBG,IAAAA,IAAI,GAAAC,6BAAA,CAAAV,IAAA,EAAAW,SAAA,CAAA,CAAA;AAgEP;AACA;AACA;AACA,EAAA,OAAOC,oBAAoB,CAAAC,QAAA,CAAA,EAAA,EAKpBJ,IAAI,EAAA;AACPF,IAAAA,OAAO,EAAPA,OAAO;AACPL,IAAAA,kBAAkB,EAAlBA,kBAAkB;AAClBE,IAAAA,QAAQ,EAAE;AAAC,MAAA,GAAG,EAAEA,QAAAA;KAAS;AACzB;AACAC,IAAAA,SAAS,EAAEA,SAAS,GAAQA,IAAAA,GAAAA,SAAS,GAAK,GAAA;AAAG,GAAA,CAAA,EAE/C,GAAG,CACJ,CAAA;AACH;;;;"}
@@ -1,50 +0,0 @@
1
- import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose, extends as _extends } from '../_virtual/_rollupPluginBabelHelpers.esm.js';
2
- import IntlError, { IntlErrorCode } from './IntlError.esm.js';
3
- import createBaseTranslator from './createBaseTranslator.esm.js';
4
- import resolveNamespace from './resolveNamespace.esm.js';
5
-
6
- var _excluded = ["getMessageFallback", "messages", "namespace", "onError"];
7
- function createTranslatorImpl(_ref, namespacePrefix) {
8
- var getMessageFallback = _ref.getMessageFallback,
9
- messages = _ref.messages,
10
- namespace = _ref.namespace,
11
- onError = _ref.onError,
12
- rest = _objectWithoutPropertiesLoose(_ref, _excluded);
13
- // The `namespacePrefix` is part of the type system.
14
- // See the comment in the function invocation.
15
- messages = messages[namespacePrefix];
16
- namespace = resolveNamespace(namespace, namespacePrefix);
17
- var translator = createBaseTranslator(_extends({}, rest, {
18
- onError: onError,
19
- getMessageFallback: getMessageFallback,
20
- messages: messages,
21
- namespace: namespace
22
- }));
23
- var originalRich = translator.rich;
24
- function base() {
25
- return translator.apply(void 0, arguments);
26
- }
27
- // Augment `t.rich` to return plain strings
28
- base.rich = function (key, /** Key value pairs for values to interpolate into the message. */
29
- values, formats) {
30
- // `chunks` is returned as a string when no React element
31
- // is used, therefore it's safe to cast this type.
32
- var result = originalRich(key, values, formats);
33
- // When only string chunks are provided to the parser, only strings should be returned here.
34
- if (typeof result !== 'string') {
35
- var error = new IntlError(IntlErrorCode.FORMATTING_ERROR, process.env.NODE_ENV !== 'production' ? "`createTranslator` only accepts functions for rich text formatting that receive and return strings.\n\nE.g. t.rich('rich', {b: (chunks) => `<b>${chunks}</b>`})" : undefined);
36
- onError(error);
37
- return getMessageFallback({
38
- error: error,
39
- key: key,
40
- namespace: namespace
41
- });
42
- }
43
- return result;
44
- };
45
- base.raw = translator.raw;
46
- return base;
47
- }
48
-
49
- export { createTranslatorImpl as default };
50
- //# sourceMappingURL=createTranslatorImpl.esm.js.map