next-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 +499 -0
- package/README.md +1 -1
- package/dist/react-server/index.d.ts +5 -7
- package/dist/react-server/useIntl.d.ts +5 -0
- package/dist/react-server/useLocale.d.ts +1 -0
- package/dist/react-server/useNow.d.ts +1 -0
- package/dist/react-server/useTimeZone.d.ts +1 -0
- package/dist/react-server/useTranslations.d.ts +1 -0
- package/dist/server/NextIntlRequestStorage.d.ts +25 -0
- package/dist/server/NextIntlServerProvider.d.ts +2 -0
- package/dist/server/NextRequestStorage.d.ts +14 -0
- package/dist/server/index.d.ts +1 -0
- package/dist/src/react-server/index.d.ts +5 -7
- package/dist/src/react-server/index.js +9 -10
- package/dist/src/react-server/index.js.map +1 -1
- package/dist/src/react-server/useIntl.d.ts +5 -0
- package/dist/src/react-server/useIntl.js +5 -0
- package/dist/src/react-server/useIntl.js.map +1 -0
- package/dist/src/react-server/useLocale.d.ts +1 -0
- package/dist/src/react-server/useLocale.js +5 -0
- package/dist/src/react-server/useLocale.js.map +1 -0
- package/dist/src/react-server/useNow.d.ts +1 -0
- package/dist/src/react-server/useNow.js +5 -0
- package/dist/src/react-server/useNow.js.map +1 -0
- package/dist/src/react-server/useTimeZone.d.ts +1 -0
- package/dist/src/react-server/useTimeZone.js +5 -0
- package/dist/src/react-server/useTimeZone.js.map +1 -0
- package/dist/src/react-server/useTranslations.d.ts +1 -0
- package/dist/src/react-server/useTranslations.js +10 -0
- package/dist/src/react-server/useTranslations.js.map +1 -0
- package/dist/src/server/NextIntlRequestStorage.d.ts +25 -0
- package/dist/src/server/NextIntlRequestStorage.js +46 -0
- package/dist/src/server/NextIntlRequestStorage.js.map +1 -0
- package/dist/src/server/NextIntlServerProvider.d.ts +2 -0
- package/dist/src/server/NextIntlServerProvider.js +15 -0
- package/dist/src/server/NextIntlServerProvider.js.map +1 -0
- package/dist/src/server/NextRequestStorage.d.ts +14 -0
- package/dist/src/server/NextRequestStorage.js +28 -0
- package/dist/src/server/NextRequestStorage.js.map +1 -0
- package/dist/src/server/index.d.ts +1 -0
- package/dist/src/server/index.js +1 -0
- package/dist/src/server/index.js.map +1 -1
- package/package.json +4 -4
- package/src/react-server/index.tsx +10 -13
- package/src/react-server/useIntl.tsx +5 -0
- package/src/react-server/useLocale.tsx +5 -0
- package/src/react-server/useNow.tsx +5 -0
- package/src/react-server/useTimeZone.tsx +5 -0
- package/src/react-server/useTranslations.tsx +12 -0
- package/src/server/NextIntlRequestStorage.tsx +68 -0
- package/src/server/NextIntlServerProvider.tsx +18 -0
- package/src/server/NextRequestStorage.tsx +35 -0
- package/src/server/index.tsx +1 -0
- package/LICENSE +0 -21
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,499 @@
|
|
|
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 next-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/issues/144)) ([18c94d6](https://github.com/amannn/next-intl/commit/18c94d623a05afa7710fea83360f12f9811fb38d))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
## 2.9.2 (2022-12-08)
|
|
26
|
+
|
|
27
|
+
**Note:** Version bump only for package next-intl
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
## 2.9.1 (2022-11-03)
|
|
34
|
+
|
|
35
|
+
**Note:** Version bump only for package next-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/issues/140)) ([65326a0](https://github.com/amannn/next-intl/commit/65326a0b47980f260df466a283a6e7a0aa5e1cd0)), closes [#139](https://github.com/amannn/next-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/issues/137)) ([91f7489](https://github.com/amannn/next-intl/commit/91f748972008b8587553b48aa36c95d7348b4b0c))
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
## 2.7.6 (2022-09-22)
|
|
64
|
+
|
|
65
|
+
**Note:** Version bump only for package next-intl
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
## 2.7.5 (2022-08-30)
|
|
72
|
+
|
|
73
|
+
**Note:** Version bump only for package next-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/issues/115)) ([cf0b83e](https://github.com/amannn/next-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/issues/113)) ([8395822](https://github.com/amannn/next-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/issues/108)) ([157b0e2](https://github.com/amannn/next-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/issues/110)) ([14ae8ff](https://github.com/amannn/next-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/issues/106)) ([e86ab28](https://github.com/amannn/next-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/issues/98)) ([38614eb](https://github.com/amannn/next-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/issues/93)) ([13b49b1](https://github.com/amannn/next-intl/commit/13b49b138bc0ec3adbe661af6a70dfabfe7e86b0))
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
## 2.4.1 (2022-03-24)
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
### Bug Fixes
|
|
162
|
+
|
|
163
|
+
* Overwrite prerelease ([6caf5c4](https://github.com/amannn/next-intl/commit/6caf5c48a35179f802503bc6580469187765c837))
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
# [2.4.0](https://github.com/amannn/next-intl/compare/v2.3.5...v2.4.0) (2022-02-08)
|
|
170
|
+
|
|
171
|
+
**Note:** Version bump only for package next-intl
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
## 2.3.5 (2022-01-19)
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
### Bug Fixes
|
|
181
|
+
|
|
182
|
+
* Support identical wrappers with identical text content in rich text ([#80](https://github.com/amannn/next-intl/issues/80)) ([b35bb9f](https://github.com/amannn/next-intl/commit/b35bb9ffc5fa56c6260b6b424be3cd875f199aef))
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
## 2.3.4 (2022-01-04)
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
### Bug Fixes
|
|
192
|
+
|
|
193
|
+
* Allow usage outside of Next.js (e.g. Jest and Storybook) ([#76](https://github.com/amannn/next-intl/issues/76)) ([7c6925b](https://github.com/amannn/next-intl/commit/7c6925b39338be95c1c940c67a1ae2f5e3f85cdd))
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
## 2.3.3 (2021-12-23)
|
|
200
|
+
|
|
201
|
+
**Note:** Version bump only for package next-intl
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
## 2.3.2 (2021-12-23)
|
|
208
|
+
|
|
209
|
+
**Note:** Version bump only for package next-intl
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
## 2.3.1 (2021-12-23)
|
|
216
|
+
|
|
217
|
+
**Note:** Version bump only for package next-intl
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
# 2.3.0 (2021-11-24)
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
### Features
|
|
227
|
+
|
|
228
|
+
* Add `useLocale` and `useTimeZone` ([#67](https://github.com/amannn/next-intl/issues/67)) ([7833f4a](https://github.com/amannn/next-intl/commit/7833f4adc1aadc937cbaa550a968ef6f7b4f5ee1))
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
## 2.2.1 (2021-11-23)
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
### Bug Fixes
|
|
238
|
+
|
|
239
|
+
* Clearer error message when no messages are provided ([#66](https://github.com/amannn/next-intl/issues/66)) ([742729a](https://github.com/amannn/next-intl/commit/742729aaddd63367efc2b79ef0cdf93545abdfb0))
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
# 2.2.0 (2021-11-02)
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
### Features
|
|
249
|
+
|
|
250
|
+
* 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/issues/63)) ([d73e935](https://github.com/amannn/next-intl/commit/d73e9358bf13c87c0a653bd9fbed35e41548ff1d))
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
## 2.1.1 (2021-10-28)
|
|
257
|
+
|
|
258
|
+
**Note:** Version bump only for package next-intl
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
# 2.1.0 (2021-10-27)
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
### Features
|
|
268
|
+
|
|
269
|
+
* Support Next.js 12 ([#61](https://github.com/amannn/next-intl/issues/61)) ([0391cc8](https://github.com/amannn/next-intl/commit/0391cc85d3401bca9df29080a569957f6be93c85))
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
## 2.0.5 (2021-09-28)
|
|
276
|
+
|
|
277
|
+
**Note:** Version bump only for package next-intl
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
## 2.0.4 (2021-09-28)
|
|
284
|
+
|
|
285
|
+
**Note:** Version bump only for package next-intl
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
## 2.0.3 (2021-09-17)
|
|
292
|
+
|
|
293
|
+
**Note:** Version bump only for package next-intl
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
## 2.0.2 (2021-09-17)
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
### Bug Fixes
|
|
303
|
+
|
|
304
|
+
* Render correct messages when the namespace changes in `useTranslations` ([#58](https://github.com/amannn/next-intl/issues/58)) ([b8f7dab](https://github.com/amannn/next-intl/commit/b8f7dab0e3a213a91bdcd7929547cd01ba0b5f54))
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
## 2.0.1 (2021-09-04)
|
|
311
|
+
|
|
312
|
+
**Note:** Version bump only for package next-intl
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
# 2.0.0 (2021-08-26)
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
* feat!: Use a separate API for rich text formatting to avoid type casting in TypeScript #54 ([4c13a64](https://github.com/amannn/next-intl/commit/4c13a644ce99992d9e57887afe35a09b8e3d6572)), closes [#54](https://github.com/amannn/next-intl/issues/54)
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
### BREAKING CHANGES
|
|
325
|
+
|
|
326
|
+
* 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.
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
## 1.5.1 (2021-08-13)
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
### Bug Fixes
|
|
336
|
+
|
|
337
|
+
* Improve API for rendering raw messages and add docs ([#51](https://github.com/amannn/next-intl/issues/51)) ([19f4a7e](https://github.com/amannn/next-intl/commit/19f4a7e4e81e1cff78dc7e3f337dce69800be280))
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
# 1.5.0 (2021-08-10)
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
### Features
|
|
347
|
+
|
|
348
|
+
* Add flag to return raw messages ([#48](https://github.com/amannn/next-intl/issues/48)) ([b34e19f](https://github.com/amannn/next-intl/commit/b34e19ff618308b7d0c01e7969975215d96ff608))
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
## 1.4.7 (2021-08-02)
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
### Bug Fixes
|
|
358
|
+
|
|
359
|
+
* Adjust default for `onError` of the provider to log errors correctly ([#46](https://github.com/amannn/next-intl/issues/46)) ([d0a1986](https://github.com/amannn/next-intl/commit/d0a1986905e30acac40630e9ea6d099caad617fb))
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
## 1.4.6 (2021-08-02)
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
### Bug Fixes
|
|
369
|
+
|
|
370
|
+
* Use `timeZone` in translation function from `useTranslations` ([#45](https://github.com/amannn/next-intl/issues/45)) ([ebf75f2](https://github.com/amannn/next-intl/commit/ebf75f2add0ddc46f89768e9481bb16c56f94720))
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
## 1.4.5 (2021-07-26)
|
|
377
|
+
|
|
378
|
+
**Note:** Version bump only for package next-intl
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
## 1.4.4 (2021-07-08)
|
|
385
|
+
|
|
386
|
+
**Note:** Version bump only for package next-intl
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
## 1.4.3 (2021-07-08)
|
|
393
|
+
|
|
394
|
+
**Note:** Version bump only for package next-intl
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
## [1.4.2](https://github.com/amannn/next-intl/compare/v1.4.1...v1.4.2) (2021-06-16)
|
|
401
|
+
|
|
402
|
+
|
|
403
|
+
### Bug Fixes
|
|
404
|
+
|
|
405
|
+
* Don't require `react-dom` as a peer dependency ([#39](https://github.com/amannn/next-intl/issues/39)) ([39edfcd](https://github.com/amannn/next-intl/commit/39edfcd9091e09570fc2152cda6a1e9ae5e7c210))
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
## [1.4.1](https://github.com/amannn/next-intl/compare/v1.4.0...v1.4.1) (2021-06-16)
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
### Bug Fixes
|
|
415
|
+
|
|
416
|
+
* Use correct version range for use-intl ([02c33d3](https://github.com/amannn/next-intl/commit/02c33d341794bdcf6ba30ca8325a6a843a684635))
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
# [1.4.0](https://github.com/amannn/next-intl/compare/v1.3.11...v1.4.0) (2021-06-16)
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+
### Features
|
|
426
|
+
|
|
427
|
+
* Support Next.js 11 ([#36](https://github.com/amannn/next-intl/issues/36)) ([fc59871](https://github.com/amannn/next-intl/commit/fc5987156c2a74a9703e39f2b7ee19b84165fd77))
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
|
|
433
|
+
## 1.3.11 (2021-05-07)
|
|
434
|
+
|
|
435
|
+
**Note:** Version bump only for package next-intl
|
|
436
|
+
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
|
|
441
|
+
## 1.3.10 (2021-05-02)
|
|
442
|
+
|
|
443
|
+
**Note:** Version bump only for package next-intl
|
|
444
|
+
|
|
445
|
+
|
|
446
|
+
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
## 1.3.9 (2021-05-02)
|
|
450
|
+
|
|
451
|
+
**Note:** Version bump only for package next-intl
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
## 1.3.8 (2021-03-26)
|
|
458
|
+
|
|
459
|
+
**Note:** Version bump only for package next-intl
|
|
460
|
+
|
|
461
|
+
|
|
462
|
+
|
|
463
|
+
|
|
464
|
+
|
|
465
|
+
## 1.3.7 (2021-02-12)
|
|
466
|
+
|
|
467
|
+
**Note:** Version bump only for package next-intl
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+
|
|
471
|
+
|
|
472
|
+
|
|
473
|
+
## 1.3.6 (2021-02-09)
|
|
474
|
+
|
|
475
|
+
**Note:** Version bump only for package next-intl
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
|
|
479
|
+
|
|
480
|
+
|
|
481
|
+
## 1.3.5 (2021-02-09)
|
|
482
|
+
|
|
483
|
+
**Note:** Version bump only for package next-intl
|
|
484
|
+
|
|
485
|
+
|
|
486
|
+
|
|
487
|
+
|
|
488
|
+
|
|
489
|
+
## 1.3.4 (2021-02-09)
|
|
490
|
+
|
|
491
|
+
**Note:** Version bump only for package next-intl
|
|
492
|
+
|
|
493
|
+
|
|
494
|
+
|
|
495
|
+
|
|
496
|
+
|
|
497
|
+
## [1.3.3](https://github.com/amannn/next-intl/compare/v1.3.2...v1.3.3) (2021-02-09)
|
|
498
|
+
|
|
499
|
+
**Note:** Version bump only for package next-intl
|
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
|
|
14
14
|
<hr />
|
|
15
15
|
|
|
16
|
-
**🚀 New ✨**: `next-intl` is adding support for **Next.js 13** and the [`app` directory](https://beta.nextjs.org/docs/routing/fundamentals). A preview version with support for React Server Components is [now available](https://next-intl-
|
|
16
|
+
**🚀 New ✨**: `next-intl` is adding support for **Next.js 13** and the [`app` directory](https://beta.nextjs.org/docs/routing/fundamentals). A preview version with support for React Server Components is [now available](https://next-intl-docs.vercel.app/docs/next-13) for early adopters.
|
|
17
17
|
|
|
18
18
|
<hr />
|
|
19
19
|
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
+
export { default as useLocale } from './useLocale';
|
|
2
|
+
export { default as useTranslations } from './useTranslations';
|
|
3
|
+
export { default as useIntl } from './useIntl';
|
|
4
|
+
export { default as useNow } from './useNow';
|
|
5
|
+
export { default as useTimeZone } from './useTimeZone';
|
|
1
6
|
export * from 'use-intl/dist/src/core';
|
|
2
|
-
declare function notSupported(): void;
|
|
3
|
-
export declare const IntlProvider: typeof notSupported;
|
|
4
|
-
export declare const useTranslations: typeof notSupported;
|
|
5
|
-
export declare const useIntl: typeof notSupported;
|
|
6
|
-
export declare const useLocale: typeof notSupported;
|
|
7
|
-
export declare const useNow: typeof notSupported;
|
|
8
|
-
export declare const useTimeZone: typeof notSupported;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export default function useIntl(): {
|
|
2
|
+
formatDateTime: (value: number | Date, formatOrOptions?: string | import("use-intl/dist/src/core/DateTimeFormatOptions").default | undefined) => string;
|
|
3
|
+
formatNumber: (value: number, formatOrOptions?: string | import("use-intl").NumberFormatOptions | undefined) => string;
|
|
4
|
+
formatRelativeTime: (date: number | Date, now?: number | Date | undefined) => string;
|
|
5
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function useLocale(): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function useNow(): Date | undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function useTimeZone(): string | undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function useTranslations(namespace?: string): (key: string, ...rest: any) => string;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import 'server-only';
|
|
2
|
+
import IntlContextValue from 'use-intl/dist/src/react/IntlContextValue';
|
|
3
|
+
declare class NextIntlRequestStorage {
|
|
4
|
+
private key;
|
|
5
|
+
private storage;
|
|
6
|
+
constructor();
|
|
7
|
+
initRequest(opts: IntlContextValue): void;
|
|
8
|
+
isInitialized(): boolean;
|
|
9
|
+
getLocale(): string;
|
|
10
|
+
getTranslator(): {
|
|
11
|
+
<TargetKey extends never>(key: TargetKey, values?: import("use-intl/dist/src/core/TranslationValues").default | undefined, formats?: Partial<import("use-intl/dist/src/core/Formats").default> | undefined): string;
|
|
12
|
+
rich<TargetKey_1 extends never>(key: TargetKey_1, values?: import("use-intl/dist/src/core/createTranslatorImpl").CoreRichTranslationValues | undefined, formats?: Partial<import("use-intl/dist/src/core/Formats").default> | undefined): string;
|
|
13
|
+
raw<TargetKey_2 extends never>(key: TargetKey_2): any;
|
|
14
|
+
};
|
|
15
|
+
getIntl(): {
|
|
16
|
+
formatDateTime: (value: number | Date, formatOrOptions?: string | import("use-intl/dist/src/core/DateTimeFormatOptions").default | undefined) => string;
|
|
17
|
+
formatNumber: (value: number, formatOrOptions?: string | import("@formatjs/ecma402-abstract/types/number").NumberFormatOptions | undefined) => string;
|
|
18
|
+
formatRelativeTime: (date: number | Date, now?: number | Date | undefined) => string;
|
|
19
|
+
};
|
|
20
|
+
getNow(): Date | undefined;
|
|
21
|
+
getTimeZone(): string | undefined;
|
|
22
|
+
private getInitializedStorage;
|
|
23
|
+
}
|
|
24
|
+
declare const instance: NextIntlRequestStorage;
|
|
25
|
+
export default instance;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the request-level storage of Next.js where typically headers
|
|
3
|
+
* and cookies are stored. This is recreated for every request.
|
|
4
|
+
*
|
|
5
|
+
* This uses internal APIs of Next.js and may break in
|
|
6
|
+
* the future, so we should really move away from this.
|
|
7
|
+
*/
|
|
8
|
+
export default class NextRequestStorage<Data> {
|
|
9
|
+
private key;
|
|
10
|
+
constructor(key: string);
|
|
11
|
+
set(value: Data): void;
|
|
12
|
+
get(): Data | undefined;
|
|
13
|
+
private getStorage;
|
|
14
|
+
}
|
package/dist/server/index.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
+
export { default as useLocale } from './useLocale';
|
|
2
|
+
export { default as useTranslations } from './useTranslations';
|
|
3
|
+
export { default as useIntl } from './useIntl';
|
|
4
|
+
export { default as useNow } from './useNow';
|
|
5
|
+
export { default as useTimeZone } from './useTimeZone';
|
|
1
6
|
export * from 'use-intl/dist/src/core';
|
|
2
|
-
declare function notSupported(): void;
|
|
3
|
-
export declare const IntlProvider: typeof notSupported;
|
|
4
|
-
export declare const useTranslations: typeof notSupported;
|
|
5
|
-
export declare const useIntl: typeof notSupported;
|
|
6
|
-
export declare const useLocale: typeof notSupported;
|
|
7
|
-
export declare const useNow: typeof notSupported;
|
|
8
|
-
export declare const useTimeZone: typeof notSupported;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
//
|
|
1
|
+
// This is the main entry file when the 'react-server' environment imports
|
|
2
|
+
// from 'next-intl'. Make sure this mirrors the API from the main entry.
|
|
3
|
+
// Replaced exports from the `react` package
|
|
4
|
+
export { default as useLocale } from './useLocale';
|
|
5
|
+
export { default as useTranslations } from './useTranslations';
|
|
6
|
+
export { default as useIntl } from './useIntl';
|
|
7
|
+
export { default as useNow } from './useNow';
|
|
8
|
+
export { default as useTimeZone } from './useTimeZone';
|
|
9
|
+
// Everything from `core`
|
|
2
10
|
export * from 'use-intl/dist/src/core';
|
|
3
|
-
function notSupported() {
|
|
4
|
-
throw new Error('The React APIs of next-intl are currently not available in Server Components (see https://next-intl-docs.vercel.app/docs/next-13). As a stopgap solution, you can use the core library for these use cases (see https://next-intl-docs.vercel.app/docs/usage/core-library).');
|
|
5
|
-
}
|
|
6
|
-
export const IntlProvider = notSupported;
|
|
7
|
-
export const useTranslations = notSupported;
|
|
8
|
-
export const useIntl = notSupported;
|
|
9
|
-
export const useLocale = notSupported;
|
|
10
|
-
export const useNow = notSupported;
|
|
11
|
-
export const useTimeZone = notSupported;
|
|
12
11
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/react-server/index.tsx"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/react-server/index.tsx"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,wEAAwE;AAExE,4CAA4C;AAC5C,OAAO,EAAC,OAAO,IAAI,SAAS,EAAC,MAAM,aAAa,CAAC;AACjD,OAAO,EAAC,OAAO,IAAI,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAC,OAAO,IAAI,OAAO,EAAC,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAC,OAAO,IAAI,MAAM,EAAC,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAC,OAAO,IAAI,WAAW,EAAC,MAAM,eAAe,CAAC;AAErD,yBAAyB;AACzB,cAAc,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export default function useIntl(): {
|
|
2
|
+
formatDateTime: (value: number | Date, formatOrOptions?: string | import("use-intl/dist/src/core/DateTimeFormatOptions").default | undefined) => string;
|
|
3
|
+
formatNumber: (value: number, formatOrOptions?: string | import("use-intl").NumberFormatOptions | undefined) => string;
|
|
4
|
+
formatRelativeTime: (date: number | Date, now?: number | Date | undefined) => string;
|
|
5
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useIntl.js","sourceRoot":"","sources":["../../../src/react-server/useIntl.tsx"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,MAAM,kCAAkC,CAAC;AAEtE,MAAM,CAAC,OAAO,UAAU,OAAO;IAC7B,OAAO,sBAAsB,CAAC,OAAO,EAAE,CAAC;AAC1C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function useLocale(): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useLocale.js","sourceRoot":"","sources":["../../../src/react-server/useLocale.tsx"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,MAAM,kCAAkC,CAAC;AAEtE,MAAM,CAAC,OAAO,UAAU,SAAS;IAC/B,OAAO,sBAAsB,CAAC,SAAS,EAAE,CAAC;AAC5C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function useNow(): Date | undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useNow.js","sourceRoot":"","sources":["../../../src/react-server/useNow.tsx"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,MAAM,kCAAkC,CAAC;AAEtE,MAAM,CAAC,OAAO,UAAU,MAAM;IAC5B,OAAO,sBAAsB,CAAC,MAAM,EAAE,CAAC;AACzC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function useTimeZone(): string | undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTimeZone.js","sourceRoot":"","sources":["../../../src/react-server/useTimeZone.tsx"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,MAAM,kCAAkC,CAAC;AAEtE,MAAM,CAAC,OAAO,UAAU,WAAW;IACjC,OAAO,sBAAsB,CAAC,WAAW,EAAE,CAAC;AAC9C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function useTranslations(namespace?: string): (key: string, ...rest: any) => string;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import NextIntlRequestStorage from '../server/NextIntlRequestStorage';
|
|
2
|
+
export default function useTranslations(namespace) {
|
|
3
|
+
const translator = NextIntlRequestStorage.getTranslator();
|
|
4
|
+
return function translate(key, ...rest) {
|
|
5
|
+
const path = [namespace, key].filter((part) => part != null).join('.');
|
|
6
|
+
// @ts-expect-error We're using the types from the real `useTranslations` anyway
|
|
7
|
+
return translator(path, ...rest);
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=useTranslations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTranslations.js","sourceRoot":"","sources":["../../../src/react-server/useTranslations.tsx"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,MAAM,kCAAkC,CAAC;AAEtE,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,SAAkB;IACxD,MAAM,UAAU,GAAG,sBAAsB,CAAC,aAAa,EAAE,CAAC;IAE1D,OAAO,SAAS,SAAS,CAAC,GAAW,EAAE,GAAG,IAAS;QACjD,MAAM,IAAI,GAAG,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAEvE,gFAAgF;QAChF,OAAO,UAAU,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC;IACnC,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import 'server-only';
|
|
2
|
+
import IntlContextValue from 'use-intl/dist/src/react/IntlContextValue';
|
|
3
|
+
declare class NextIntlRequestStorage {
|
|
4
|
+
private key;
|
|
5
|
+
private storage;
|
|
6
|
+
constructor();
|
|
7
|
+
initRequest(opts: IntlContextValue): void;
|
|
8
|
+
isInitialized(): boolean;
|
|
9
|
+
getLocale(): string;
|
|
10
|
+
getTranslator(): {
|
|
11
|
+
<TargetKey extends never>(key: TargetKey, values?: import("use-intl/dist/src/core/TranslationValues").default | undefined, formats?: Partial<import("use-intl/dist/src/core/Formats").default> | undefined): string;
|
|
12
|
+
rich<TargetKey_1 extends never>(key: TargetKey_1, values?: import("use-intl/dist/src/core/createTranslatorImpl").CoreRichTranslationValues | undefined, formats?: Partial<import("use-intl/dist/src/core/Formats").default> | undefined): string;
|
|
13
|
+
raw<TargetKey_2 extends never>(key: TargetKey_2): any;
|
|
14
|
+
};
|
|
15
|
+
getIntl(): {
|
|
16
|
+
formatDateTime: (value: number | Date, formatOrOptions?: string | import("use-intl/dist/src/core/DateTimeFormatOptions").default | undefined) => string;
|
|
17
|
+
formatNumber: (value: number, formatOrOptions?: string | import("@formatjs/ecma402-abstract/types/number").NumberFormatOptions | undefined) => string;
|
|
18
|
+
formatRelativeTime: (date: number | Date, now?: number | Date | undefined) => string;
|
|
19
|
+
};
|
|
20
|
+
getNow(): Date | undefined;
|
|
21
|
+
getTimeZone(): string | undefined;
|
|
22
|
+
private getInitializedStorage;
|
|
23
|
+
}
|
|
24
|
+
declare const instance: NextIntlRequestStorage;
|
|
25
|
+
export default instance;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import 'server-only';
|
|
2
|
+
import { createTranslator, createIntl } from 'use-intl/dist/src/core';
|
|
3
|
+
import NextRequestStorage from './NextRequestStorage';
|
|
4
|
+
class NextIntlRequestStorage {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.key = '__next-intl';
|
|
7
|
+
this.storage = new NextRequestStorage(this.key);
|
|
8
|
+
}
|
|
9
|
+
initRequest(opts) {
|
|
10
|
+
const translator = createTranslator({
|
|
11
|
+
...opts,
|
|
12
|
+
messages: opts.messages
|
|
13
|
+
});
|
|
14
|
+
const intl = createIntl(opts);
|
|
15
|
+
const now = opts.now || new Date();
|
|
16
|
+
this.storage.set({ ...opts, translator, intl, now });
|
|
17
|
+
}
|
|
18
|
+
isInitialized() {
|
|
19
|
+
return this.storage.get() != null;
|
|
20
|
+
}
|
|
21
|
+
getLocale() {
|
|
22
|
+
return this.getInitializedStorage().locale;
|
|
23
|
+
}
|
|
24
|
+
getTranslator() {
|
|
25
|
+
return this.getInitializedStorage().translator;
|
|
26
|
+
}
|
|
27
|
+
getIntl() {
|
|
28
|
+
return this.getInitializedStorage().intl;
|
|
29
|
+
}
|
|
30
|
+
getNow() {
|
|
31
|
+
return this.getInitializedStorage().now;
|
|
32
|
+
}
|
|
33
|
+
getTimeZone() {
|
|
34
|
+
return this.getInitializedStorage().timeZone;
|
|
35
|
+
}
|
|
36
|
+
getInitializedStorage() {
|
|
37
|
+
if (!this.isInitialized()) {
|
|
38
|
+
throw new Error('`NextIntlServerProvider` was not initialized.');
|
|
39
|
+
}
|
|
40
|
+
return this.storage.get();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// Provide a singleton-instance of the storage.
|
|
44
|
+
const instance = new NextIntlRequestStorage();
|
|
45
|
+
export default instance;
|
|
46
|
+
//# sourceMappingURL=NextIntlRequestStorage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NextIntlRequestStorage.js","sourceRoot":"","sources":["../../../src/server/NextIntlRequestStorage.tsx"],"names":[],"mappings":"AAAA,OAAO,aAAa,CAAC;AACrB,OAAO,EAAC,gBAAgB,EAAE,UAAU,EAAC,MAAM,wBAAwB,CAAC;AAGpE,OAAO,kBAAkB,MAAM,sBAAsB,CAAC;AAEtD,MAAM,sBAAsB;IAU1B;QATQ,QAAG,GAAG,aAAa,CAAC;QAU1B,IAAI,CAAC,OAAO,GAAG,IAAI,kBAAkB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAClD,CAAC;IAEM,WAAW,CAAC,IAAsB;QACvC,MAAM,UAAU,GAAG,gBAAgB,CAAC;YAClC,GAAG,IAAI;YACP,QAAQ,EAAE,IAAI,CAAC,QAAQ;SACxB,CAAC,CAAC;QACH,MAAM,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;QAC9B,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,IAAI,IAAI,IAAI,EAAE,CAAC;QAEnC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAC,GAAG,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAC,CAAC,CAAC;IACrD,CAAC;IAEM,aAAa;QAClB,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC;IACpC,CAAC;IAEM,SAAS;QACd,OAAO,IAAI,CAAC,qBAAqB,EAAE,CAAC,MAAM,CAAC;IAC7C,CAAC;IAEM,aAAa;QAClB,OAAO,IAAI,CAAC,qBAAqB,EAAE,CAAC,UAAU,CAAC;IACjD,CAAC;IAEM,OAAO;QACZ,OAAO,IAAI,CAAC,qBAAqB,EAAE,CAAC,IAAI,CAAC;IAC3C,CAAC;IAEM,MAAM;QACX,OAAO,IAAI,CAAC,qBAAqB,EAAE,CAAC,GAAG,CAAC;IAC1C,CAAC;IAEM,WAAW;QAChB,OAAO,IAAI,CAAC,qBAAqB,EAAE,CAAC,QAAQ,CAAC;IAC/C,CAAC;IAEO,qBAAqB;QAC3B,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,EAAE;YACzB,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;SAClE;QAED,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,EAAG,CAAC;IAC7B,CAAC;CACF;AAED,+CAA+C;AAC/C,MAAM,QAAQ,GAAG,IAAI,sBAAsB,EAAE,CAAC;AAE9C,eAAe,QAAQ,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import getIntlContextValue from 'use-intl/dist/src/react/getIntlContextValue';
|
|
3
|
+
import NextIntlRequestStorage from './NextIntlRequestStorage';
|
|
4
|
+
export default function NextIntlServerProvider(props) {
|
|
5
|
+
// Typically this component renders only once in `layout`. It can however be
|
|
6
|
+
// the case that when next-intl features are necessary in the `<head>`, this
|
|
7
|
+
// provider will be used twice.
|
|
8
|
+
//
|
|
9
|
+
// Maybe we're doing us a disfavour by using an API that looks like it's
|
|
10
|
+
// scoped to a part of the tree. The big advantage is that the API is the
|
|
11
|
+
// same for both server and client.
|
|
12
|
+
NextIntlRequestStorage.initRequest(getIntlContextValue(props));
|
|
13
|
+
return React.createElement(React.Fragment, null, props.children);
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=NextIntlServerProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NextIntlServerProvider.js","sourceRoot":"","sources":["../../../src/server/NextIntlServerProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,OAAO,mBAAmB,MAAM,6CAA6C,CAAC;AAC9E,OAAO,sBAAsB,MAAM,0BAA0B,CAAC;AAE9D,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAAC,KAAwB;IACrE,4EAA4E;IAC5E,4EAA4E;IAC5E,+BAA+B;IAC/B,EAAE;IACF,wEAAwE;IACxE,yEAAyE;IACzE,mCAAmC;IACnC,sBAAsB,CAAC,WAAW,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC,CAAC;IAE/D,OAAO,0CAAG,KAAK,CAAC,QAAQ,CAAI,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the request-level storage of Next.js where typically headers
|
|
3
|
+
* and cookies are stored. This is recreated for every request.
|
|
4
|
+
*
|
|
5
|
+
* This uses internal APIs of Next.js and may break in
|
|
6
|
+
* the future, so we should really move away from this.
|
|
7
|
+
*/
|
|
8
|
+
export default class NextRequestStorage<Data> {
|
|
9
|
+
private key;
|
|
10
|
+
constructor(key: string);
|
|
11
|
+
set(value: Data): void;
|
|
12
|
+
get(): Data | undefined;
|
|
13
|
+
private getStorage;
|
|
14
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { requestAsyncStorage } from 'next/dist/client/components/request-async-storage';
|
|
2
|
+
/**
|
|
3
|
+
* Returns the request-level storage of Next.js where typically headers
|
|
4
|
+
* and cookies are stored. This is recreated for every request.
|
|
5
|
+
*
|
|
6
|
+
* This uses internal APIs of Next.js and may break in
|
|
7
|
+
* the future, so we should really move away from this.
|
|
8
|
+
*/
|
|
9
|
+
export default class NextRequestStorage {
|
|
10
|
+
constructor(key) {
|
|
11
|
+
this.key = key;
|
|
12
|
+
}
|
|
13
|
+
set(value) {
|
|
14
|
+
const storage = this.getStorage();
|
|
15
|
+
storage[this.key] = value;
|
|
16
|
+
}
|
|
17
|
+
get() {
|
|
18
|
+
const storage = this.getStorage();
|
|
19
|
+
return storage[this.key];
|
|
20
|
+
}
|
|
21
|
+
getStorage() {
|
|
22
|
+
const requestStore = requestAsyncStorage && 'getStore' in requestAsyncStorage
|
|
23
|
+
? requestAsyncStorage.getStore()
|
|
24
|
+
: requestAsyncStorage;
|
|
25
|
+
return requestStore;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=NextRequestStorage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NextRequestStorage.js","sourceRoot":"","sources":["../../../src/server/NextRequestStorage.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,mBAAmB,EAAC,MAAM,mDAAmD,CAAC;AAEtF;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,OAAO,kBAAkB;IAGrC,YAAY,GAAW;QACrB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,CAAC;IAEM,GAAG,CAAC,KAAW;QACpB,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;QACjC,OAAe,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IACrC,CAAC;IAEM,GAAG;QACR,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;QAClC,OAAQ,OAAe,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACpC,CAAC;IAEO,UAAU;QAChB,MAAM,YAAY,GAChB,mBAAmB,IAAI,UAAU,IAAI,mBAAmB;YACtD,CAAC,CAAC,mBAAmB,CAAC,QAAQ,EAAE;YAChC,CAAC,CAAC,mBAAmB,CAAC;QAE1B,OAAO,YAAY,CAAC;IACtB,CAAC;CACF"}
|
package/dist/src/server/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/server/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,IAAI,oBAAoB,EAAC,MAAM,wBAAwB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/server/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,IAAI,oBAAoB,EAAC,MAAM,wBAAwB,CAAC;AACvE,OAAO,EAAC,OAAO,IAAI,sBAAsB,EAAC,MAAM,0BAA0B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-intl",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.11.0-alpha.1",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"author": "Jan Amann <jan@amann.me>",
|
|
6
6
|
"description": "A minimal, but complete solution for internationalization in Next.js apps.",
|
|
@@ -56,7 +56,8 @@
|
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
58
|
"accept-language-parser": "^1.5.0",
|
|
59
|
-
"
|
|
59
|
+
"server-only": "0.0.1",
|
|
60
|
+
"use-intl": "2.10.1"
|
|
60
61
|
},
|
|
61
62
|
"peerDependencies": {
|
|
62
63
|
"next": "^10.0.0 || ^11.0.0 || ^12.0.0 || ^13.0.0",
|
|
@@ -75,6 +76,5 @@
|
|
|
75
76
|
},
|
|
76
77
|
"engines": {
|
|
77
78
|
"node": ">=10"
|
|
78
|
-
}
|
|
79
|
-
"gitHead": "cda1f5415724c973500f4b693f208ba1145baa43"
|
|
79
|
+
}
|
|
80
80
|
}
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
1
|
+
// This is the main entry file when the 'react-server' environment imports
|
|
2
|
+
// from 'next-intl'. Make sure this mirrors the API from the main entry.
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
4
|
+
// Replaced exports from the `react` package
|
|
5
|
+
export {default as useLocale} from './useLocale';
|
|
6
|
+
export {default as useTranslations} from './useTranslations';
|
|
7
|
+
export {default as useIntl} from './useIntl';
|
|
8
|
+
export {default as useNow} from './useNow';
|
|
9
|
+
export {default as useTimeZone} from './useTimeZone';
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
export
|
|
12
|
-
export const useIntl = notSupported;
|
|
13
|
-
export const useLocale = notSupported;
|
|
14
|
-
export const useNow = notSupported;
|
|
15
|
-
export const useTimeZone = notSupported;
|
|
11
|
+
// Everything from `core`
|
|
12
|
+
export * from 'use-intl/dist/src/core';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import NextIntlRequestStorage from '../server/NextIntlRequestStorage';
|
|
2
|
+
|
|
3
|
+
export default function useTranslations(namespace?: string) {
|
|
4
|
+
const translator = NextIntlRequestStorage.getTranslator();
|
|
5
|
+
|
|
6
|
+
return function translate(key: string, ...rest: any) {
|
|
7
|
+
const path = [namespace, key].filter((part) => part != null).join('.');
|
|
8
|
+
|
|
9
|
+
// @ts-expect-error We're using the types from the real `useTranslations` anyway
|
|
10
|
+
return translator(path, ...rest);
|
|
11
|
+
};
|
|
12
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import 'server-only';
|
|
2
|
+
import {createTranslator, createIntl} from 'use-intl/dist/src/core';
|
|
3
|
+
// eslint-disable-next-line import/default -- False positive
|
|
4
|
+
import IntlContextValue from 'use-intl/dist/src/react/IntlContextValue';
|
|
5
|
+
import NextRequestStorage from './NextRequestStorage';
|
|
6
|
+
|
|
7
|
+
class NextIntlRequestStorage {
|
|
8
|
+
private key = '__next-intl';
|
|
9
|
+
|
|
10
|
+
private storage: NextRequestStorage<
|
|
11
|
+
IntlContextValue & {
|
|
12
|
+
translator: ReturnType<typeof createTranslator>;
|
|
13
|
+
intl: ReturnType<typeof createIntl>;
|
|
14
|
+
}
|
|
15
|
+
>;
|
|
16
|
+
|
|
17
|
+
constructor() {
|
|
18
|
+
this.storage = new NextRequestStorage(this.key);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public initRequest(opts: IntlContextValue) {
|
|
22
|
+
const translator = createTranslator({
|
|
23
|
+
...opts,
|
|
24
|
+
messages: opts.messages
|
|
25
|
+
});
|
|
26
|
+
const intl = createIntl(opts);
|
|
27
|
+
const now = opts.now || new Date();
|
|
28
|
+
|
|
29
|
+
this.storage.set({...opts, translator, intl, now});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public isInitialized() {
|
|
33
|
+
return this.storage.get() != null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public getLocale() {
|
|
37
|
+
return this.getInitializedStorage().locale;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public getTranslator() {
|
|
41
|
+
return this.getInitializedStorage().translator;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public getIntl() {
|
|
45
|
+
return this.getInitializedStorage().intl;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public getNow() {
|
|
49
|
+
return this.getInitializedStorage().now;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
public getTimeZone() {
|
|
53
|
+
return this.getInitializedStorage().timeZone;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
private getInitializedStorage() {
|
|
57
|
+
if (!this.isInitialized()) {
|
|
58
|
+
throw new Error('`NextIntlServerProvider` was not initialized.');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return this.storage.get()!;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Provide a singleton-instance of the storage.
|
|
66
|
+
const instance = new NextIntlRequestStorage();
|
|
67
|
+
|
|
68
|
+
export default instance;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
// eslint-disable-next-line import/default -- False positive
|
|
3
|
+
import IntlProviderProps from 'use-intl/dist/src/react/IntlProviderProps';
|
|
4
|
+
import getIntlContextValue from 'use-intl/dist/src/react/getIntlContextValue';
|
|
5
|
+
import NextIntlRequestStorage from './NextIntlRequestStorage';
|
|
6
|
+
|
|
7
|
+
export default function NextIntlServerProvider(props: IntlProviderProps) {
|
|
8
|
+
// Typically this component renders only once in `layout`. It can however be
|
|
9
|
+
// the case that when next-intl features are necessary in the `<head>`, this
|
|
10
|
+
// provider will be used twice.
|
|
11
|
+
//
|
|
12
|
+
// Maybe we're doing us a disfavour by using an API that looks like it's
|
|
13
|
+
// scoped to a part of the tree. The big advantage is that the API is the
|
|
14
|
+
// same for both server and client.
|
|
15
|
+
NextIntlRequestStorage.initRequest(getIntlContextValue(props));
|
|
16
|
+
|
|
17
|
+
return <>{props.children}</>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {requestAsyncStorage} from 'next/dist/client/components/request-async-storage';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns the request-level storage of Next.js where typically headers
|
|
5
|
+
* and cookies are stored. This is recreated for every request.
|
|
6
|
+
*
|
|
7
|
+
* This uses internal APIs of Next.js and may break in
|
|
8
|
+
* the future, so we should really move away from this.
|
|
9
|
+
*/
|
|
10
|
+
export default class NextRequestStorage<Data> {
|
|
11
|
+
private key: string;
|
|
12
|
+
|
|
13
|
+
constructor(key: string) {
|
|
14
|
+
this.key = key;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public set(value: Data) {
|
|
18
|
+
const storage = this.getStorage();
|
|
19
|
+
(storage as any)[this.key] = value;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public get(): Data | undefined {
|
|
23
|
+
const storage = this.getStorage();
|
|
24
|
+
return (storage as any)[this.key];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
private getStorage() {
|
|
28
|
+
const requestStore =
|
|
29
|
+
requestAsyncStorage && 'getStore' in requestAsyncStorage
|
|
30
|
+
? requestAsyncStorage.getStore()
|
|
31
|
+
: requestAsyncStorage;
|
|
32
|
+
|
|
33
|
+
return requestStore;
|
|
34
|
+
}
|
|
35
|
+
}
|
package/src/server/index.tsx
CHANGED
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2020 Jan Amann
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|