use-intl 2.10.0 → 2.11.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +490 -0
- package/dist/core/use-intl.esm2.js +2 -2
- package/dist/core/use-intl.esm3.js +3 -3
- package/dist/core/use-intl.esm3.js.map +1 -1
- package/dist/core/use-intl.esm4.js +12 -56
- package/dist/core/use-intl.esm4.js.map +1 -1
- package/dist/core/use-intl.esm5.js +56 -12
- package/dist/core/use-intl.esm5.js.map +1 -1
- package/dist/core/use-intl.esm7.js +8 -8
- package/dist/core/use-intl.esm7.js.map +1 -1
- package/dist/react/IntlContext.d.ts +2 -19
- package/dist/react/IntlContextValue.d.ts +19 -0
- package/dist/react/IntlProvider.d.ts +2 -16
- package/dist/react/IntlProviderProps.d.ts +15 -0
- package/dist/react/getIntlContextValue.d.ts +18 -0
- package/dist/react/use-intl.esm.js +6 -25
- package/dist/react/use-intl.esm.js.map +1 -1
- package/dist/react/use-intl.esm10.js +44 -0
- package/dist/react/use-intl.esm10.js.map +1 -0
- package/dist/react/use-intl.esm2.js +4 -22
- package/dist/react/use-intl.esm2.js.map +1 -1
- package/dist/react/use-intl.esm3.js +1 -1
- package/dist/react/use-intl.esm4.js +46 -4
- package/dist/react/use-intl.esm4.js.map +1 -1
- package/dist/react/use-intl.esm5.js +17 -41
- package/dist/react/use-intl.esm5.js.map +1 -1
- package/dist/react/use-intl.esm6.js +1 -1
- package/dist/react/use-intl.esm7.js.map +1 -1
- package/dist/react/use-intl.esm8.js +26 -8
- package/dist/react/use-intl.esm8.js.map +1 -1
- package/dist/react/use-intl.esm9.js +9 -38
- package/dist/react/use-intl.esm9.js.map +1 -1
- package/dist/react/useIntlContext.d.ts +1 -1
- package/dist/src/core/createBaseTranslator.js +11 -7
- package/dist/src/core/createBaseTranslator.js.map +1 -1
- package/dist/src/core/createIntl.js +2 -2
- package/dist/src/core/createIntl.js.map +1 -1
- package/dist/src/core/createTranslatorImpl.js +1 -1
- package/dist/src/core/createTranslatorImpl.js.map +1 -1
- package/dist/src/react/IntlContext.d.ts +2 -19
- package/dist/src/react/IntlContext.js.map +1 -1
- package/dist/src/react/IntlContextValue.d.ts +19 -0
- package/dist/src/react/IntlContextValue.js +2 -0
- package/dist/src/react/IntlContextValue.js.map +1 -0
- package/dist/src/react/IntlProvider.d.ts +2 -16
- package/dist/src/react/IntlProvider.js +4 -13
- package/dist/src/react/IntlProvider.js.map +1 -1
- package/dist/src/react/IntlProviderProps.d.ts +15 -0
- package/dist/src/react/IntlProviderProps.js +2 -0
- package/dist/src/react/IntlProviderProps.js.map +1 -0
- package/dist/src/react/getIntlContextValue.d.ts +18 -0
- package/dist/src/react/getIntlContextValue.js +21 -0
- package/dist/src/react/getIntlContextValue.js.map +1 -0
- package/dist/src/react/useIntlContext.d.ts +1 -1
- package/dist/src/react/useIntlContext.js +1 -1
- package/dist/src/react/useIntlContext.js.map +1 -1
- package/dist/use-intl.cjs.development.js +37 -28
- package/dist/use-intl.cjs.development.js.map +1 -1
- package/dist/use-intl.cjs.production.min.js +1 -1
- package/dist/use-intl.cjs.production.min.js.map +1 -1
- package/dist/use-intl.esm.js +3 -3
- package/package.json +2 -3
- package/src/core/createBaseTranslator.tsx +11 -7
- package/src/core/createIntl.tsx +2 -2
- package/src/core/createTranslatorImpl.tsx +1 -1
- package/src/react/IntlContext.tsx +2 -20
- package/src/react/IntlContextValue.tsx +21 -0
- package/src/react/IntlProvider.tsx +5 -36
- package/src/react/IntlProviderProps.tsx +17 -0
- package/src/react/getIntlContextValue.tsx +30 -0
- package/src/react/useIntlContext.tsx +1 -1
- package/LICENSE +0 -21
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,490 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
## 2.10.1 (2022-12-09)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package use-intl
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# 2.10.0 (2022-12-09)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Features
|
|
18
|
+
|
|
19
|
+
* Add support for using `next-intl` in the `app` folder with Next.js 13 (see https://next-intl-docs.vercel.app/docs/next-13, [#144](https://github.com/amannn/next-intl/tree/main/packages/use-intl/issues/144)) ([18c94d6](https://github.com/amannn/next-intl/tree/main/packages/use-intl/commit/18c94d623a05afa7710fea83360f12f9811fb38d))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
## 2.9.2 (2022-12-08)
|
|
26
|
+
|
|
27
|
+
**Note:** Version bump only for package use-intl
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
## 2.9.1 (2022-11-03)
|
|
34
|
+
|
|
35
|
+
**Note:** Version bump only for package use-intl
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
# 2.9.0 (2022-10-27)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
### Features
|
|
45
|
+
|
|
46
|
+
* Next.js 13 compatibility ([#140](https://github.com/amannn/next-intl/tree/main/packages/use-intl/issues/140)) ([65326a0](https://github.com/amannn/next-intl/tree/main/packages/use-intl/commit/65326a0b47980f260df466a283a6e7a0aa5e1cd0)), closes [#139](https://github.com/amannn/next-intl/tree/main/packages/use-intl/issues/139)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
# 2.8.0 (2022-10-18)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
### Features
|
|
56
|
+
|
|
57
|
+
* Provide `createTranslator` and `createIntl` by extracting a React-agnostic core library. Thanks to David Brands from Marvia for sponsoring the work on this feature, participating in discussion and providing feedback! ([#137](https://github.com/amannn/next-intl/tree/main/packages/use-intl/issues/137)) ([91f7489](https://github.com/amannn/next-intl/tree/main/packages/use-intl/commit/91f748972008b8587553b48aa36c95d7348b4b0c))
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
## 2.7.6 (2022-09-22)
|
|
64
|
+
|
|
65
|
+
**Note:** Version bump only for package use-intl
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
## 2.7.5 (2022-08-30)
|
|
72
|
+
|
|
73
|
+
**Note:** Version bump only for package use-intl
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
## 2.7.4 (2022-05-30)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
### Bug Fixes
|
|
83
|
+
|
|
84
|
+
* Adapt TypeScript validation to work with messages files that only have a single top-level namespace ([#115](https://github.com/amannn/next-intl/tree/main/packages/use-intl/issues/115)) ([cf0b83e](https://github.com/amannn/next-intl/tree/main/packages/use-intl/commit/cf0b83e3a591cfe87e17537c3ca0c7000cc70b1e))
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
## 2.7.3 (2022-05-20)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
### Bug Fixes
|
|
94
|
+
|
|
95
|
+
* Add back the ability to render the provider without messages ([#113](https://github.com/amannn/next-intl/tree/main/packages/use-intl/issues/113)) ([8395822](https://github.com/amannn/next-intl/tree/main/packages/use-intl/commit/8395822fa17cd0a04b88f8edce3b20e5e613fc78))
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
## 2.7.2 (2022-05-10)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
### Bug Fixes
|
|
105
|
+
|
|
106
|
+
* Enable tree-shaking ([#108](https://github.com/amannn/next-intl/tree/main/packages/use-intl/issues/108)) ([157b0e2](https://github.com/amannn/next-intl/tree/main/packages/use-intl/commit/157b0e28376055e7e34e86007c51d008c8e214aa))
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
## 2.7.1 (2022-04-28)
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
### Bug Fixes
|
|
116
|
+
|
|
117
|
+
* Allow null message values ([#110](https://github.com/amannn/next-intl/tree/main/packages/use-intl/issues/110)) ([14ae8ff](https://github.com/amannn/next-intl/tree/main/packages/use-intl/commit/14ae8ffdf1b295873f14081e2c3709d0f9bd2b9e))
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
# 2.7.0 (2022-04-28)
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
### Features
|
|
127
|
+
|
|
128
|
+
* Warn for invalid namespace keys ([#106](https://github.com/amannn/next-intl/tree/main/packages/use-intl/issues/106)) ([e86ab28](https://github.com/amannn/next-intl/tree/main/packages/use-intl/commit/e86ab28b9180b866ce1a0a9173355d4b686b7d07))
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
# 2.6.0 (2022-04-08)
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
### Features
|
|
138
|
+
|
|
139
|
+
* Support React 18 ([#98](https://github.com/amannn/next-intl/tree/main/packages/use-intl/issues/98)) ([38614eb](https://github.com/amannn/next-intl/tree/main/packages/use-intl/commit/38614eb9c6d6fb96704424d7f3ff8a67a24b789e))
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
# 2.5.0 (2022-04-01)
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
### Features
|
|
149
|
+
|
|
150
|
+
* Type safe messages ([#93](https://github.com/amannn/next-intl/tree/main/packages/use-intl/issues/93)) ([13b49b1](https://github.com/amannn/next-intl/tree/main/packages/use-intl/commit/13b49b138bc0ec3adbe661af6a70dfabfe7e86b0))
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
## 2.4.1 (2022-03-24)
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
### Bug Fixes
|
|
164
|
+
|
|
165
|
+
* Overwrite prerelease ([6caf5c4](https://github.com/amannn/next-intl/tree/main/packages/use-intl/commit/6caf5c48a35179f802503bc6580469187765c837))
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
# [2.4.0](https://github.com/amannn/next-intl/tree/main/packages/use-intl/compare/v2.3.5...v2.4.0) (2022-02-08)
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
### Features
|
|
175
|
+
|
|
176
|
+
* Default translation values ([#86](https://github.com/amannn/next-intl/tree/main/packages/use-intl/issues/86)) ([0ed5e70](https://github.com/amannn/next-intl/tree/main/packages/use-intl/commit/0ed5e70ffc57dcdb1b7b9270dbce9e8475b3f478))
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
## 2.3.5 (2022-01-19)
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
### Bug Fixes
|
|
186
|
+
|
|
187
|
+
* Support identical wrappers with identical text content in rich text ([#80](https://github.com/amannn/next-intl/tree/main/packages/use-intl/issues/80)) ([b35bb9f](https://github.com/amannn/next-intl/tree/main/packages/use-intl/commit/b35bb9ffc5fa56c6260b6b424be3cd875f199aef))
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
## 2.3.4 (2022-01-04)
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
### Bug Fixes
|
|
197
|
+
|
|
198
|
+
* Allow usage outside of Next.js (e.g. Jest and Storybook) ([#76](https://github.com/amannn/next-intl/tree/main/packages/use-intl/issues/76)) ([7c6925b](https://github.com/amannn/next-intl/tree/main/packages/use-intl/commit/7c6925b39338be95c1c940c67a1ae2f5e3f85cdd))
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
## 2.3.3 (2021-12-23)
|
|
205
|
+
|
|
206
|
+
**Note:** Version bump only for package use-intl
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
## 2.3.2 (2021-12-23)
|
|
213
|
+
|
|
214
|
+
**Note:** Version bump only for package use-intl
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
## 2.3.1 (2021-12-23)
|
|
221
|
+
|
|
222
|
+
**Note:** Version bump only for package use-intl
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
# 2.3.0 (2021-11-24)
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
### Features
|
|
232
|
+
|
|
233
|
+
* Add `useLocale` and `useTimeZone` ([#67](https://github.com/amannn/next-intl/tree/main/packages/use-intl/issues/67)) ([7833f4a](https://github.com/amannn/next-intl/tree/main/packages/use-intl/commit/7833f4adc1aadc937cbaa550a968ef6f7b4f5ee1))
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
## 2.2.1 (2021-11-23)
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
### Bug Fixes
|
|
243
|
+
|
|
244
|
+
* Clearer error message when no messages are provided ([#66](https://github.com/amannn/next-intl/tree/main/packages/use-intl/issues/66)) ([742729a](https://github.com/amannn/next-intl/tree/main/packages/use-intl/commit/742729aaddd63367efc2b79ef0cdf93545abdfb0))
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
# 2.2.0 (2021-11-02)
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
### Features
|
|
254
|
+
|
|
255
|
+
* TypeScript improvements: Use enum type for `style` of `NumberFormatOptions`, only allow passing React children to messages rendered with `t.rich` and update `tslib` ([#63](https://github.com/amannn/next-intl/tree/main/packages/use-intl/issues/63)) ([d73e935](https://github.com/amannn/next-intl/tree/main/packages/use-intl/commit/d73e9358bf13c87c0a653bd9fbed35e41548ff1d))
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
## 2.1.1 (2021-10-28)
|
|
262
|
+
|
|
263
|
+
**Note:** Version bump only for package use-intl
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
# 2.1.0 (2021-10-27)
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
### Features
|
|
273
|
+
|
|
274
|
+
* Support Next.js 12 ([#61](https://github.com/amannn/next-intl/tree/main/packages/use-intl/issues/61)) ([0391cc8](https://github.com/amannn/next-intl/tree/main/packages/use-intl/commit/0391cc85d3401bca9df29080a569957f6be93c85))
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
## 2.0.5 (2021-09-28)
|
|
281
|
+
|
|
282
|
+
**Note:** Version bump only for package use-intl
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
## 2.0.4 (2021-09-28)
|
|
289
|
+
|
|
290
|
+
**Note:** Version bump only for package use-intl
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
## 2.0.3 (2021-09-17)
|
|
297
|
+
|
|
298
|
+
**Note:** Version bump only for package use-intl
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
## 2.0.2 (2021-09-17)
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
### Bug Fixes
|
|
308
|
+
|
|
309
|
+
* Render correct messages when the namespace changes in `useTranslations` ([#58](https://github.com/amannn/next-intl/tree/main/packages/use-intl/issues/58)) ([b8f7dab](https://github.com/amannn/next-intl/tree/main/packages/use-intl/commit/b8f7dab0e3a213a91bdcd7929547cd01ba0b5f54))
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
## 2.0.1 (2021-09-04)
|
|
316
|
+
|
|
317
|
+
**Note:** Version bump only for package use-intl
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
# 2.0.0 (2021-08-26)
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
* feat!: Use a separate API for rich text formatting to avoid type casting in TypeScript #54 ([4c13a64](https://github.com/amannn/next-intl/tree/main/packages/use-intl/commit/4c13a644ce99992d9e57887afe35a09b8e3d6572)), closes [#54](https://github.com/amannn/next-intl/tree/main/packages/use-intl/issues/54)
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
### BREAKING CHANGES
|
|
330
|
+
|
|
331
|
+
* Instead of using the `t` function for formatting both regular messages and rich text, this function will only work for regular messages now. For rich text you can use `t.rich` instead now.
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
## 1.5.1 (2021-08-13)
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
### Bug Fixes
|
|
341
|
+
|
|
342
|
+
* Improve API for rendering raw messages and add docs ([#51](https://github.com/amannn/next-intl/tree/main/packages/use-intl/issues/51)) ([19f4a7e](https://github.com/amannn/next-intl/tree/main/packages/use-intl/commit/19f4a7e4e81e1cff78dc7e3f337dce69800be280))
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
# 1.5.0 (2021-08-10)
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
### Features
|
|
352
|
+
|
|
353
|
+
* Add flag to return raw messages ([#48](https://github.com/amannn/next-intl/tree/main/packages/use-intl/issues/48)) ([b34e19f](https://github.com/amannn/next-intl/tree/main/packages/use-intl/commit/b34e19ff618308b7d0c01e7969975215d96ff608))
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
## 1.4.7 (2021-08-02)
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
### Bug Fixes
|
|
363
|
+
|
|
364
|
+
* Adjust default for `onError` of the provider to log errors correctly ([#46](https://github.com/amannn/next-intl/tree/main/packages/use-intl/issues/46)) ([d0a1986](https://github.com/amannn/next-intl/tree/main/packages/use-intl/commit/d0a1986905e30acac40630e9ea6d099caad617fb))
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
## 1.4.6 (2021-08-02)
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
### Bug Fixes
|
|
374
|
+
|
|
375
|
+
* Use `timeZone` in translation function from `useTranslations` ([#45](https://github.com/amannn/next-intl/tree/main/packages/use-intl/issues/45)) ([ebf75f2](https://github.com/amannn/next-intl/tree/main/packages/use-intl/commit/ebf75f2add0ddc46f89768e9481bb16c56f94720))
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
## 1.4.5 (2021-07-26)
|
|
382
|
+
|
|
383
|
+
**Note:** Version bump only for package use-intl
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
## 1.4.4 (2021-07-08)
|
|
390
|
+
|
|
391
|
+
**Note:** Version bump only for package use-intl
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
## 1.4.3 (2021-07-08)
|
|
398
|
+
|
|
399
|
+
**Note:** Version bump only for package use-intl
|
|
400
|
+
|
|
401
|
+
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
## [1.4.2](https://github.com/amannn/next-intl/tree/main/packages/use-intl/compare/v1.4.1...v1.4.2) (2021-06-16)
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
### Bug Fixes
|
|
409
|
+
|
|
410
|
+
* Don't require `react-dom` as a peer dependency ([#39](https://github.com/amannn/next-intl/tree/main/packages/use-intl/issues/39)) ([39edfcd](https://github.com/amannn/next-intl/tree/main/packages/use-intl/commit/39edfcd9091e09570fc2152cda6a1e9ae5e7c210))
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
## 1.3.11 (2021-05-07)
|
|
417
|
+
|
|
418
|
+
**Note:** Version bump only for package use-intl
|
|
419
|
+
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
## 1.3.10 (2021-05-02)
|
|
425
|
+
|
|
426
|
+
**Note:** Version bump only for package use-intl
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
## 1.3.9 (2021-05-02)
|
|
433
|
+
|
|
434
|
+
**Note:** Version bump only for package use-intl
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
## 1.3.8 (2021-03-26)
|
|
441
|
+
|
|
442
|
+
**Note:** Version bump only for package use-intl
|
|
443
|
+
|
|
444
|
+
|
|
445
|
+
|
|
446
|
+
|
|
447
|
+
|
|
448
|
+
## 1.3.7 (2021-02-12)
|
|
449
|
+
|
|
450
|
+
**Note:** Version bump only for package use-intl
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
## 1.3.6 (2021-02-09)
|
|
457
|
+
|
|
458
|
+
**Note:** Version bump only for package use-intl
|
|
459
|
+
|
|
460
|
+
|
|
461
|
+
|
|
462
|
+
|
|
463
|
+
|
|
464
|
+
## 1.3.5 (2021-02-09)
|
|
465
|
+
|
|
466
|
+
**Note:** Version bump only for package use-intl
|
|
467
|
+
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+
|
|
471
|
+
|
|
472
|
+
## 1.3.4 (2021-02-09)
|
|
473
|
+
|
|
474
|
+
**Note:** Version bump only for package use-intl
|
|
475
|
+
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
|
|
479
|
+
|
|
480
|
+
## [1.3.3](https://github.com/amannn/next-intl/tree/main/packages/use-intl/compare/v1.3.2...v1.3.3) (2021-02-09)
|
|
481
|
+
|
|
482
|
+
|
|
483
|
+
### Bug Fixes
|
|
484
|
+
|
|
485
|
+
* Update DateTimeFormatOptions ([#29](https://github.com/amannn/next-intl/tree/main/packages/use-intl/issues/29)) ([91a8f52](https://github.com/amannn/next-intl/tree/main/packages/use-intl/commit/91a8f5216a9ef2a0e76be6e3e8bd706f5c7496a3))
|
|
486
|
+
|
|
487
|
+
|
|
488
|
+
## Previous releases
|
|
489
|
+
|
|
490
|
+
See [next-intl changelog](https://github.com/amannn/next-intl/blob/main/CHANGELOG.md).
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose, extends as _extends } from '../_virtual/use-intl.esm.js';
|
|
2
|
-
import createTranslatorImpl from './use-intl.
|
|
3
|
-
import { defaultOnError, defaultGetMessageFallback } from './use-intl.
|
|
2
|
+
import createTranslatorImpl from './use-intl.esm5.js';
|
|
3
|
+
import { defaultOnError, defaultGetMessageFallback } from './use-intl.esm4.js';
|
|
4
4
|
|
|
5
5
|
var _excluded = ["onError", "getMessageFallback", "messages", "namespace"];
|
|
6
6
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { extends as _extends } from '../_virtual/use-intl.esm.js';
|
|
2
2
|
import IntlError, { IntlErrorCode } from './use-intl.esm.js';
|
|
3
|
-
import { defaultOnError } from './use-intl.
|
|
3
|
+
import { defaultOnError } from './use-intl.esm4.js';
|
|
4
4
|
|
|
5
5
|
var MINUTE = 60;
|
|
6
6
|
var HOUR = MINUTE * 60;
|
|
@@ -60,7 +60,7 @@ function createIntl(_ref) {
|
|
|
60
60
|
options = typeFormats == null ? void 0 : typeFormats[formatName];
|
|
61
61
|
|
|
62
62
|
if (!options) {
|
|
63
|
-
var error = new IntlError(IntlErrorCode.MISSING_FORMAT, process.env.NODE_ENV !==
|
|
63
|
+
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);
|
|
64
64
|
onError(error);
|
|
65
65
|
throw error;
|
|
66
66
|
}
|
|
@@ -123,7 +123,7 @@ function createIntl(_ref) {
|
|
|
123
123
|
if (globalNow) {
|
|
124
124
|
now = globalNow;
|
|
125
125
|
} else {
|
|
126
|
-
throw new Error(process.env.NODE_ENV !==
|
|
126
|
+
throw new Error(process.env.NODE_ENV !== 'production' ? "The `now` parameter wasn't provided to `formatRelativeTime` and there was no global fallback configured on the provider." : undefined);
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
129
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-intl.esm3.js","sources":["../../src/core/createIntl.tsx"],"sourcesContent":["import DateTimeFormatOptions from './DateTimeFormatOptions';\nimport Formats from './Formats';\nimport IntlError, {IntlErrorCode} from './IntlError';\nimport NumberFormatOptions from './NumberFormatOptions';\nimport {defaultOnError} from './defaults';\n\nconst MINUTE = 60;\nconst HOUR = MINUTE * 60;\nconst DAY = HOUR * 24;\nconst WEEK = DAY * 7;\nconst MONTH = DAY * (365 / 12); // Approximation\nconst YEAR = DAY * 365;\n\nfunction getRelativeTimeFormatConfig(seconds: number) {\n const absValue = Math.abs(seconds);\n let value, unit: Intl.RelativeTimeFormatUnit;\n\n // We have to round the resulting values, as `Intl.RelativeTimeFormat`\n // will include fractions like '2.1 hours ago'.\n\n if (absValue < MINUTE) {\n unit = 'second';\n value = Math.round(seconds);\n } else if (absValue < HOUR) {\n unit = 'minute';\n value = Math.round(seconds / MINUTE);\n } else if (absValue < DAY) {\n unit = 'hour';\n value = Math.round(seconds / HOUR);\n } else if (absValue < WEEK) {\n unit = 'day';\n value = Math.round(seconds / DAY);\n } else if (absValue < MONTH) {\n unit = 'week';\n value = Math.round(seconds / WEEK);\n } else if (absValue < YEAR) {\n unit = 'month';\n value = Math.round(seconds / MONTH);\n } else {\n unit = 'year';\n value = Math.round(seconds / YEAR);\n }\n\n return {value, unit};\n}\n\ntype Props = {\n locale: string;\n timeZone?: string;\n onError?(error: IntlError): void;\n formats?: Partial<Formats>;\n now?: Date;\n};\n\nexport default function createIntl({\n formats,\n locale,\n now: globalNow,\n onError = defaultOnError,\n timeZone\n}: Props) {\n function resolveFormatOrOptions<Options>(\n typeFormats: Record<string, Options> | undefined,\n formatOrOptions?: string | Options\n ) {\n let options;\n if (typeof formatOrOptions === 'string') {\n const formatName = formatOrOptions;\n options = typeFormats?.[formatName];\n\n if (!options) {\n const error = new IntlError(\n IntlErrorCode.MISSING_FORMAT,\n __DEV__\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 formatDateTime(\n /** If a number is supplied, this is interpreted as a UTC timestamp. */\n value: Date | number,\n /** If a time zone is supplied, the `value` is converted to that time zone.\n * Otherwise the user time zone will be used. */\n formatOrOptions?: string | DateTimeFormatOptions\n ) {\n return getFormattedValue(\n value,\n formatOrOptions,\n formats?.dateTime,\n (options) => {\n if (timeZone && !options?.timeZone) {\n options = {...options, timeZone};\n }\n\n return new Intl.DateTimeFormat(locale, options).format(value);\n }\n );\n }\n\n function formatNumber(\n value: number,\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 formatRelativeTime(\n /** The date time that needs to be formatted. */\n date: number | Date,\n /** The reference point in time to which `date` will be formatted in relation to. */\n now?: number | Date\n ) {\n try {\n if (!now) {\n if (globalNow) {\n now = globalNow;\n } else {\n throw new Error(\n __DEV__\n ? `The \\`now\\` parameter wasn't provided to \\`formatRelativeTime\\` and there was no global fallback configured on the provider.`\n : undefined\n );\n }\n }\n\n const dateDate = date instanceof Date ? date : new Date(date);\n const nowDate = now instanceof Date ? now : new Date(now);\n\n const seconds = (dateDate.getTime() - nowDate.getTime()) / 1000;\n const {unit, value} = getRelativeTimeFormatConfig(seconds);\n\n return new Intl.RelativeTimeFormat(locale, {\n numeric: 'auto'\n }).format(value, unit);\n } catch (error) {\n onError(\n new IntlError(IntlErrorCode.FORMATTING_ERROR, (error as Error).message)\n );\n return String(date);\n }\n }\n\n return {formatDateTime, formatNumber, formatRelativeTime};\n}\n"],"names":["MINUTE","HOUR","DAY","WEEK","MONTH","YEAR","getRelativeTimeFormatConfig","seconds","absValue","Math","abs","value","unit","round","createIntl","formats","locale","globalNow","now","onError","defaultOnError","timeZone","resolveFormatOrOptions","typeFormats","formatOrOptions","options","formatName","error","IntlError","IntlErrorCode","MISSING_FORMAT","undefined","getFormattedValue","formatter","String","FORMATTING_ERROR","message","formatDateTime","dateTime","Intl","DateTimeFormat","format","formatNumber","number","NumberFormat","formatRelativeTime","date","Error","dateDate","Date","nowDate","getTime","RelativeTimeFormat","numeric"],"mappings":";;;;AAMA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J,CAAS/B,GAAT,CAA5C,CAAA;AAEA,MAAA,IAAMX,OAAO,GAAG,CAACyC,QAAQ,CAACG,OAAT,EAAqBD,GAAAA,OAAO,CAACC,OAAR,EAAtB,IAA2C,IAA3D,CAAA;;AACA,MAAsB7C,IAAAA,qBAAAA,GAAAA,2BAA2B,CAACC,OAAD,CAAjD;AAAA,UAAOK,IAAP,yBAAOA,IAAP;AAAA,UAAaD,KAAb,yBAAaA,KAAb,CAAA;;AAEA,MAAA,OAAO,IAAI4B,IAAI,CAACa,kBAAT,CAA4BpC,MAA5B,EAAoC;AACzCqC,QAAAA,OAAO,EAAE,MAAA;AADgC,OAApC,EAEJZ,MAFI,CAEG9B,KAFH,EAEUC,IAFV,CAAP,CAAA;AAGD,KAtBD,CAsBE,OAAOe,KAAP,EAAc;AACdR,MAAAA,OAAO,CACL,IAAIS,SAAJ,CAAcC,aAAa,CAACM,gBAA5B,EAA+CR,KAAe,CAACS,OAA/D,CADK,CAAP,CAAA;AAGA,MAAOF,OAAAA,MAAM,CAACY,IAAD,CAAb,CAAA;AACD,KAAA;AACF,GAAA;;AAED,EAAO,OAAA;AAACT,IAAAA,cAAc,EAAdA,cAAD;AAAiBK,IAAAA,YAAY,EAAZA,YAAjB;AAA+BG,IAAAA,kBAAkB,EAAlBA,kBAAAA;AAA/B,GAAP,CAAA;AACD;;;;"}
|
|
1
|
+
{"version":3,"file":"use-intl.esm3.js","sources":["../../src/core/createIntl.tsx"],"sourcesContent":["import DateTimeFormatOptions from './DateTimeFormatOptions';\nimport Formats from './Formats';\nimport IntlError, {IntlErrorCode} from './IntlError';\nimport NumberFormatOptions from './NumberFormatOptions';\nimport {defaultOnError} from './defaults';\n\nconst MINUTE = 60;\nconst HOUR = MINUTE * 60;\nconst DAY = HOUR * 24;\nconst WEEK = DAY * 7;\nconst MONTH = DAY * (365 / 12); // Approximation\nconst YEAR = DAY * 365;\n\nfunction getRelativeTimeFormatConfig(seconds: number) {\n const absValue = Math.abs(seconds);\n let value, unit: Intl.RelativeTimeFormatUnit;\n\n // We have to round the resulting values, as `Intl.RelativeTimeFormat`\n // will include fractions like '2.1 hours ago'.\n\n if (absValue < MINUTE) {\n unit = 'second';\n value = Math.round(seconds);\n } else if (absValue < HOUR) {\n unit = 'minute';\n value = Math.round(seconds / MINUTE);\n } else if (absValue < DAY) {\n unit = 'hour';\n value = Math.round(seconds / HOUR);\n } else if (absValue < WEEK) {\n unit = 'day';\n value = Math.round(seconds / DAY);\n } else if (absValue < MONTH) {\n unit = 'week';\n value = Math.round(seconds / WEEK);\n } else if (absValue < YEAR) {\n unit = 'month';\n value = Math.round(seconds / MONTH);\n } else {\n unit = 'year';\n value = Math.round(seconds / YEAR);\n }\n\n return {value, unit};\n}\n\ntype Props = {\n locale: string;\n timeZone?: string;\n onError?(error: IntlError): void;\n formats?: Partial<Formats>;\n now?: Date;\n};\n\nexport default function createIntl({\n formats,\n locale,\n now: globalNow,\n onError = defaultOnError,\n timeZone\n}: Props) {\n function resolveFormatOrOptions<Options>(\n typeFormats: Record<string, Options> | undefined,\n formatOrOptions?: string | Options\n ) {\n let options;\n if (typeof formatOrOptions === 'string') {\n const formatName = formatOrOptions;\n options = typeFormats?.[formatName];\n\n if (!options) {\n const error = new IntlError(\n IntlErrorCode.MISSING_FORMAT,\n process.env.NODE_ENV !== 'production'\n ? `Format \\`${formatName}\\` is not available. You can configure it on the provider or provide custom options.`\n : undefined\n );\n onError(error);\n throw error;\n }\n } else {\n options = formatOrOptions;\n }\n\n return options;\n }\n\n function getFormattedValue<Value, Options>(\n value: Value,\n formatOrOptions: string | Options | undefined,\n typeFormats: Record<string, Options> | undefined,\n formatter: (options?: Options) => string\n ) {\n let options;\n try {\n options = resolveFormatOrOptions(typeFormats, formatOrOptions);\n } catch (error) {\n return String(value);\n }\n\n try {\n return formatter(options);\n } catch (error) {\n onError(\n new IntlError(IntlErrorCode.FORMATTING_ERROR, (error as Error).message)\n );\n return String(value);\n }\n }\n\n function formatDateTime(\n /** If a number is supplied, this is interpreted as a UTC timestamp. */\n value: Date | number,\n /** If a time zone is supplied, the `value` is converted to that time zone.\n * Otherwise the user time zone will be used. */\n formatOrOptions?: string | DateTimeFormatOptions\n ) {\n return getFormattedValue(\n value,\n formatOrOptions,\n formats?.dateTime,\n (options) => {\n if (timeZone && !options?.timeZone) {\n options = {...options, timeZone};\n }\n\n return new Intl.DateTimeFormat(locale, options).format(value);\n }\n );\n }\n\n function formatNumber(\n value: number,\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 formatRelativeTime(\n /** The date time that needs to be formatted. */\n date: number | Date,\n /** The reference point in time to which `date` will be formatted in relation to. */\n now?: number | Date\n ) {\n try {\n if (!now) {\n if (globalNow) {\n now = globalNow;\n } else {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? `The \\`now\\` parameter wasn't provided to \\`formatRelativeTime\\` and there was no global fallback configured on the provider.`\n : undefined\n );\n }\n }\n\n const dateDate = date instanceof Date ? date : new Date(date);\n const nowDate = now instanceof Date ? now : new Date(now);\n\n const seconds = (dateDate.getTime() - nowDate.getTime()) / 1000;\n const {unit, value} = getRelativeTimeFormatConfig(seconds);\n\n return new Intl.RelativeTimeFormat(locale, {\n numeric: 'auto'\n }).format(value, unit);\n } catch (error) {\n onError(\n new IntlError(IntlErrorCode.FORMATTING_ERROR, (error as Error).message)\n );\n return String(date);\n }\n }\n\n return {formatDateTime, formatNumber, formatRelativeTime};\n}\n"],"names":["MINUTE","HOUR","DAY","WEEK","MONTH","YEAR","getRelativeTimeFormatConfig","seconds","absValue","Math","abs","value","unit","round","createIntl","formats","locale","globalNow","now","onError","defaultOnError","timeZone","resolveFormatOrOptions","typeFormats","formatOrOptions","options","formatName","error","IntlError","IntlErrorCode","MISSING_FORMAT","process","env","NODE_ENV","undefined","getFormattedValue","formatter","String","FORMATTING_ERROR","message","formatDateTime","dateTime","Intl","DateTimeFormat","format","formatNumber","number","NumberFormat","formatRelativeTime","date","Error","dateDate","Date","nowDate","getTime","RelativeTimeFormat","numeric"],"mappings":";;;;AAMA,IAAMA,MAAM,GAAG,EAAf,CAAA;AACA,IAAMC,IAAI,GAAGD,MAAM,GAAG,EAAtB,CAAA;AACA,IAAME,GAAG,GAAGD,IAAI,GAAG,EAAnB,CAAA;AACA,IAAME,IAAI,GAAGD,GAAG,GAAG,CAAnB,CAAA;AACA,IAAME,KAAK,GAAGF,GAAG,IAAI,MAAM,EAAV,CAAjB;;AACA,IAAMG,IAAI,GAAGH,GAAG,GAAG,GAAnB,CAAA;;AAEA,SAASI,2BAAT,CAAqCC,OAArC,EAAoD;AAClD,EAAA,IAAMC,QAAQ,GAAGC,IAAI,CAACC,GAAL,CAASH,OAAT,CAAjB,CAAA;AACA,EAAA,IAAII,KAAJ,EAAWC,IAAX,CAFkD;AAKlD;;AAEA,EAAIJ,IAAAA,QAAQ,GAAGR,MAAf,EAAuB;AACrBY,IAAAA,IAAI,GAAG,QAAP,CAAA;AACAD,IAAAA,KAAK,GAAGF,IAAI,CAACI,KAAL,CAAWN,OAAX,CAAR,CAAA;AACD,GAHD,MAGO,IAAIC,QAAQ,GAAGP,IAAf,EAAqB;AAC1BW,IAAAA,IAAI,GAAG,QAAP,CAAA;AACAD,IAAAA,KAAK,GAAGF,IAAI,CAACI,KAAL,CAAWN,OAAO,GAAGP,MAArB,CAAR,CAAA;AACD,GAHM,MAGA,IAAIQ,QAAQ,GAAGN,GAAf,EAAoB;AACzBU,IAAAA,IAAI,GAAG,MAAP,CAAA;AACAD,IAAAA,KAAK,GAAGF,IAAI,CAACI,KAAL,CAAWN,OAAO,GAAGN,IAArB,CAAR,CAAA;AACD,GAHM,MAGA,IAAIO,QAAQ,GAAGL,IAAf,EAAqB;AAC1BS,IAAAA,IAAI,GAAG,KAAP,CAAA;AACAD,IAAAA,KAAK,GAAGF,IAAI,CAACI,KAAL,CAAWN,OAAO,GAAGL,GA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AAT,CAA/C,CAAA;AACA,MAAA,IAAMI,OAAO,GAAGnC,GAAG,YAAYkC,IAAf,GAAsBlC,GAAtB,GAA4B,IAAIkC,IAAJ,CAASlC,GAAT,CAA5C,CAAA;AAEA,MAAA,IAAMX,OAAO,GAAG,CAAC4C,QAAQ,CAACG,OAAT,EAAqBD,GAAAA,OAAO,CAACC,OAAR,EAAtB,IAA2C,IAA3D,CAAA;;AACA,MAAsBhD,IAAAA,qBAAAA,GAAAA,2BAA2B,CAACC,OAAD,CAAjD;AAAA,UAAOK,IAAP,yBAAOA,IAAP;AAAA,UAAaD,KAAb,yBAAaA,KAAb,CAAA;;AAEA,MAAA,OAAO,IAAI+B,IAAI,CAACa,kBAAT,CAA4BvC,MAA5B,EAAoC;AACzCwC,QAAAA,OAAO,EAAE,MAAA;AADgC,OAApC,EAEJZ,MAFI,CAEGjC,KAFH,EAEUC,IAFV,CAAP,CAAA;AAGD,KAtBD,CAsBE,OAAOe,KAAP,EAAc;AACdR,MAAAA,OAAO,CACL,IAAIS,SAAJ,CAAcC,aAAa,CAACS,gBAA5B,EAA+CX,KAAe,CAACY,OAA/D,CADK,CAAP,CAAA;AAGA,MAAOF,OAAAA,MAAM,CAACY,IAAD,CAAb,CAAA;AACD,KAAA;AACF,GAAA;;AAED,EAAO,OAAA;AAACT,IAAAA,cAAc,EAAdA,cAAD;AAAiBK,IAAAA,YAAY,EAAZA,YAAjB;AAA+BG,IAAAA,kBAAkB,EAAlBA,kBAAAA;AAA/B,GAAP,CAAA;AACD;;;;"}
|
|
@@ -1,59 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
13
|
-
|
|
14
|
-
// The `namespacePrefix` is part of the type system.
|
|
15
|
-
// See the comment in the function invocation.
|
|
16
|
-
messages = messages[namespacePrefix];
|
|
17
|
-
namespace = resolveNamespace(namespace, namespacePrefix);
|
|
18
|
-
var translator = createBaseTranslator(_extends({}, rest, {
|
|
19
|
-
onError: onError,
|
|
20
|
-
getMessageFallback: getMessageFallback,
|
|
21
|
-
messagesOrError: getMessagesOrError({
|
|
22
|
-
messages: messages,
|
|
23
|
-
namespace: namespace,
|
|
24
|
-
onError: onError
|
|
25
|
-
})
|
|
26
|
-
}));
|
|
27
|
-
var originalRich = translator.rich;
|
|
28
|
-
|
|
29
|
-
function base() {
|
|
30
|
-
return translator.apply(void 0, arguments);
|
|
31
|
-
} // Augment `t.rich` to return plain strings
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
base.rich = function (key,
|
|
35
|
-
/** Key value pairs for values to interpolate into the message. */
|
|
36
|
-
values, formats) {
|
|
37
|
-
// `chunks` is returned as a string when no React element
|
|
38
|
-
// is used, therefore it's safe to cast this type.
|
|
39
|
-
var result = originalRich(key, values, formats); // When only string chunks are provided to the parser, only strings should be returned here.
|
|
40
|
-
|
|
41
|
-
if (typeof result !== 'string') {
|
|
42
|
-
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);
|
|
43
|
-
onError(error);
|
|
44
|
-
return getMessageFallback({
|
|
45
|
-
error: error,
|
|
46
|
-
key: key,
|
|
47
|
-
namespace: namespace
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return result;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
base.raw = translator.raw;
|
|
55
|
-
return base;
|
|
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);
|
|
56
12
|
}
|
|
57
13
|
|
|
58
|
-
export {
|
|
14
|
+
export { defaultGetMessageFallback, defaultOnError };
|
|
59
15
|
//# sourceMappingURL=use-intl.esm4.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-intl.esm4.js","sources":["../../src/core/
|
|
1
|
+
{"version":3,"file":"use-intl.esm4.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,yBAAV,CAAoCC,KAApC,EAIL;AACC,EAAA,OAAO,CAACA,KAAK,CAACC,SAAP,EAAkBD,KAAK,CAACE,GAAxB,CAA6BC,CAAAA,MAA7B,CAAoC,UAACC,IAAD,EAAA;AAAA,IAAUA,OAAAA,IAAI,IAAI,IAAlB,CAAA;AAAA,GAApC,CAA4DC,CAAAA,IAA5D,CAAiE,GAAjE,CAAP,CAAA;AACD,CAAA;AAEK,SAAUC,cAAV,CAAyBC,KAAzB,EAAyC;AAC7CC,EAAAA,OAAO,CAACD,KAAR,CAAcA,KAAd,CAAA,CAAA;AACD;;;;"}
|