use-intl 2.22.0 → 2.22.2

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 (298) hide show
  1. package/README.md +1 -1
  2. package/_IntlProvider.d.ts +1 -0
  3. package/_useLocale.d.ts +1 -0
  4. package/core.d.ts +1 -0
  5. package/dist/_IntlProvider.js +7 -0
  6. package/dist/_useLocale.js +7 -0
  7. package/dist/core.js +7 -0
  8. package/dist/development/IntlContext-b5cc6be8.js +8 -0
  9. package/dist/development/_IntlProvider.js +53 -0
  10. package/dist/development/_useLocale-321e619f.js +19 -0
  11. package/dist/development/_useLocale.js +11 -0
  12. package/dist/development/core.js +66 -0
  13. package/dist/development/createFormatter-4848f6c8.js +453 -0
  14. package/dist/development/index.js +28 -0
  15. package/dist/development/initializeConfig-0a0b87a7.js +120 -0
  16. package/dist/development/react.js +145 -0
  17. package/dist/esm/IntlContext-381f3ce4.js +1 -0
  18. package/dist/esm/_IntlProvider.js +1 -0
  19. package/dist/esm/_useLocale-89b32eb9.js +1 -0
  20. package/dist/esm/_useLocale.js +1 -0
  21. package/dist/esm/core.js +1 -0
  22. package/dist/esm/createFormatter-c871a8ce.js +1 -0
  23. package/dist/esm/index.js +1 -0
  24. package/dist/esm/initializeConfig-29e7ba4c.js +1 -0
  25. package/dist/esm/react.js +1 -0
  26. package/dist/index.js +3 -4
  27. package/dist/production/IntlContext-381f3ce4.js +1 -0
  28. package/dist/production/_IntlProvider.js +1 -0
  29. package/dist/production/_useLocale-8e23751a.js +1 -0
  30. package/dist/production/_useLocale.js +1 -0
  31. package/dist/production/core.js +1 -0
  32. package/dist/production/createFormatter-7a8c6f36.js +1 -0
  33. package/dist/production/index.js +1 -0
  34. package/dist/production/initializeConfig-984a566d.js +1 -0
  35. package/dist/production/react.js +1 -0
  36. package/dist/react.js +7 -0
  37. package/dist/types/src/_IntlProvider.d.ts +1 -0
  38. package/dist/types/src/_useLocale.d.ts +1 -0
  39. package/dist/{src → types/src}/core/IntlConfig.d.ts +1 -1
  40. package/dist/{core → types/src/core}/TranslationValues.d.ts +6 -5
  41. package/dist/{src → types/src}/core/createBaseTranslator.d.ts +5 -9
  42. package/dist/{src → types/src}/core/createTranslator.d.ts +16 -4
  43. package/dist/types/src/core/createTranslatorImpl.d.ts +16 -0
  44. package/dist/{core → types/src/core}/index.d.ts +14 -9
  45. package/dist/types/src/core/initializeConfig.d.ts +14 -0
  46. package/dist/types/src/core.d.ts +1 -0
  47. package/dist/types/src/react/IntlProvider.d.ts +7 -0
  48. package/dist/{src → types/src}/react/index.d.ts +0 -1
  49. package/dist/types/src/react/useMessages.d.ts +2 -0
  50. package/dist/{src → types/src}/react/useTranslations.d.ts +10 -1
  51. package/dist/{src → types/src}/react/useTranslationsImpl.d.ts +2 -1
  52. package/dist/types/src/react.d.ts +1 -0
  53. package/dist/types/test/core/createFormatter.test.d.ts +1 -0
  54. package/dist/types/test/core/createTranslator.test.d.ts +1 -0
  55. package/dist/types/test/react/IntlProvider.test.d.ts +1 -0
  56. package/dist/types/test/react/useFormatter.test.d.ts +1 -0
  57. package/dist/types/test/react/useLocale.test.d.ts +1 -0
  58. package/dist/types/test/react/useMessages.test.d.ts +1 -0
  59. package/dist/types/test/react/useNow.test.d.ts +1 -0
  60. package/dist/types/test/react/useTimeZone.test.d.ts +1 -0
  61. package/dist/types/test/react/useTranslations.test.d.ts +1 -0
  62. package/dist/types/test/setup.d.ts +1 -0
  63. package/package.json +38 -21
  64. package/react.d.ts +1 -0
  65. package/dist/_virtual/use-intl.esm.js +0 -102
  66. package/dist/_virtual/use-intl.esm.js.map +0 -1
  67. package/dist/core/AbstractIntlMessages.d.ts +0 -9
  68. package/dist/core/DateTimeFormatOptions.d.ts +0 -73
  69. package/dist/core/Formats.d.ts +0 -8
  70. package/dist/core/IntlConfig.d.ts +0 -54
  71. package/dist/core/IntlError.d.ts +0 -14
  72. package/dist/core/MessageFormatCache.d.ts +0 -5
  73. package/dist/core/NumberFormatOptions.d.ts +0 -2
  74. package/dist/core/RelativeTimeFormatOptions.d.ts +0 -5
  75. package/dist/core/TimeZone.d.ts +0 -2
  76. package/dist/core/convertFormatsToIntlMessageFormat.d.ts +0 -11
  77. package/dist/core/createBaseTranslator.d.ts +0 -26
  78. package/dist/core/createFormatter.d.ts +0 -20
  79. package/dist/core/createIntl.d.ts +0 -7
  80. package/dist/core/createTranslator.d.ts +0 -48
  81. package/dist/core/createTranslatorImpl.d.ts +0 -14
  82. package/dist/core/defaults.d.ts +0 -11
  83. package/dist/core/resolveNamespace.d.ts +0 -5
  84. package/dist/core/use-intl.esm.js +0 -34
  85. package/dist/core/use-intl.esm.js.map +0 -1
  86. package/dist/core/use-intl.esm10.js +0 -37
  87. package/dist/core/use-intl.esm10.js.map +0 -1
  88. package/dist/core/use-intl.esm2.js +0 -36
  89. package/dist/core/use-intl.esm2.js.map +0 -1
  90. package/dist/core/use-intl.esm3.js +0 -161
  91. package/dist/core/use-intl.esm3.js.map +0 -1
  92. package/dist/core/use-intl.esm4.js +0 -14
  93. package/dist/core/use-intl.esm4.js.map +0 -1
  94. package/dist/core/use-intl.esm5.js +0 -53
  95. package/dist/core/use-intl.esm5.js.map +0 -1
  96. package/dist/core/use-intl.esm6.js +0 -15
  97. package/dist/core/use-intl.esm6.js.map +0 -1
  98. package/dist/core/use-intl.esm7.js +0 -10
  99. package/dist/core/use-intl.esm7.js.map +0 -1
  100. package/dist/core/use-intl.esm8.js +0 -200
  101. package/dist/core/use-intl.esm8.js.map +0 -1
  102. package/dist/core/use-intl.esm9.js +0 -28
  103. package/dist/core/use-intl.esm9.js.map +0 -1
  104. package/dist/core/utils/MessageKeys.d.ts +0 -5
  105. package/dist/core/utils/NamespaceKeys.d.ts +0 -5
  106. package/dist/core/utils/NestedKeyOf.d.ts +0 -4
  107. package/dist/core/utils/NestedValueOf.d.ts +0 -2
  108. package/dist/core/validateMessages.d.ts +0 -3
  109. package/dist/index.d.ts +0 -2
  110. package/dist/react/IntlContext.d.ts +0 -13
  111. package/dist/react/IntlProvider.d.ts +0 -7
  112. package/dist/react/getInitializedConfig.d.ts +0 -13
  113. package/dist/react/index.d.ts +0 -8
  114. package/dist/react/use-intl.esm.js +0 -22
  115. package/dist/react/use-intl.esm.js.map +0 -1
  116. package/dist/react/use-intl.esm10.js +0 -29
  117. package/dist/react/use-intl.esm10.js.map +0 -1
  118. package/dist/react/use-intl.esm11.js +0 -13
  119. package/dist/react/use-intl.esm11.js.map +0 -1
  120. package/dist/react/use-intl.esm12.js +0 -43
  121. package/dist/react/use-intl.esm12.js.map +0 -1
  122. package/dist/react/use-intl.esm2.js +0 -26
  123. package/dist/react/use-intl.esm2.js.map +0 -1
  124. package/dist/react/use-intl.esm3.js +0 -8
  125. package/dist/react/use-intl.esm3.js.map +0 -1
  126. package/dist/react/use-intl.esm4.js +0 -45
  127. package/dist/react/use-intl.esm4.js.map +0 -1
  128. package/dist/react/use-intl.esm5.js +0 -8
  129. package/dist/react/use-intl.esm5.js.map +0 -1
  130. package/dist/react/use-intl.esm6.js +0 -8
  131. package/dist/react/use-intl.esm6.js.map +0 -1
  132. package/dist/react/use-intl.esm7.js +0 -24
  133. package/dist/react/use-intl.esm7.js.map +0 -1
  134. package/dist/react/use-intl.esm8.js +0 -30
  135. package/dist/react/use-intl.esm8.js.map +0 -1
  136. package/dist/react/use-intl.esm9.js +0 -6
  137. package/dist/react/use-intl.esm9.js.map +0 -1
  138. package/dist/react/useFormatter.d.ts +0 -6
  139. package/dist/react/useIntl.d.ts +0 -6
  140. package/dist/react/useIntlContext.d.ts +0 -10
  141. package/dist/react/useLocale.d.ts +0 -1
  142. package/dist/react/useMessages.d.ts +0 -1
  143. package/dist/react/useNow.d.ts +0 -23
  144. package/dist/react/useTimeZone.d.ts +0 -1
  145. package/dist/react/useTranslations.d.ts +0 -44
  146. package/dist/react/useTranslationsImpl.d.ts +0 -8
  147. package/dist/src/core/AbstractIntlMessages.js +0 -2
  148. package/dist/src/core/AbstractIntlMessages.js.map +0 -1
  149. package/dist/src/core/DateTimeFormatOptions.js +0 -3
  150. package/dist/src/core/DateTimeFormatOptions.js.map +0 -1
  151. package/dist/src/core/Formats.js +0 -2
  152. package/dist/src/core/Formats.js.map +0 -1
  153. package/dist/src/core/IntlConfig.js +0 -2
  154. package/dist/src/core/IntlConfig.js.map +0 -1
  155. package/dist/src/core/IntlError.js +0 -24
  156. package/dist/src/core/IntlError.js.map +0 -1
  157. package/dist/src/core/MessageFormatCache.js +0 -2
  158. package/dist/src/core/MessageFormatCache.js.map +0 -1
  159. package/dist/src/core/NumberFormatOptions.js +0 -2
  160. package/dist/src/core/NumberFormatOptions.js.map +0 -1
  161. package/dist/src/core/RelativeTimeFormatOptions.js +0 -2
  162. package/dist/src/core/RelativeTimeFormatOptions.js.map +0 -1
  163. package/dist/src/core/TimeZone.js +0 -2
  164. package/dist/src/core/TimeZone.js.map +0 -1
  165. package/dist/src/core/TranslationValues.d.ts +0 -5
  166. package/dist/src/core/TranslationValues.js +0 -2
  167. package/dist/src/core/TranslationValues.js.map +0 -1
  168. package/dist/src/core/convertFormatsToIntlMessageFormat.js +0 -47
  169. package/dist/src/core/convertFormatsToIntlMessageFormat.js.map +0 -1
  170. package/dist/src/core/createBaseTranslator.js +0 -218
  171. package/dist/src/core/createBaseTranslator.js.map +0 -1
  172. package/dist/src/core/createFormatter.js +0 -163
  173. package/dist/src/core/createFormatter.js.map +0 -1
  174. package/dist/src/core/createIntl.d.ts +0 -7
  175. package/dist/src/core/createIntl.js +0 -11
  176. package/dist/src/core/createIntl.js.map +0 -1
  177. package/dist/src/core/createTranslator.js +0 -23
  178. package/dist/src/core/createTranslator.js.map +0 -1
  179. package/dist/src/core/createTranslatorImpl.d.ts +0 -14
  180. package/dist/src/core/createTranslatorImpl.js +0 -43
  181. package/dist/src/core/createTranslatorImpl.js.map +0 -1
  182. package/dist/src/core/defaults.js +0 -11
  183. package/dist/src/core/defaults.js.map +0 -1
  184. package/dist/src/core/index.d.ts +0 -9
  185. package/dist/src/core/index.js +0 -6
  186. package/dist/src/core/index.js.map +0 -1
  187. package/dist/src/core/resolveNamespace.js +0 -10
  188. package/dist/src/core/resolveNamespace.js.map +0 -1
  189. package/dist/src/core/utils/MessageKeys.js +0 -2
  190. package/dist/src/core/utils/MessageKeys.js.map +0 -1
  191. package/dist/src/core/utils/NamespaceKeys.js +0 -2
  192. package/dist/src/core/utils/NamespaceKeys.js.map +0 -1
  193. package/dist/src/core/utils/NestedKeyOf.js +0 -2
  194. package/dist/src/core/utils/NestedKeyOf.js.map +0 -1
  195. package/dist/src/core/utils/NestedValueOf.js +0 -2
  196. package/dist/src/core/utils/NestedValueOf.js.map +0 -1
  197. package/dist/src/core/validateMessages.js +0 -56
  198. package/dist/src/core/validateMessages.js.map +0 -1
  199. package/dist/src/index.js +0 -3
  200. package/dist/src/index.js.map +0 -1
  201. package/dist/src/react/IntlContext.js +0 -4
  202. package/dist/src/react/IntlContext.js.map +0 -1
  203. package/dist/src/react/IntlProvider.d.ts +0 -7
  204. package/dist/src/react/IntlProvider.js +0 -11
  205. package/dist/src/react/IntlProvider.js.map +0 -1
  206. package/dist/src/react/getInitializedConfig.d.ts +0 -13
  207. package/dist/src/react/getInitializedConfig.js +0 -21
  208. package/dist/src/react/getInitializedConfig.js.map +0 -1
  209. package/dist/src/react/index.js +0 -10
  210. package/dist/src/react/index.js.map +0 -1
  211. package/dist/src/react/useFormatter.js +0 -14
  212. package/dist/src/react/useFormatter.js.map +0 -1
  213. package/dist/src/react/useIntl.d.ts +0 -6
  214. package/dist/src/react/useIntl.js +0 -20
  215. package/dist/src/react/useIntl.js.map +0 -1
  216. package/dist/src/react/useIntlContext.js +0 -12
  217. package/dist/src/react/useIntlContext.js.map +0 -1
  218. package/dist/src/react/useLocale.js +0 -5
  219. package/dist/src/react/useLocale.js.map +0 -1
  220. package/dist/src/react/useMessages.d.ts +0 -1
  221. package/dist/src/react/useMessages.js +0 -5
  222. package/dist/src/react/useMessages.js.map +0 -1
  223. package/dist/src/react/useNow.js +0 -40
  224. package/dist/src/react/useNow.js.map +0 -1
  225. package/dist/src/react/useTimeZone.js +0 -5
  226. package/dist/src/react/useTimeZone.js.map +0 -1
  227. package/dist/src/react/useTranslations.js +0 -21
  228. package/dist/src/react/useTranslations.js.map +0 -1
  229. package/dist/src/react/useTranslationsImpl.js +0 -35
  230. package/dist/src/react/useTranslationsImpl.js.map +0 -1
  231. package/dist/use-intl.cjs.development.js +0 -863
  232. package/dist/use-intl.cjs.development.js.map +0 -1
  233. package/dist/use-intl.cjs.production.min.js +0 -2
  234. package/dist/use-intl.cjs.production.min.js.map +0 -1
  235. package/dist/use-intl.esm.js +0 -13
  236. package/dist/use-intl.esm.js.map +0 -1
  237. package/src/core/AbstractIntlMessages.tsx +0 -10
  238. package/src/core/DateTimeFormatOptions.tsx +0 -130
  239. package/src/core/Formats.tsx +0 -10
  240. package/src/core/IntlConfig.tsx +0 -59
  241. package/src/core/IntlError.tsx +0 -27
  242. package/src/core/MessageFormatCache.tsx +0 -10
  243. package/src/core/NumberFormatOptions.tsx +0 -3
  244. package/src/core/RelativeTimeFormatOptions.tsx +0 -6
  245. package/src/core/TimeZone.tsx +0 -426
  246. package/src/core/TranslationValues.tsx +0 -22
  247. package/src/core/convertFormatsToIntlMessageFormat.tsx +0 -63
  248. package/src/core/createBaseTranslator.tsx +0 -352
  249. package/src/core/createFormatter.tsx +0 -242
  250. package/src/core/createIntl.tsx +0 -13
  251. package/src/core/createTranslator.tsx +0 -111
  252. package/src/core/createTranslatorImpl.tsx +0 -87
  253. package/src/core/defaults.tsx +0 -18
  254. package/src/core/index.tsx +0 -14
  255. package/src/core/resolveNamespace.tsx +0 -12
  256. package/src/core/utils/MessageKeys.tsx +0 -9
  257. package/src/core/utils/NamespaceKeys.tsx +0 -9
  258. package/src/core/utils/NestedKeyOf.tsx +0 -9
  259. package/src/core/utils/NestedValueOf.tsx +0 -12
  260. package/src/core/validateMessages.tsx +0 -77
  261. package/src/index.tsx +0 -2
  262. package/src/react/IntlContext.tsx +0 -12
  263. package/src/react/IntlProvider.tsx +0 -23
  264. package/src/react/getInitializedConfig.tsx +0 -29
  265. package/src/react/index.tsx +0 -10
  266. package/src/react/useFormatter.tsx +0 -19
  267. package/src/react/useIntl.tsx +0 -29
  268. package/src/react/useIntlContext.tsx +0 -16
  269. package/src/react/useLocale.tsx +0 -5
  270. package/src/react/useMessages.tsx +0 -5
  271. package/src/react/useNow.tsx +0 -49
  272. package/src/react/useTimeZone.tsx +0 -5
  273. package/src/react/useTranslations.tsx +0 -103
  274. package/src/react/useTranslationsImpl.tsx +0 -61
  275. /package/dist/{src → types/src}/core/AbstractIntlMessages.d.ts +0 -0
  276. /package/dist/{src → types/src}/core/DateTimeFormatOptions.d.ts +0 -0
  277. /package/dist/{src → types/src}/core/Formats.d.ts +0 -0
  278. /package/dist/{src → types/src}/core/IntlError.d.ts +0 -0
  279. /package/dist/{src → types/src}/core/MessageFormatCache.d.ts +0 -0
  280. /package/dist/{src → types/src}/core/NumberFormatOptions.d.ts +0 -0
  281. /package/dist/{src → types/src}/core/RelativeTimeFormatOptions.d.ts +0 -0
  282. /package/dist/{src → types/src}/core/TimeZone.d.ts +0 -0
  283. /package/dist/{src → types/src}/core/convertFormatsToIntlMessageFormat.d.ts +0 -0
  284. /package/dist/{src → types/src}/core/createFormatter.d.ts +0 -0
  285. /package/dist/{src → types/src}/core/defaults.d.ts +0 -0
  286. /package/dist/{src → types/src}/core/resolveNamespace.d.ts +0 -0
  287. /package/dist/{src → types/src}/core/utils/MessageKeys.d.ts +0 -0
  288. /package/dist/{src → types/src}/core/utils/NamespaceKeys.d.ts +0 -0
  289. /package/dist/{src → types/src}/core/utils/NestedKeyOf.d.ts +0 -0
  290. /package/dist/{src → types/src}/core/utils/NestedValueOf.d.ts +0 -0
  291. /package/dist/{src → types/src}/core/validateMessages.d.ts +0 -0
  292. /package/dist/{src → types/src}/index.d.ts +0 -0
  293. /package/dist/{src → types/src}/react/IntlContext.d.ts +0 -0
  294. /package/dist/{src → types/src}/react/useFormatter.d.ts +0 -0
  295. /package/dist/{src → types/src}/react/useIntlContext.d.ts +0 -0
  296. /package/dist/{src → types/src}/react/useLocale.d.ts +0 -0
  297. /package/dist/{src → types/src}/react/useNow.d.ts +0 -0
  298. /package/dist/{src → types/src}/react/useTimeZone.d.ts +0 -0
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-intl.esm.js","sources":["../../src/core/IntlError.tsx"],"sourcesContent":["export enum IntlErrorCode {\n MISSING_MESSAGE = 'MISSING_MESSAGE',\n MISSING_FORMAT = 'MISSING_FORMAT',\n ENVIRONMENT_FALLBACK = 'ENVIRONMENT_FALLBACK',\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,cAQX;AARD,CAAA,UAAYA,aAAa,EAAA;AACvBA,EAAAA,aAAA,CAAA,iBAAA,CAAA,GAAA,iBAAmC,CAAA;AACnCA,EAAAA,aAAA,CAAA,gBAAA,CAAA,GAAA,gBAAiC,CAAA;AACjCA,EAAAA,aAAA,CAAA,sBAAA,CAAA,GAAA,sBAA6C,CAAA;AAC7CA,EAAAA,aAAA,CAAA,mBAAA,CAAA,GAAA,mBAAuC,CAAA;AACvCA,EAAAA,aAAA,CAAA,iBAAA,CAAA,GAAA,iBAAmC,CAAA;AACnCA,EAAAA,aAAA,CAAA,aAAA,CAAA,GAAA,aAA2B,CAAA;AAC3BA,EAAAA,aAAA,CAAA,kBAAA,CAAA,GAAA,kBAAqC,CAAA;AACvC,CAAC,EARWA,aAAa,KAAbA,aAAa,GAQxB,EAAA,CAAA,CAAA,CAAA;AAEoBC,IAAAA,SAAU,0BAAAC,MAAA,EAAA;EAAAC,cAAA,CAAAF,SAAA,EAAAC,MAAA,CAAA,CAAA;AAI7B,EAAA,SAAAD,SAAYG,CAAAA,IAAmB,EAAEC,eAAwB,EAAA;AAAA,IAAA,IAAAC,KAAA,CAAA;IACvD,IAAIC,OAAO,GAAWH,IAAI,CAAA;AAC1B,IAAA,IAAIC,eAAe,EAAE;MACnBE,OAAO,IAAI,IAAI,GAAGF,eAAe,CAAA;AAClC,KAAA;AACDC,IAAAA,KAAA,GAAAJ,MAAA,CAAAM,IAAA,CAAA,IAAA,EAAMD,OAAO,CAAC,IAAA,IAAA,CAAA;AAACD,IAAAA,KAAA,CARDF,IAAI,GAAA,KAAA,CAAA,CAAA;AAAAE,IAAAA,KAAA,CACJD,eAAe,GAAA,KAAA,CAAA,CAAA;IAS7BC,KAAA,CAAKF,IAAI,GAAGA,IAAI,CAAA;AAChB,IAAA,IAAIC,eAAe,EAAE;MACnBC,KAAA,CAAKD,eAAe,GAAGA,eAAe,CAAA;AACvC,KAAA;AAAA,IAAA,OAAAC,KAAA,CAAA;AACH,GAAA;AAAC,EAAA,OAAAL,SAAA,CAAA;AAAA,CAAAQ,eAAAA,gBAAA,CAfoCC,KAAK,CAAA;;;;"}
@@ -1,37 +0,0 @@
1
- import { extends as _extends } from '../_virtual/use-intl.esm.js';
2
- import IntlMessageFormat from 'intl-messageformat';
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=use-intl.esm10.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-intl.esm10.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","defaultDateFormats","mfTimeDefaults","time","defaultTimeFormats"],"mappings":";;;AAMA,SAASA,oBAAoBA,CAC3BC,OAA0D,EAC1DC,QAAkB,EAAA;AAElB,EAAA,IAAI,CAACD,OAAO,EAAE,OAAOA,OAAO,CAAA;AAE5B;AACA;AACA,EAAA,OAAOE,MAAM,CAACC,IAAI,CAACH,OAAO,CAAC,CAACI,MAAM,CAChC,UAACC,GAA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 -1,36 +0,0 @@
1
- import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose, extends as _extends } from '../_virtual/use-intl.esm.js';
2
- import createTranslatorImpl from './use-intl.esm5.js';
3
- import { defaultGetMessageFallback, defaultOnError } from './use-intl.esm6.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
- namespace: namespace ? "!." + namespace : '!'
32
- }), '!');
33
- }
34
-
35
- export { createTranslator as default };
36
- //# sourceMappingURL=use-intl.esm2.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-intl.esm2.js","sources":["../../src/core/createTranslator.tsx"],"sourcesContent":["import Formats from './Formats';\nimport IntlConfig from './IntlConfig';\nimport TranslationValues from './TranslationValues';\nimport createTranslatorImpl, {\n CoreRichTranslationValues\n} 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?: CoreRichTranslationValues,\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 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;AACzBC,IAAAA,SAAS,EAAEA,SAAS,GAAQA,IAAAA,GAAAA,SAAS,GAAK,GAAA;AAAG,GAAA,CAAA,EAE/C,GAAG,CACJ,CAAA;AACH;;;;"}
@@ -1,161 +0,0 @@
1
- import { extends as _extends } from '../_virtual/use-intl.esm.js';
2
- import IntlError, { IntlErrorCode } from './use-intl.esm.js';
3
- import { defaultOnError } from './use-intl.esm6.js';
4
-
5
- var SECOND = 1;
6
- var MINUTE = SECOND * 60;
7
- var HOUR = MINUTE * 60;
8
- var DAY = HOUR * 24;
9
- var WEEK = DAY * 7;
10
- var MONTH = DAY * (365 / 12); // Approximation
11
- var QUARTER = MONTH * 3;
12
- var YEAR = DAY * 365;
13
- var UNIT_SECONDS = {
14
- second: SECOND,
15
- seconds: SECOND,
16
- minute: MINUTE,
17
- minutes: MINUTE,
18
- hour: HOUR,
19
- hours: HOUR,
20
- day: DAY,
21
- days: DAY,
22
- week: WEEK,
23
- weeks: WEEK,
24
- month: MONTH,
25
- months: MONTH,
26
- quarter: QUARTER,
27
- quarters: QUARTER,
28
- year: YEAR,
29
- years: YEAR
30
- };
31
- function resolveRelativeTimeUnit(seconds) {
32
- var absValue = Math.abs(seconds);
33
- if (absValue < MINUTE) {
34
- return 'second';
35
- } else if (absValue < HOUR) {
36
- return 'minute';
37
- } else if (absValue < DAY) {
38
- return 'hour';
39
- } else if (absValue < WEEK) {
40
- return 'day';
41
- } else if (absValue < MONTH) {
42
- return 'week';
43
- } else if (absValue < YEAR) {
44
- return 'month';
45
- }
46
- return 'year';
47
- }
48
- function calculateRelativeTimeValue(seconds, unit) {
49
- // We have to round the resulting values, as `Intl.RelativeTimeFormat`
50
- // will include fractions like '2.1 hours ago'.
51
- return Math.round(seconds / UNIT_SECONDS[unit]);
52
- }
53
- function createFormatter(_ref) {
54
- var formats = _ref.formats,
55
- locale = _ref.locale,
56
- globalNow = _ref.now,
57
- _ref$onError = _ref.onError,
58
- onError = _ref$onError === void 0 ? defaultOnError : _ref$onError,
59
- globalTimeZone = _ref.timeZone;
60
- function resolveFormatOrOptions(typeFormats, formatOrOptions) {
61
- var options;
62
- if (typeof formatOrOptions === 'string') {
63
- var formatName = formatOrOptions;
64
- options = typeFormats == null ? void 0 : typeFormats[formatName];
65
- if (!options) {
66
- 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);
67
- onError(error);
68
- throw error;
69
- }
70
- } else {
71
- options = formatOrOptions;
72
- }
73
- return options;
74
- }
75
- function getFormattedValue(value, formatOrOptions, typeFormats, formatter) {
76
- var options;
77
- try {
78
- options = resolveFormatOrOptions(typeFormats, formatOrOptions);
79
- } catch (error) {
80
- return String(value);
81
- }
82
- try {
83
- return formatter(options);
84
- } catch (error) {
85
- onError(new IntlError(IntlErrorCode.FORMATTING_ERROR, error.message));
86
- return String(value);
87
- }
88
- }
89
- function dateTime( /** If a number is supplied, this is interpreted as a UTC timestamp. */
90
- value,
91
- /** If a time zone is supplied, the `value` is converted to that time zone.
92
- * Otherwise the user time zone will be used. */
93
- formatOrOptions) {
94
- return getFormattedValue(value, formatOrOptions, formats == null ? void 0 : formats.dateTime, function (options) {
95
- var _options;
96
- if (!((_options = options) != null && _options.timeZone)) {
97
- if (globalTimeZone) {
98
- options = _extends({}, options, {
99
- timeZone: globalTimeZone
100
- });
101
- } else {
102
- onError(new IntlError(IntlErrorCode.ENVIRONMENT_FALLBACK, process.env.NODE_ENV !== 'production' ? "The `timeZone` parameter wasn't provided and there is no global default configured. Consider adding a global default to avoid markup mismatches caused by environment differences. Learn more: https://next-intl-docs.vercel.app/docs/configuration#time-zone" : undefined));
103
- }
104
- }
105
- return new Intl.DateTimeFormat(locale, options).format(value);
106
- });
107
- }
108
- function number(value, formatOrOptions) {
109
- return getFormattedValue(value, formatOrOptions, formats == null ? void 0 : formats.number, function (options) {
110
- return new Intl.NumberFormat(locale, options).format(value);
111
- });
112
- }
113
- function getGlobalNow() {
114
- if (globalNow) {
115
- return globalNow;
116
- } else {
117
- onError(new IntlError(IntlErrorCode.ENVIRONMENT_FALLBACK, process.env.NODE_ENV !== 'production' ? "The `now` parameter wasn't provided and there is no global default configured. Consider adding a global default to avoid markup mismatches caused by environment differences. Learn more: https://next-intl-docs.vercel.app/docs/configuration#now" : undefined));
118
- return new Date();
119
- }
120
- }
121
- function extractNowDate(nowOrOptions) {
122
- if (nowOrOptions instanceof Date || typeof nowOrOptions === 'number') {
123
- return new Date(nowOrOptions);
124
- }
125
- if ((nowOrOptions == null ? void 0 : nowOrOptions.now) !== undefined) {
126
- return new Date(nowOrOptions.now);
127
- }
128
- return getGlobalNow();
129
- }
130
- function relativeTime( /** The date time that needs to be formatted. */
131
- date, /** The reference point in time to which `date` will be formatted in relation to. */
132
- nowOrOptions) {
133
- try {
134
- var dateDate = new Date(date);
135
- var nowDate = extractNowDate(nowOrOptions);
136
- var seconds = (dateDate.getTime() - nowDate.getTime()) / 1000;
137
- var unit = typeof nowOrOptions === 'number' || nowOrOptions instanceof Date || (nowOrOptions == null ? void 0 : nowOrOptions.unit) === undefined ? resolveRelativeTimeUnit(seconds) : nowOrOptions.unit;
138
- var value = calculateRelativeTimeValue(seconds, unit);
139
- return new Intl.RelativeTimeFormat(locale, {
140
- numeric: 'auto'
141
- }).format(value, unit);
142
- } catch (error) {
143
- onError(new IntlError(IntlErrorCode.FORMATTING_ERROR, error.message));
144
- return String(date);
145
- }
146
- }
147
- function list(value, formatOrOptions) {
148
- return getFormattedValue(value, formatOrOptions, formats == null ? void 0 : formats.list, function (options) {
149
- return new Intl.ListFormat(locale, options).format(value);
150
- });
151
- }
152
- return {
153
- dateTime: dateTime,
154
- number: number,
155
- relativeTime: relativeTime,
156
- list: list
157
- };
158
- }
159
-
160
- export { createFormatter as default };
161
- //# sourceMappingURL=use-intl.esm3.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-intl.esm3.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 RelativeTimeFormatOptions from './RelativeTimeFormatOptions';\nimport TimeZone from './TimeZone';\nimport {defaultOnError} from './defaults';\n\nconst SECOND = 1;\nconst MINUTE = SECOND * 60;\nconst HOUR = MINUTE * 60;\nconst DAY = HOUR * 24;\nconst WEEK = DAY * 7;\nconst MONTH = DAY * (365 / 12); // Approximation\nconst QUARTER = MONTH * 3;\nconst YEAR = DAY * 365;\n\nconst UNIT_SECONDS: Record<Intl.RelativeTimeFormatUnit, number> = {\n second: SECOND,\n seconds: SECOND,\n minute: MINUTE,\n minutes: MINUTE,\n hour: HOUR,\n hours: HOUR,\n day: DAY,\n days: DAY,\n week: WEEK,\n weeks: WEEK,\n month: MONTH,\n months: MONTH,\n quarter: QUARTER,\n quarters: QUARTER,\n year: YEAR,\n years: YEAR\n} as const;\n\nfunction resolveRelativeTimeUnit(seconds: number) {\n const absValue = Math.abs(seconds);\n\n if (absValue < MINUTE) {\n return 'second';\n } else if (absValue < HOUR) {\n return 'minute';\n } else if (absValue < DAY) {\n return 'hour';\n } else if (absValue < WEEK) {\n return 'day';\n } else if (absValue < MONTH) {\n return 'week';\n } else if (absValue < YEAR) {\n return 'month';\n }\n return 'year';\n}\n\nfunction calculateRelativeTimeValue(\n seconds: number,\n 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 return Math.round(seconds / UNIT_SECONDS[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: globalTimeZone\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 (!options?.timeZone) {\n if (globalTimeZone) {\n options = {...options, timeZone: globalTimeZone};\n } else {\n onError(\n new IntlError(\n IntlErrorCode.ENVIRONMENT_FALLBACK,\n process.env.NODE_ENV !== 'production'\n ? `The \\`timeZone\\` parameter wasn't provided and there is no global default configured. Consider adding a global default to avoid markup mismatches caused by environment differences. Learn more: https://next-intl-docs.vercel.app/docs/configuration#time-zone`\n : undefined\n )\n );\n }\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 getGlobalNow() {\n if (globalNow) {\n return globalNow;\n } else {\n onError(\n new IntlError(\n IntlErrorCode.ENVIRONMENT_FALLBACK,\n process.env.NODE_ENV !== 'production'\n ? `The \\`now\\` parameter wasn't provided and there is no global default configured. Consider adding a global default to avoid markup mismatches caused by environment differences. Learn more: https://next-intl-docs.vercel.app/docs/configuration#now`\n : undefined\n )\n );\n return new Date();\n }\n }\n\n function extractNowDate(\n nowOrOptions?: RelativeTimeFormatOptions['now'] | RelativeTimeFormatOptions\n ) {\n if (nowOrOptions instanceof Date || typeof nowOrOptions === 'number') {\n return new Date(nowOrOptions);\n }\n if (nowOrOptions?.now !== undefined) {\n return new Date(nowOrOptions.now);\n }\n return getGlobalNow();\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 nowOrOptions?: RelativeTimeFormatOptions['now'] | RelativeTimeFormatOptions\n ) {\n try {\n const dateDate = new Date(date);\n const nowDate = extractNowDate(nowOrOptions);\n const seconds = (dateDate.getTime() - nowDate.getTime()) / 1000;\n\n const unit =\n typeof nowOrOptions === 'number' ||\n nowOrOptions instanceof Date ||\n nowOrOptions?.unit === undefined\n ? resolveRelativeTimeUnit(seconds)\n : nowOrOptions.unit;\n\n const value = calculateRelativeTimeValue(seconds, unit);\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":["SECOND","MINUTE","HOUR","DAY","WEEK","MONTH","QUARTER","YEAR","UNIT_SECONDS","second","seconds","minute","minutes","hour","hours","day","days","week","weeks","month","months","quarter","quarters","year","years","resolveRelativeTimeUnit","absValue","Math","abs","calculateRelativeTimeValue","unit","round","createFormatter","_ref","formats","locale","globalNow","now","_ref$onError","onError","defaultOnError","globalTimeZone","timeZone","resolveFormatOrOptions","typeFormats","formatOrOptions","options","formatName","error","IntlError","IntlErrorCode","MISSING_FORMAT","process","env","NODE_ENV","undefined","getFormattedValue","value","formatter","String","FORMATTING_ERROR","message","dateTime","_options","_extends","ENVIRONMENT_FALLBACK","Intl","DateTimeFormat","format","number","NumberFormat","getGlobalNow","Date","extractNowDate","nowOrOptions","relativeTime","date","dateDate","nowDate","getTime","RelativeTimeFormat","numeric","list","ListFormat"],"mappings":";;;;AAQA,IAAMA,MAAM,GAAG,CAAC,CAAA;AAChB,IAAMC,MAAM,GAAGD,MAAM,GAAG,EAAE,CAAA;AAC1B,IAAME,IAAI,GAAGD,MAAM,GAAG,EAAE,CAAA;AACxB,IAAME,GAAG,GAAGD,IAAI,GAAG,EAAE,CAAA;AACrB,IAAME,IAAI,GAAGD,GAAG,GAAG,CAAC,CAAA;AACpB,IAAME,KAAK,GAAGF,GAAG,IAAI,GAAG,GAAG,EAAE,CAAC,CAAC;AAC/B,IAAMG,OAAO,GAAGD,KAAK,GAAG,CAAC,CAAA;AACzB,IAAME,IAAI,GAAGJ,GAAG,GAAG,GAAG,CAAA;AAEtB,IAAMK,YAAY,GAAgD;AAChEC,EAAAA,MAAM,EAAET,MAAM;AACdU,EAAAA,OAAO,EAAEV,MAAM;AACfW,EAAAA,MAAM,EAAEV,MAAM;AACdW,EAAAA,OAAO,EAAEX,MAAM;AACfY,EAAAA,IAAI,EAAEX,IAAI;AACVY,EAAAA,KAAK,EAAEZ,IAAI;AACXa,EAAAA,GAAG,EAAEZ,GAAG;AACRa,EAAAA,IAAI,EAAEb,GAAG;AACTc,EAAAA,IAAI,EAAEb,IAAI;AACVc,EAAAA,KAAK,EAAEd,IAAI;AACXe,EAAAA,KAAK,EAAEd,KAAK;AACZe,EAAAA,MAAM,EAAEf,KAAK;AACbgB,EAAAA,OAAO,EAAEf,OAAO;AAChBgB,EAAAA,QAAQ,EAAEhB,OAAO;AACjBiB,EAAAA,IAAI,EAAEhB,IAAI;AACViB,EAAAA,KAAK,EAAEjB,IAAAA;CACC,CAAA;AAEV,SAASkB,uBAAuBA,CAACf,OAAe,EAAA;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,IAAI,CAAC,CAAA;AAEvD,MAAA,OAAO,IAAIoC,IAAI,CAACc,kBAAkB,CAAC7C,MAAM,EAAE;AACzC8C,QAAAA,OAAO,EAAE,MAAA;AACV,OAAA,CAAC,CAACb,MAAM,CAACX,KAAK,EAAE3B,IAAI,CAAC,CAAA;KACvB,CAAC,OAAOkB,KAAK,EAAE;AACdT,MAAAA,OAAO,CACL,IAAIU,SAAS,CAACC,aAAa,CAACU,gBAAgB,EAAGZ,KAAe,CAACa,OAAO,CAAC,CACxE,CAAA;MACD,OAAOF,MAAM,CAACiB,IAAI,CAAC,CAAA;AACpB,KAAA;AACH,GAAA;AAEA,EAAA,SAASM,IAAIA,CACXzB,KAAuB,EACvBZ,eAAiD,EAAA;AAEjD,IAAA,OAAOW,iBAAiB,CAACC,KAAK,EAAEZ,eAAe,EAAEX,OAAO,IAAA,IAAA,GAAA,KAAA,CAAA,GAAPA,OAAO,CAAEgD,IAAI,EAAE,UAACpC,OAAO,EAAA;AAAA,MAAA,OACtE,IAAIoB,IAAI,CAACiB,UAAU,CAAChD,MAAM,EAAEW,OAAO,CAAC,CAACsB,MAAM,CAACX,KAAK,CAAC,CAAA;KACnD,CAAA,CAAA;AACH,GAAA;EAEA,OAAO;AAACK,IAAAA,QAAQ,EAARA,QAAQ;AAAEO,IAAAA,MAAM,EAANA,MAAM;AAAEM,IAAAA,YAAY,EAAZA,YAAY;AAAEO,IAAAA,IAAI,EAAJA,IAAAA;GAAK,CAAA;AAC/C;;;;"}
@@ -1,14 +0,0 @@
1
- import createFormatter from './use-intl.esm3.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=use-intl.esm4.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-intl.esm4.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,53 +0,0 @@
1
- import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose, extends as _extends } from '../_virtual/use-intl.esm.js';
2
- import IntlError, { IntlErrorCode } from './use-intl.esm.js';
3
- import createBaseTranslator, { getMessagesOrError } from './use-intl.esm8.js';
4
- import resolveNamespace from './use-intl.esm7.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
- messagesOrError: getMessagesOrError({
21
- messages: messages,
22
- namespace: namespace,
23
- onError: onError
24
- })
25
- }));
26
- var originalRich = translator.rich;
27
- function base() {
28
- return translator.apply(void 0, arguments);
29
- }
30
- // Augment `t.rich` to return plain strings
31
- base.rich = function (key, /** Key value pairs for values to interpolate into the message. */
32
- values, formats) {
33
- // `chunks` is returned as a string when no React element
34
- // is used, therefore it's safe to cast this type.
35
- var result = originalRich(key, values, formats);
36
- // When only string chunks are provided to the parser, only strings should be returned here.
37
- if (typeof result !== 'string') {
38
- 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);
39
- onError(error);
40
- return getMessageFallback({
41
- error: error,
42
- key: key,
43
- namespace: namespace
44
- });
45
- }
46
- return result;
47
- };
48
- base.raw = translator.raw;
49
- return base;
50
- }
51
-
52
- export { createTranslatorImpl as default };
53
- //# sourceMappingURL=use-intl.esm5.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-intl.esm5.js","sources":["../../src/core/createTranslatorImpl.tsx"],"sourcesContent":["import AbstractIntlMessages from './AbstractIntlMessages';\nimport {InitializedIntlConfig} from './IntlConfig';\nimport IntlError, {IntlErrorCode} from './IntlError';\nimport {RichTranslationValues, TranslationValue} from './TranslationValues';\nimport createBaseTranslator, {getMessagesOrError} from './createBaseTranslator';\nimport resolveNamespace from './resolveNamespace';\nimport NestedKeyOf from './utils/NestedKeyOf';\n\nexport type CoreRichTranslationValues = Record<\n string,\n TranslationValue | ((chunks: string) => string)\n>;\n\nexport type CreateTranslatorImplProps<Messages> = Omit<\n InitializedIntlConfig,\n 'messages'\n> & {\n namespace: string;\n messages: Messages;\n};\n\nexport default function createTranslatorImpl<\n Messages extends AbstractIntlMessages,\n NestedKey extends NestedKeyOf<Messages>\n>(\n {\n getMessageFallback,\n messages,\n namespace,\n onError,\n ...rest\n }: CreateTranslatorImplProps<Messages>,\n namespacePrefix: string\n) {\n // The `namespacePrefix` is part of the type system.\n // See the comment in the function invocation.\n messages = messages[namespacePrefix] as Messages;\n namespace = resolveNamespace(namespace, namespacePrefix) as NestedKey;\n\n const translator = createBaseTranslator<Messages, NestedKey>({\n ...rest,\n onError,\n getMessageFallback,\n messagesOrError: getMessagesOrError({\n messages,\n namespace,\n onError\n }) as Messages | IntlError\n });\n\n const originalRich = translator.rich;\n\n function base(...args: Parameters<typeof translator>) {\n return translator(...args);\n }\n\n // Augment `t.rich` to return plain strings\n base.rich = (\n key: Parameters<typeof originalRich>[0],\n /** Key value pairs for values to interpolate into the message. */\n values: CoreRichTranslationValues,\n formats?: Parameters<typeof originalRich>[2]\n ): string => {\n // `chunks` is returned as a string when no React element\n // is used, therefore it's safe to cast this type.\n const result = originalRich(key, values as RichTranslationValues, formats);\n\n // When only string chunks are provided to the parser, only strings should be returned here.\n if (typeof result !== 'string') {\n const error = new IntlError(\n IntlErrorCode.FORMATTING_ERROR,\n process.env.NODE_ENV !== 'production'\n ? \"`createTranslator` only accepts functions for rich text formatting that receive and return strings.\\n\\nE.g. t.rich('rich', {b: (chunks) => `<b>${chunks}</b>`})\"\n : undefined\n );\n\n onError(error);\n return getMessageFallback({error, key, namespace});\n }\n\n return result;\n };\n\n base.raw = translator.raw;\n\n return base;\n}\n"],"names":["createTranslatorImpl","_ref","namespacePrefix","getMessageFallback","messages","namespace","onError","rest","_objectWithoutPropertiesLoose","_excluded","resolveNamespace","translator","createBaseTranslator","_extends","messagesOrError","getMessagesOrError","originalRich","rich","base","apply","arguments","key","values","formats","result","error","IntlError","IntlErrorCode","FORMATTING_ERROR","process","env","NODE_ENV","undefined","raw"],"mappings":";;;;;;AAqBc,SAAUA,oBAAoBA,CAAAC,IAAA,EAW1CC,eAAuB,EAAA;AAAA,EAAA,IANrBC,kBAAkB,GAAAF,IAAA,CAAlBE,kBAAkB;IAClBC,QAAQ,GAAAH,IAAA,CAARG,QAAQ;IACRC,SAAS,GAAAJ,IAAA,CAATI,SAAS;IACTC,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QAAAA,KAAK,EAALA,KAAK;AAAEJ,QAAAA,GAAG,EAAHA,GAAG;AAAEhB,QAAAA,SAAS,EAATA,SAAAA;AAAU,OAAA,CAAC,CAAA;AACnD,KAAA;AAED,IAAA,OAAOmB,MAAM,CAAA;GACd,CAAA;AAEDN,EAAAA,IAAI,CAACe,GAAG,GAAGtB,UAAU,CAACsB,GAAG,CAAA;AAEzB,EAAA,OAAOf,IAAI,CAAA;AACb;;;;"}
@@ -1,15 +0,0 @@
1
- /**
2
- * Contains defaults that are used for all entry points into the core.
3
- * See also `InitializedIntlConfiguration`.
4
- */
5
- function defaultGetMessageFallback(props) {
6
- return [props.namespace, props.key].filter(function (part) {
7
- return part != null;
8
- }).join('.');
9
- }
10
- function defaultOnError(error) {
11
- console.error(error);
12
- }
13
-
14
- export { defaultGetMessageFallback, defaultOnError };
15
- //# sourceMappingURL=use-intl.esm6.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-intl.esm6.js","sources":["../../src/core/defaults.tsx"],"sourcesContent":["import IntlError from './IntlError';\n\n/**\n * Contains defaults that are used for all entry points into the core.\n * See also `InitializedIntlConfiguration`.\n */\n\nexport function defaultGetMessageFallback(props: {\n error: IntlError;\n key: string;\n namespace?: string;\n}) {\n return [props.namespace, props.key].filter((part) => part != null).join('.');\n}\n\nexport function defaultOnError(error: IntlError) {\n console.error(error);\n}\n"],"names":["defaultGetMessageFallback","props","namespace","key","filter","part","join","defaultOnError","error","console"],"mappings":"AAEA;;;AAGG;AAEG,SAAUA,yBAAyBA,CAACC,KAIzC,EAAA;AACC,EAAA,OAAO,CAACA,KAAK,CAACC,SAAS,EAAED,KAAK,CAACE,GAAG,CAAC,CAACC,MAAM,CAAC,UAACC,IAAI,EAAA;IAAA,OAAKA,IAAI,IAAI,IAAI,CAAA;AAAA,GAAA,CAAC,CAACC,IAAI,CAAC,GAAG,CAAC,CAAA;AAC9E,CAAA;AAEM,SAAUC,cAAcA,CAACC,KAAgB,EAAA;AAC7CC,EAAAA,OAAO,CAACD,KAAK,CAACA,KAAK,CAAC,CAAA;AACtB;;;;"}
@@ -1,10 +0,0 @@
1
- /**
2
- * For the strictly typed messages to work we have to wrap the namespace into
3
- * a mandatory prefix. See https://stackoverflow.com/a/71529575/343045
4
- */
5
- function resolveNamespace(namespace, namespacePrefix) {
6
- return namespace === namespacePrefix ? undefined : namespace.slice((namespacePrefix + '.').length);
7
- }
8
-
9
- export { resolveNamespace as default };
10
- //# sourceMappingURL=use-intl.esm7.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-intl.esm7.js","sources":["../../src/core/resolveNamespace.tsx"],"sourcesContent":["/**\n * For the strictly typed messages to work we have to wrap the namespace into\n * a mandatory prefix. See https://stackoverflow.com/a/71529575/343045\n */\nexport default function resolveNamespace(\n namespace: string,\n namespacePrefix: string\n) {\n return namespace === namespacePrefix\n ? undefined\n : namespace.slice((namespacePrefix + '.').length);\n}\n"],"names":["resolveNamespace","namespace","namespacePrefix","undefined","slice","length"],"mappings":"AAAA;;;AAGG;AACW,SAAUA,gBAAgBA,CACtCC,SAAiB,EACjBC,eAAuB,EAAA;AAEvB,EAAA,OAAOD,SAAS,KAAKC,eAAe,GAChCC,SAAS,GACTF,SAAS,CAACG,KAAK,CAAC,CAACF,eAAe,GAAG,GAAG,EAAEG,MAAM,CAAC,CAAA;AACrD;;;;"}
@@ -1,200 +0,0 @@
1
- import { extends as _extends } from '../_virtual/use-intl.esm.js';
2
- import IntlMessageFormat from 'intl-messageformat';
3
- import { isValidElement, cloneElement } from 'react';
4
- import IntlError, { IntlErrorCode } from './use-intl.esm.js';
5
- import convertFormatsToIntlMessageFormat from './use-intl.esm10.js';
6
- import { defaultOnError, defaultGetMessageFallback } from './use-intl.esm6.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(_ref2) {
77
- var defaultTranslationValues = _ref2.defaultTranslationValues,
78
- globalFormats = _ref2.formats,
79
- _ref2$getMessageFallb = _ref2.getMessageFallback,
80
- getMessageFallback = _ref2$getMessageFallb === void 0 ? defaultGetMessageFallback : _ref2$getMessageFallb,
81
- locale = _ref2.locale,
82
- messageFormatCache = _ref2.messageFormatCache,
83
- messagesOrError = _ref2.messagesOrError,
84
- namespace = _ref2.namespace,
85
- onError = _ref2.onError,
86
- timeZone = _ref2.timeZone;
87
- function getFallbackFromErrorAndNotify(key, code, message) {
88
- var error = new IntlError(code, message);
89
- onError(error);
90
- return getMessageFallback({
91
- error: error,
92
- key: key,
93
- namespace: namespace
94
- });
95
- }
96
- function translateBaseFn( /** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */
97
- key, /** Key value pairs for values to interpolate into the message. */
98
- values, /** Provide custom formats for numbers, dates and times. */
99
- formats) {
100
- if (messagesOrError instanceof IntlError) {
101
- // We have already warned about this during render
102
- return getMessageFallback({
103
- error: messagesOrError,
104
- key: key,
105
- namespace: namespace
106
- });
107
- }
108
- var messages = messagesOrError;
109
- var message;
110
- try {
111
- message = resolvePath(messages, key, namespace);
112
- } catch (error) {
113
- return getFallbackFromErrorAndNotify(key, IntlErrorCode.MISSING_MESSAGE, error.message);
114
- }
115
- function joinPath(parts) {
116
- return parts.filter(function (part) {
117
- return part != null;
118
- }).join('.');
119
- }
120
- var cacheKey = joinPath([locale, namespace, key, String(message)]);
121
- var messageFormat;
122
- if (messageFormatCache != null && messageFormatCache.has(cacheKey)) {
123
- messageFormat = messageFormatCache.get(cacheKey);
124
- } else {
125
- if (typeof message === 'object') {
126
- var code, errorMessage;
127
- if (Array.isArray(message)) {
128
- code = IntlErrorCode.INVALID_MESSAGE;
129
- if (process.env.NODE_ENV !== 'production') {
130
- 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";
131
- }
132
- } else {
133
- code = IntlErrorCode.INSUFFICIENT_PATH;
134
- if (process.env.NODE_ENV !== 'production') {
135
- 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";
136
- }
137
- }
138
- return getFallbackFromErrorAndNotify(key, code, errorMessage);
139
- }
140
- // Hot path that avoids creating an `IntlMessageFormat` instance
141
- var plainMessage = getPlainMessage(message, values);
142
- if (plainMessage) return plainMessage;
143
- try {
144
- messageFormat = new IntlMessageFormat(message, locale, convertFormatsToIntlMessageFormat(_extends({}, globalFormats, formats), timeZone));
145
- } catch (error) {
146
- return getFallbackFromErrorAndNotify(key, IntlErrorCode.INVALID_MESSAGE, error.message);
147
- }
148
- messageFormatCache == null || messageFormatCache.set(cacheKey, messageFormat);
149
- }
150
- try {
151
- var formattedMessage = messageFormat.format(
152
- // @ts-ignore `intl-messageformat` expects a different format
153
- // for rich text elements since a recent minor update. This
154
- // needs to be evaluated in detail, possibly also in regards
155
- // to be able to format to parts.
156
- prepareTranslationValues(_extends({}, defaultTranslationValues, values)));
157
- if (formattedMessage == null) {
158
- throw new Error(process.env.NODE_ENV !== 'production' ? "Unable to format `" + key + "` in " + (namespace ? "namespace `" + namespace + "`" : 'messages') : undefined);
159
- }
160
- // Limit the function signature to return strings or React elements
161
- return isValidElement(formattedMessage) ||
162
- // Arrays of React elements
163
- Array.isArray(formattedMessage) || typeof formattedMessage === 'string' ? formattedMessage : String(formattedMessage);
164
- } catch (error) {
165
- return getFallbackFromErrorAndNotify(key, IntlErrorCode.FORMATTING_ERROR, error.message);
166
- }
167
- }
168
- function translateFn( /** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */
169
- key, /** Key value pairs for values to interpolate into the message. */
170
- values, /** Provide custom formats for numbers, dates and times. */
171
- formats) {
172
- var result = translateBaseFn(key, values, formats);
173
- if (typeof result !== 'string') {
174
- 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);
175
- }
176
- return result;
177
- }
178
- translateFn.rich = translateBaseFn;
179
- translateFn.raw = function ( /** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */
180
- key) {
181
- if (messagesOrError instanceof IntlError) {
182
- // We have already warned about this during render
183
- return getMessageFallback({
184
- error: messagesOrError,
185
- key: key,
186
- namespace: namespace
187
- });
188
- }
189
- var messages = messagesOrError;
190
- try {
191
- return resolvePath(messages, key, namespace);
192
- } catch (error) {
193
- return getFallbackFromErrorAndNotify(key, IntlErrorCode.MISSING_MESSAGE, error.message);
194
- }
195
- };
196
- return translateFn;
197
- }
198
-
199
- export { createBaseTranslator as default, getMessagesOrError };
200
- //# sourceMappingURL=use-intl.esm8.js.map