use-intl 2.22.1 → 2.22.3

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 -3
  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 -200
  99. package/dist/core/use-intl.esm7.js.map +0 -1
  100. package/dist/core/use-intl.esm8.js +0 -10
  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
package/README.md CHANGED
@@ -1,7 +1,5 @@
1
1
  # 🌐 use-intl
2
2
 
3
- ![Gzipped size](https://badgen.net/bundlephobia/minzip/use-intl) ![Tree shaking supported](https://badgen.net/bundlephobia/tree-shaking/use-intl) [<img src="https://img.shields.io/npm/dw/use-intl.svg" />](https://www.npmjs.com/package/use-intl)
4
-
5
3
  > Internationalization for React that gets out of your way.
6
4
 
7
5
  ## Features
@@ -35,7 +33,7 @@ export default function UserProfile({user}) {
35
33
  }
36
34
  ```
37
35
 
38
- ```json
36
+ ```js
39
37
  // en.json
40
38
  {
41
39
  "UserProfile": {
@@ -0,0 +1 @@
1
+ export * from './dist/types/src/_IntlProvider';
@@ -0,0 +1 @@
1
+ export * from './dist/types/src/_useLocale';
package/core.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './dist/types/src/core';
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ if (process.env.NODE_ENV === 'production') {
4
+ module.exports = require('./production/_IntlProvider.js');
5
+ } else {
6
+ module.exports = require('./development/_IntlProvider.js');
7
+ }
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ if (process.env.NODE_ENV === 'production') {
4
+ module.exports = require('./production/_useLocale.js');
5
+ } else {
6
+ module.exports = require('./development/_useLocale.js');
7
+ }
package/dist/core.js ADDED
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ if (process.env.NODE_ENV === 'production') {
4
+ module.exports = require('./production/core.js');
5
+ } else {
6
+ module.exports = require('./development/core.js');
7
+ }
@@ -0,0 +1,8 @@
1
+ 'use strict';
2
+
3
+ var React = require('react');
4
+
5
+ const IntlContext = /*#__PURE__*/React.createContext(undefined);
6
+ var IntlContext$1 = IntlContext;
7
+
8
+ exports.IntlContext = IntlContext$1;
@@ -0,0 +1,53 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var React = require('react');
6
+ var initializeConfig = require('./initializeConfig-0a0b87a7.js');
7
+ var IntlContext = require('./IntlContext-b5cc6be8.js');
8
+
9
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
10
+
11
+ var React__default = /*#__PURE__*/_interopDefault(React);
12
+
13
+ function IntlProvider(_ref) {
14
+ let {
15
+ children,
16
+ defaultTranslationValues,
17
+ formats,
18
+ getMessageFallback,
19
+ locale,
20
+ messages,
21
+ now,
22
+ onError,
23
+ timeZone
24
+ } = _ref;
25
+ const [messageFormatCache] = React.useState(() => new Map());
26
+
27
+ // Memoizing this value helps to avoid triggering a re-render of all
28
+ // context consumers in case the configuration didn't change. However,
29
+ // if some of the non-primitive values change, a re-render will still
30
+ // be triggered. Note that there's no need to put `memo` on `IntlProvider`
31
+ // itself, because the `children` typically change on every render.
32
+ // There's some burden on the consumer side if it's important to reduce
33
+ // re-renders, put that's how React works.
34
+ // See: https://blog.isquaredsoftware.com/2020/05/blogged-answers-a-mostly-complete-guide-to-react-rendering-behavior/#context-updates-and-render-optimizations
35
+ const value = React.useMemo(() => ({
36
+ ...initializeConfig.initializeConfig({
37
+ locale,
38
+ defaultTranslationValues,
39
+ formats,
40
+ getMessageFallback,
41
+ messages,
42
+ now,
43
+ onError,
44
+ timeZone
45
+ }),
46
+ messageFormatCache
47
+ }), [defaultTranslationValues, formats, getMessageFallback, locale, messageFormatCache, messages, now, onError, timeZone]);
48
+ return /*#__PURE__*/React__default.default.createElement(IntlContext.IntlContext.Provider, {
49
+ value: value
50
+ }, children);
51
+ }
52
+
53
+ exports.IntlProvider = IntlProvider;
@@ -0,0 +1,19 @@
1
+ 'use strict';
2
+
3
+ var React = require('react');
4
+ var IntlContext = require('./IntlContext-b5cc6be8.js');
5
+
6
+ function useIntlContext() {
7
+ const context = React.useContext(IntlContext.IntlContext);
8
+ if (!context) {
9
+ throw new Error('No intl context found. Have you configured the provider?' );
10
+ }
11
+ return context;
12
+ }
13
+
14
+ function useLocale() {
15
+ return useIntlContext().locale;
16
+ }
17
+
18
+ exports.useIntlContext = useIntlContext;
19
+ exports.useLocale = useLocale;
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _useLocale = require('./_useLocale-321e619f.js');
6
+ require('react');
7
+ require('./IntlContext-b5cc6be8.js');
8
+
9
+
10
+
11
+ exports.useLocale = _useLocale.useLocale;
@@ -0,0 +1,66 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var initializeConfig = require('./initializeConfig-0a0b87a7.js');
6
+ var createFormatter = require('./createFormatter-4848f6c8.js');
7
+ require('intl-messageformat');
8
+ require('react');
9
+
10
+ function createTranslatorImpl(_ref, namespacePrefix) {
11
+ let {
12
+ getMessageFallback,
13
+ messages,
14
+ namespace,
15
+ onError,
16
+ ...rest
17
+ } = _ref;
18
+ // The `namespacePrefix` is part of the type system.
19
+ // See the comment in the function invocation.
20
+ messages = messages[namespacePrefix];
21
+ namespace = createFormatter.resolveNamespace(namespace, namespacePrefix);
22
+ return createFormatter.createBaseTranslator({
23
+ ...rest,
24
+ onError,
25
+ getMessageFallback,
26
+ messages,
27
+ namespace
28
+ });
29
+ }
30
+
31
+ /**
32
+ * Translates messages from the given namespace by using the ICU syntax.
33
+ * See https://formatjs.io/docs/core-concepts/icu-syntax.
34
+ *
35
+ * If no namespace is provided, all available messages are returned.
36
+ * The namespace can also indicate nesting by using a dot
37
+ * (e.g. `namespace.Component`).
38
+ */
39
+ function createTranslator(_ref) {
40
+ let {
41
+ getMessageFallback = initializeConfig.defaultGetMessageFallback,
42
+ messages,
43
+ namespace,
44
+ onError = initializeConfig.defaultOnError,
45
+ ...rest
46
+ } = _ref;
47
+ // We have to wrap the actual function so the type inference for the optional
48
+ // namespace works correctly. See https://stackoverflow.com/a/71529575/343045
49
+ // The prefix ("!") is arbitrary.
50
+ return createTranslatorImpl({
51
+ ...rest,
52
+ onError,
53
+ getMessageFallback,
54
+ // @ts-expect-error `messages` is allowed to be `undefined` here and will be handled internally
55
+ messages: {
56
+ '!': messages
57
+ },
58
+ namespace: namespace ? "!.".concat(namespace) : '!'
59
+ }, '!');
60
+ }
61
+
62
+ exports.IntlError = initializeConfig.IntlError;
63
+ exports.IntlErrorCode = initializeConfig.IntlErrorCode;
64
+ exports.initializeConfig = initializeConfig.initializeConfig;
65
+ exports.createFormatter = createFormatter.createFormatter;
66
+ exports.createTranslator = createTranslator;
@@ -0,0 +1,453 @@
1
+ 'use strict';
2
+
3
+ var IntlMessageFormat = require('intl-messageformat');
4
+ var React = require('react');
5
+ var initializeConfig = require('./initializeConfig-0a0b87a7.js');
6
+
7
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
8
+
9
+ var IntlMessageFormat__default = /*#__PURE__*/_interopDefault(IntlMessageFormat);
10
+
11
+ // eslint-disable-next-line import/no-named-as-default -- False positive
12
+ function setTimeZoneInFormats(formats, timeZone) {
13
+ if (!formats) return formats;
14
+
15
+ // The only way to set a time zone with `intl-messageformat` is to merge it into the formats
16
+ // https://github.com/formatjs/formatjs/blob/8256c5271505cf2606e48e3c97ecdd16ede4f1b5/packages/intl/src/message.ts#L15
17
+ return Object.keys(formats).reduce((acc, key) => {
18
+ acc[key] = {
19
+ timeZone,
20
+ ...formats[key]
21
+ };
22
+ return acc;
23
+ }, {});
24
+ }
25
+
26
+ /**
27
+ * `intl-messageformat` uses separate keys for `date` and `time`, but there's
28
+ * only one native API: `Intl.DateTimeFormat`. Additionally you might want to
29
+ * include both a time and a date in a value, therefore the separation doesn't
30
+ * seem so useful. We offer a single `dateTime` namespace instead, but we have
31
+ * to convert the format before `intl-messageformat` can be used.
32
+ */
33
+ function convertFormatsToIntlMessageFormat(formats, timeZone) {
34
+ const formatsWithTimeZone = timeZone ? {
35
+ ...formats,
36
+ dateTime: setTimeZoneInFormats(formats.dateTime, timeZone)
37
+ } : formats;
38
+ const mfDateDefaults = IntlMessageFormat__default.default.formats.date;
39
+ const defaultDateFormats = timeZone ? setTimeZoneInFormats(mfDateDefaults, timeZone) : mfDateDefaults;
40
+ const mfTimeDefaults = IntlMessageFormat__default.default.formats.time;
41
+ const defaultTimeFormats = timeZone ? setTimeZoneInFormats(mfTimeDefaults, timeZone) : mfTimeDefaults;
42
+ return {
43
+ ...formatsWithTimeZone,
44
+ date: {
45
+ ...defaultDateFormats,
46
+ ...(formatsWithTimeZone === null || formatsWithTimeZone === void 0 ? void 0 : formatsWithTimeZone.dateTime)
47
+ },
48
+ time: {
49
+ ...defaultTimeFormats,
50
+ ...(formatsWithTimeZone === null || formatsWithTimeZone === void 0 ? void 0 : formatsWithTimeZone.dateTime)
51
+ }
52
+ };
53
+ }
54
+
55
+ // eslint-disable-next-line import/no-named-as-default -- False positive
56
+ function resolvePath(messages, key, namespace) {
57
+ if (!messages) {
58
+ throw new Error("No messages available at `".concat(namespace, "`.") );
59
+ }
60
+ let message = messages;
61
+ key.split('.').forEach(part => {
62
+ const next = message[part];
63
+ if (part == null || next == null) {
64
+ throw new Error("Could not resolve `".concat(key, "` in ").concat(namespace ? "`".concat(namespace, "`") : 'messages', ".") );
65
+ }
66
+ message = next;
67
+ });
68
+ return message;
69
+ }
70
+ function prepareTranslationValues(values) {
71
+ if (Object.keys(values).length === 0) return undefined;
72
+
73
+ // Workaround for https://github.com/formatjs/formatjs/issues/1467
74
+ const transformedValues = {};
75
+ Object.keys(values).forEach(key => {
76
+ let index = 0;
77
+ const value = values[key];
78
+ let transformed;
79
+ if (typeof value === 'function') {
80
+ transformed = chunks => {
81
+ const result = value(chunks);
82
+ return /*#__PURE__*/React.isValidElement(result) ? /*#__PURE__*/React.cloneElement(result, {
83
+ key: key + index++
84
+ }) : result;
85
+ };
86
+ } else {
87
+ transformed = value;
88
+ }
89
+ transformedValues[key] = transformed;
90
+ });
91
+ return transformedValues;
92
+ }
93
+ function getMessagesOrError(_ref) {
94
+ let {
95
+ messages,
96
+ namespace,
97
+ onError = initializeConfig.defaultOnError
98
+ } = _ref;
99
+ try {
100
+ if (!messages) {
101
+ throw new Error("No messages were configured on the provider." );
102
+ }
103
+ const retrievedMessages = namespace ? resolvePath(messages, namespace) : messages;
104
+ if (!retrievedMessages) {
105
+ throw new Error("No messages for namespace `".concat(namespace, "` found.") );
106
+ }
107
+ return retrievedMessages;
108
+ } catch (error) {
109
+ const intlError = new initializeConfig.IntlError(initializeConfig.IntlErrorCode.MISSING_MESSAGE, error.message);
110
+ onError(intlError);
111
+ return intlError;
112
+ }
113
+ }
114
+ function getPlainMessage(candidate, values) {
115
+ if (values) return undefined;
116
+ const unescapedMessage = candidate.replace(/'([{}])/gi, '$1');
117
+
118
+ // Placeholders can be in the message if there are default values,
119
+ // or if the user has forgotten to provide values. In the latter
120
+ // case we need to compile the message to receive an error.
121
+ const hasPlaceholders = /<|{/.test(unescapedMessage);
122
+ if (!hasPlaceholders) {
123
+ return unescapedMessage;
124
+ }
125
+ return undefined;
126
+ }
127
+ function createBaseTranslator(config) {
128
+ const messagesOrError = getMessagesOrError({
129
+ messages: config.messages,
130
+ namespace: config.namespace,
131
+ onError: config.onError
132
+ });
133
+ return createBaseTranslatorImpl({
134
+ ...config,
135
+ messagesOrError
136
+ });
137
+ }
138
+ function createBaseTranslatorImpl(_ref2) {
139
+ let {
140
+ defaultTranslationValues,
141
+ formats: globalFormats,
142
+ getMessageFallback = initializeConfig.defaultGetMessageFallback,
143
+ locale,
144
+ messageFormatCache,
145
+ messagesOrError,
146
+ namespace,
147
+ onError,
148
+ timeZone
149
+ } = _ref2;
150
+ function getFallbackFromErrorAndNotify(key, code, message) {
151
+ const error = new initializeConfig.IntlError(code, message);
152
+ onError(error);
153
+ return getMessageFallback({
154
+ error,
155
+ key,
156
+ namespace
157
+ });
158
+ }
159
+ function translateBaseFn( /** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */
160
+ key, /** Key value pairs for values to interpolate into the message. */
161
+ values, /** Provide custom formats for numbers, dates and times. */
162
+ formats) {
163
+ if (messagesOrError instanceof initializeConfig.IntlError) {
164
+ // We have already warned about this during render
165
+ return getMessageFallback({
166
+ error: messagesOrError,
167
+ key,
168
+ namespace
169
+ });
170
+ }
171
+ const messages = messagesOrError;
172
+ let message;
173
+ try {
174
+ message = resolvePath(messages, key, namespace);
175
+ } catch (error) {
176
+ return getFallbackFromErrorAndNotify(key, initializeConfig.IntlErrorCode.MISSING_MESSAGE, error.message);
177
+ }
178
+ function joinPath(parts) {
179
+ return parts.filter(part => part != null).join('.');
180
+ }
181
+ const cacheKey = joinPath([locale, namespace, key, String(message)]);
182
+ let messageFormat;
183
+ if (messageFormatCache !== null && messageFormatCache !== void 0 && messageFormatCache.has(cacheKey)) {
184
+ messageFormat = messageFormatCache.get(cacheKey);
185
+ } else {
186
+ if (typeof message === 'object') {
187
+ let code, errorMessage;
188
+ if (Array.isArray(message)) {
189
+ code = initializeConfig.IntlErrorCode.INVALID_MESSAGE;
190
+ {
191
+ errorMessage = "Message at `".concat(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");
192
+ }
193
+ } else {
194
+ code = initializeConfig.IntlErrorCode.INSUFFICIENT_PATH;
195
+ {
196
+ errorMessage = "Message at `".concat(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");
197
+ }
198
+ }
199
+ return getFallbackFromErrorAndNotify(key, code, errorMessage);
200
+ }
201
+
202
+ // Hot path that avoids creating an `IntlMessageFormat` instance
203
+ const plainMessage = getPlainMessage(message, values);
204
+ if (plainMessage) return plainMessage;
205
+ try {
206
+ messageFormat = new IntlMessageFormat__default.default(message, locale, convertFormatsToIntlMessageFormat({
207
+ ...globalFormats,
208
+ ...formats
209
+ }, timeZone));
210
+ } catch (error) {
211
+ return getFallbackFromErrorAndNotify(key, initializeConfig.IntlErrorCode.INVALID_MESSAGE, error.message);
212
+ }
213
+ messageFormatCache === null || messageFormatCache === void 0 || messageFormatCache.set(cacheKey, messageFormat);
214
+ }
215
+ try {
216
+ const formattedMessage = messageFormat.format(
217
+ // @ts-expect-error `intl-messageformat` expects a different format
218
+ // for rich text elements since a recent minor update. This
219
+ // needs to be evaluated in detail, possibly also in regards
220
+ // to be able to format to parts.
221
+ prepareTranslationValues({
222
+ ...defaultTranslationValues,
223
+ ...values
224
+ }));
225
+ if (formattedMessage == null) {
226
+ throw new Error("Unable to format `".concat(key, "` in ").concat(namespace ? "namespace `".concat(namespace, "`") : 'messages') );
227
+ }
228
+
229
+ // Limit the function signature to return strings or React elements
230
+ return /*#__PURE__*/React.isValidElement(formattedMessage) ||
231
+ // Arrays of React elements
232
+ Array.isArray(formattedMessage) || typeof formattedMessage === 'string' ? formattedMessage : String(formattedMessage);
233
+ } catch (error) {
234
+ return getFallbackFromErrorAndNotify(key, initializeConfig.IntlErrorCode.FORMATTING_ERROR, error.message);
235
+ }
236
+ }
237
+ function translateFn( /** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */
238
+ key, /** Key value pairs for values to interpolate into the message. */
239
+ values, /** Provide custom formats for numbers, dates and times. */
240
+ formats) {
241
+ const result = translateBaseFn(key, values, formats);
242
+ if (typeof result !== 'string') {
243
+ return getFallbackFromErrorAndNotify(key, initializeConfig.IntlErrorCode.INVALID_MESSAGE, "The message `".concat(key, "` in ").concat(namespace ? "namespace `".concat(namespace, "`") : 'messages', " didn't resolve to a string. If you want to format rich text, use `t.rich` instead.") );
244
+ }
245
+ return result;
246
+ }
247
+ translateFn.rich = translateBaseFn;
248
+
249
+ // Augment `translateBaseFn` to return plain strings
250
+ translateFn.markup = (key, values, formats) => {
251
+ const result = translateBaseFn(key,
252
+ // @ts-expect-error -- `MarkupTranslationValues` is practically a sub type
253
+ // of `RichTranslationValues` but TypeScript isn't smart enough here.
254
+ values, formats);
255
+
256
+ // When only string chunks are provided to the parser, only
257
+ // strings should be returned here. Note that we need a runtime
258
+ // check for this since rich text values could be accidentally
259
+ // inherited from `defaultTranslationValues`.
260
+ if (typeof result !== 'string') {
261
+ const error = new initializeConfig.IntlError(initializeConfig.IntlErrorCode.FORMATTING_ERROR, "`t.markup` only accepts functions for formatting that receive and return strings.\n\nE.g. t.markup('markup', {b: (chunks) => `<b>${chunks}</b>`})" );
262
+ onError(error);
263
+ return getMessageFallback({
264
+ error,
265
+ key,
266
+ namespace
267
+ });
268
+ }
269
+ return result;
270
+ };
271
+ translateFn.raw = key => {
272
+ if (messagesOrError instanceof initializeConfig.IntlError) {
273
+ // We have already warned about this during render
274
+ return getMessageFallback({
275
+ error: messagesOrError,
276
+ key,
277
+ namespace
278
+ });
279
+ }
280
+ const messages = messagesOrError;
281
+ try {
282
+ return resolvePath(messages, key, namespace);
283
+ } catch (error) {
284
+ return getFallbackFromErrorAndNotify(key, initializeConfig.IntlErrorCode.MISSING_MESSAGE, error.message);
285
+ }
286
+ };
287
+ return translateFn;
288
+ }
289
+
290
+ /**
291
+ * For the strictly typed messages to work we have to wrap the namespace into
292
+ * a mandatory prefix. See https://stackoverflow.com/a/71529575/343045
293
+ */
294
+ function resolveNamespace(namespace, namespacePrefix) {
295
+ return namespace === namespacePrefix ? undefined : namespace.slice((namespacePrefix + '.').length);
296
+ }
297
+
298
+ const SECOND = 1;
299
+ const MINUTE = SECOND * 60;
300
+ const HOUR = MINUTE * 60;
301
+ const DAY = HOUR * 24;
302
+ const WEEK = DAY * 7;
303
+ const MONTH = DAY * (365 / 12); // Approximation
304
+ const QUARTER = MONTH * 3;
305
+ const YEAR = DAY * 365;
306
+ const UNIT_SECONDS = {
307
+ second: SECOND,
308
+ seconds: SECOND,
309
+ minute: MINUTE,
310
+ minutes: MINUTE,
311
+ hour: HOUR,
312
+ hours: HOUR,
313
+ day: DAY,
314
+ days: DAY,
315
+ week: WEEK,
316
+ weeks: WEEK,
317
+ month: MONTH,
318
+ months: MONTH,
319
+ quarter: QUARTER,
320
+ quarters: QUARTER,
321
+ year: YEAR,
322
+ years: YEAR
323
+ };
324
+ function resolveRelativeTimeUnit(seconds) {
325
+ const absValue = Math.abs(seconds);
326
+ if (absValue < MINUTE) {
327
+ return 'second';
328
+ } else if (absValue < HOUR) {
329
+ return 'minute';
330
+ } else if (absValue < DAY) {
331
+ return 'hour';
332
+ } else if (absValue < WEEK) {
333
+ return 'day';
334
+ } else if (absValue < MONTH) {
335
+ return 'week';
336
+ } else if (absValue < YEAR) {
337
+ return 'month';
338
+ }
339
+ return 'year';
340
+ }
341
+ function calculateRelativeTimeValue(seconds, unit) {
342
+ // We have to round the resulting values, as `Intl.RelativeTimeFormat`
343
+ // will include fractions like '2.1 hours ago'.
344
+ return Math.round(seconds / UNIT_SECONDS[unit]);
345
+ }
346
+ function createFormatter(_ref) {
347
+ let {
348
+ formats,
349
+ locale,
350
+ now: globalNow,
351
+ onError = initializeConfig.defaultOnError,
352
+ timeZone: globalTimeZone
353
+ } = _ref;
354
+ function resolveFormatOrOptions(typeFormats, formatOrOptions) {
355
+ let options;
356
+ if (typeof formatOrOptions === 'string') {
357
+ const formatName = formatOrOptions;
358
+ options = typeFormats === null || typeFormats === void 0 ? void 0 : typeFormats[formatName];
359
+ if (!options) {
360
+ const error = new initializeConfig.IntlError(initializeConfig.IntlErrorCode.MISSING_FORMAT, "Format `".concat(formatName, "` is not available. You can configure it on the provider or provide custom options.") );
361
+ onError(error);
362
+ throw error;
363
+ }
364
+ } else {
365
+ options = formatOrOptions;
366
+ }
367
+ return options;
368
+ }
369
+ function getFormattedValue(value, formatOrOptions, typeFormats, formatter) {
370
+ let options;
371
+ try {
372
+ options = resolveFormatOrOptions(typeFormats, formatOrOptions);
373
+ } catch (error) {
374
+ return String(value);
375
+ }
376
+ try {
377
+ return formatter(options);
378
+ } catch (error) {
379
+ onError(new initializeConfig.IntlError(initializeConfig.IntlErrorCode.FORMATTING_ERROR, error.message));
380
+ return String(value);
381
+ }
382
+ }
383
+ function dateTime( /** If a number is supplied, this is interpreted as a UTC timestamp. */
384
+ value,
385
+ /** If a time zone is supplied, the `value` is converted to that time zone.
386
+ * Otherwise the user time zone will be used. */
387
+ formatOrOptions) {
388
+ return getFormattedValue(value, formatOrOptions, formats === null || formats === void 0 ? void 0 : formats.dateTime, options => {
389
+ var _options;
390
+ if (!((_options = options) !== null && _options !== void 0 && _options.timeZone)) {
391
+ if (globalTimeZone) {
392
+ options = {
393
+ ...options,
394
+ timeZone: globalTimeZone
395
+ };
396
+ } else {
397
+ onError(new initializeConfig.IntlError(initializeConfig.IntlErrorCode.ENVIRONMENT_FALLBACK, "The `timeZone` parameter wasn't provided and there is no global default configured. Consider adding a global default to avoid markup mismatches caused by environment differences. Learn more: https://next-intl-docs.vercel.app/docs/configuration#time-zone" ));
398
+ }
399
+ }
400
+ return new Intl.DateTimeFormat(locale, options).format(value);
401
+ });
402
+ }
403
+ function number(value, formatOrOptions) {
404
+ return getFormattedValue(value, formatOrOptions, formats === null || formats === void 0 ? void 0 : formats.number, options => new Intl.NumberFormat(locale, options).format(value));
405
+ }
406
+ function getGlobalNow() {
407
+ if (globalNow) {
408
+ return globalNow;
409
+ } else {
410
+ onError(new initializeConfig.IntlError(initializeConfig.IntlErrorCode.ENVIRONMENT_FALLBACK, "The `now` parameter wasn't provided and there is no global default configured. Consider adding a global default to avoid markup mismatches caused by environment differences. Learn more: https://next-intl-docs.vercel.app/docs/configuration#now" ));
411
+ return new Date();
412
+ }
413
+ }
414
+ function extractNowDate(nowOrOptions) {
415
+ if (nowOrOptions instanceof Date || typeof nowOrOptions === 'number') {
416
+ return new Date(nowOrOptions);
417
+ }
418
+ if ((nowOrOptions === null || nowOrOptions === void 0 ? void 0 : nowOrOptions.now) !== undefined) {
419
+ return new Date(nowOrOptions.now);
420
+ }
421
+ return getGlobalNow();
422
+ }
423
+ function relativeTime( /** The date time that needs to be formatted. */
424
+ date, /** The reference point in time to which `date` will be formatted in relation to. */
425
+ nowOrOptions) {
426
+ try {
427
+ const dateDate = new Date(date);
428
+ const nowDate = extractNowDate(nowOrOptions);
429
+ const seconds = (dateDate.getTime() - nowDate.getTime()) / 1000;
430
+ const unit = typeof nowOrOptions === 'number' || nowOrOptions instanceof Date || (nowOrOptions === null || nowOrOptions === void 0 ? void 0 : nowOrOptions.unit) === undefined ? resolveRelativeTimeUnit(seconds) : nowOrOptions.unit;
431
+ const value = calculateRelativeTimeValue(seconds, unit);
432
+ return new Intl.RelativeTimeFormat(locale, {
433
+ numeric: 'auto'
434
+ }).format(value, unit);
435
+ } catch (error) {
436
+ onError(new initializeConfig.IntlError(initializeConfig.IntlErrorCode.FORMATTING_ERROR, error.message));
437
+ return String(date);
438
+ }
439
+ }
440
+ function list(value, formatOrOptions) {
441
+ return getFormattedValue(value, formatOrOptions, formats === null || formats === void 0 ? void 0 : formats.list, options => new Intl.ListFormat(locale, options).format(value));
442
+ }
443
+ return {
444
+ dateTime,
445
+ number,
446
+ relativeTime,
447
+ list
448
+ };
449
+ }
450
+
451
+ exports.createBaseTranslator = createBaseTranslator;
452
+ exports.createFormatter = createFormatter;
453
+ exports.resolveNamespace = resolveNamespace;