next-intl 2.9.1 → 2.10.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +472 -0
- package/dist/next-intl.cjs.development.js +11 -6
- package/dist/next-intl.cjs.development.js.map +1 -1
- package/dist/next-intl.cjs.production.min.js +1 -1
- package/dist/next-intl.cjs.production.min.js.map +1 -1
- package/dist/next-intl.esm2.js +12 -7
- package/dist/next-intl.esm2.js.map +1 -1
- package/dist/server/NextI18nConfig.d.ts +5 -0
- package/dist/server/NextIntlCookie.d.ts +11 -0
- package/dist/server/createIntlMiddleware.d.ts +3 -0
- package/dist/server/index.d.ts +1 -0
- package/dist/server/resolveLocale.d.ts +4 -0
- package/dist/src/NextIntlProvider.d.ts +7 -0
- package/dist/src/NextIntlProvider.js +27 -0
- package/dist/src/NextIntlProvider.js.map +1 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +3 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/server/NextI18nConfig.d.ts +5 -0
- package/dist/src/server/NextI18nConfig.js +2 -0
- package/dist/src/server/NextI18nConfig.js.map +1 -0
- package/dist/src/server/NextIntlCookie.d.ts +11 -0
- package/dist/src/server/NextIntlCookie.js +19 -0
- package/dist/src/server/NextIntlCookie.js.map +1 -0
- package/dist/src/server/createIntlMiddleware.d.ts +3 -0
- package/dist/src/server/createIntlMiddleware.js +22 -0
- package/dist/src/server/createIntlMiddleware.js.map +1 -0
- package/dist/src/server/index.d.ts +1 -0
- package/dist/src/server/index.js +2 -0
- package/dist/src/server/index.js.map +1 -0
- package/dist/src/server/resolveLocale.d.ts +4 -0
- package/dist/src/server/resolveLocale.js +37 -0
- package/dist/src/server/resolveLocale.js.map +1 -0
- package/package.json +22 -8
- package/src/NextIntlProvider.tsx +14 -5
- package/src/server/NextI18nConfig.tsx +7 -0
- package/src/server/NextIntlCookie.tsx +33 -0
- package/src/server/createIntlMiddleware.tsx +33 -0
- package/src/server/index.tsx +1 -0
- package/src/server/resolveLocale.tsx +56 -0
- package/LICENSE +0 -21
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,472 @@
|
|
|
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.9.1 (2022-11-03)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package next-intl
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# 2.9.0 (2022-10-27)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Features
|
|
18
|
+
|
|
19
|
+
* 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)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
# 2.8.0 (2022-10-18)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### Features
|
|
29
|
+
|
|
30
|
+
* 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))
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
## 2.7.6 (2022-09-22)
|
|
37
|
+
|
|
38
|
+
**Note:** Version bump only for package next-intl
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
## 2.7.5 (2022-08-30)
|
|
45
|
+
|
|
46
|
+
**Note:** Version bump only for package next-intl
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
## 2.7.4 (2022-05-30)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
### Bug Fixes
|
|
56
|
+
|
|
57
|
+
* 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))
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
## 2.7.3 (2022-05-20)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
### Bug Fixes
|
|
67
|
+
|
|
68
|
+
* 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))
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
## 2.7.2 (2022-05-10)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
### Bug Fixes
|
|
78
|
+
|
|
79
|
+
* Enable tree-shaking ([#108](https://github.com/amannn/next-intl/issues/108)) ([157b0e2](https://github.com/amannn/next-intl/commit/157b0e28376055e7e34e86007c51d008c8e214aa))
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
## 2.7.1 (2022-04-28)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
### Bug Fixes
|
|
89
|
+
|
|
90
|
+
* Allow null message values ([#110](https://github.com/amannn/next-intl/issues/110)) ([14ae8ff](https://github.com/amannn/next-intl/commit/14ae8ffdf1b295873f14081e2c3709d0f9bd2b9e))
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
# 2.7.0 (2022-04-28)
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
### Features
|
|
100
|
+
|
|
101
|
+
* Warn for invalid namespace keys ([#106](https://github.com/amannn/next-intl/issues/106)) ([e86ab28](https://github.com/amannn/next-intl/commit/e86ab28b9180b866ce1a0a9173355d4b686b7d07))
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
# 2.6.0 (2022-04-08)
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
### Features
|
|
111
|
+
|
|
112
|
+
* Support React 18 ([#98](https://github.com/amannn/next-intl/issues/98)) ([38614eb](https://github.com/amannn/next-intl/commit/38614eb9c6d6fb96704424d7f3ff8a67a24b789e))
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
# 2.5.0 (2022-04-01)
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
### Features
|
|
122
|
+
|
|
123
|
+
* Type safe messages ([#93](https://github.com/amannn/next-intl/issues/93)) ([13b49b1](https://github.com/amannn/next-intl/commit/13b49b138bc0ec3adbe661af6a70dfabfe7e86b0))
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
## 2.4.1 (2022-03-24)
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
### Bug Fixes
|
|
135
|
+
|
|
136
|
+
* Overwrite prerelease ([6caf5c4](https://github.com/amannn/next-intl/commit/6caf5c48a35179f802503bc6580469187765c837))
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
# [2.4.0](https://github.com/amannn/next-intl/compare/v2.3.5...v2.4.0) (2022-02-08)
|
|
143
|
+
|
|
144
|
+
**Note:** Version bump only for package next-intl
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
## 2.3.5 (2022-01-19)
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
### Bug Fixes
|
|
154
|
+
|
|
155
|
+
* 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))
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
## 2.3.4 (2022-01-04)
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
### Bug Fixes
|
|
165
|
+
|
|
166
|
+
* 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))
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
## 2.3.3 (2021-12-23)
|
|
173
|
+
|
|
174
|
+
**Note:** Version bump only for package next-intl
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
## 2.3.2 (2021-12-23)
|
|
181
|
+
|
|
182
|
+
**Note:** Version bump only for package next-intl
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
## 2.3.1 (2021-12-23)
|
|
189
|
+
|
|
190
|
+
**Note:** Version bump only for package next-intl
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
# 2.3.0 (2021-11-24)
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
### Features
|
|
200
|
+
|
|
201
|
+
* Add `useLocale` and `useTimeZone` ([#67](https://github.com/amannn/next-intl/issues/67)) ([7833f4a](https://github.com/amannn/next-intl/commit/7833f4adc1aadc937cbaa550a968ef6f7b4f5ee1))
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
## 2.2.1 (2021-11-23)
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
### Bug Fixes
|
|
211
|
+
|
|
212
|
+
* 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))
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
# 2.2.0 (2021-11-02)
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
### Features
|
|
222
|
+
|
|
223
|
+
* 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))
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
## 2.1.1 (2021-10-28)
|
|
230
|
+
|
|
231
|
+
**Note:** Version bump only for package next-intl
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
# 2.1.0 (2021-10-27)
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
### Features
|
|
241
|
+
|
|
242
|
+
* Support Next.js 12 ([#61](https://github.com/amannn/next-intl/issues/61)) ([0391cc8](https://github.com/amannn/next-intl/commit/0391cc85d3401bca9df29080a569957f6be93c85))
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
## 2.0.5 (2021-09-28)
|
|
249
|
+
|
|
250
|
+
**Note:** Version bump only for package next-intl
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
## 2.0.4 (2021-09-28)
|
|
257
|
+
|
|
258
|
+
**Note:** Version bump only for package next-intl
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
## 2.0.3 (2021-09-17)
|
|
265
|
+
|
|
266
|
+
**Note:** Version bump only for package next-intl
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
## 2.0.2 (2021-09-17)
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
### Bug Fixes
|
|
276
|
+
|
|
277
|
+
* 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))
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
## 2.0.1 (2021-09-04)
|
|
284
|
+
|
|
285
|
+
**Note:** Version bump only for package next-intl
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
# 2.0.0 (2021-08-26)
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
* 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)
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
### BREAKING CHANGES
|
|
298
|
+
|
|
299
|
+
* 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.
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
## 1.5.1 (2021-08-13)
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
### Bug Fixes
|
|
309
|
+
|
|
310
|
+
* 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))
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
# 1.5.0 (2021-08-10)
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
### Features
|
|
320
|
+
|
|
321
|
+
* Add flag to return raw messages ([#48](https://github.com/amannn/next-intl/issues/48)) ([b34e19f](https://github.com/amannn/next-intl/commit/b34e19ff618308b7d0c01e7969975215d96ff608))
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
## 1.4.7 (2021-08-02)
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
### Bug Fixes
|
|
331
|
+
|
|
332
|
+
* 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))
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
## 1.4.6 (2021-08-02)
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
### Bug Fixes
|
|
342
|
+
|
|
343
|
+
* 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))
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
## 1.4.5 (2021-07-26)
|
|
350
|
+
|
|
351
|
+
**Note:** Version bump only for package next-intl
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
## 1.4.4 (2021-07-08)
|
|
358
|
+
|
|
359
|
+
**Note:** Version bump only for package next-intl
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
## 1.4.3 (2021-07-08)
|
|
366
|
+
|
|
367
|
+
**Note:** Version bump only for package next-intl
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
## [1.4.2](https://github.com/amannn/next-intl/compare/v1.4.1...v1.4.2) (2021-06-16)
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
### Bug Fixes
|
|
377
|
+
|
|
378
|
+
* 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))
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
## [1.4.1](https://github.com/amannn/next-intl/compare/v1.4.0...v1.4.1) (2021-06-16)
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
### Bug Fixes
|
|
388
|
+
|
|
389
|
+
* Use correct version range for use-intl ([02c33d3](https://github.com/amannn/next-intl/commit/02c33d341794bdcf6ba30ca8325a6a843a684635))
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
# [1.4.0](https://github.com/amannn/next-intl/compare/v1.3.11...v1.4.0) (2021-06-16)
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
### Features
|
|
399
|
+
|
|
400
|
+
* Support Next.js 11 ([#36](https://github.com/amannn/next-intl/issues/36)) ([fc59871](https://github.com/amannn/next-intl/commit/fc5987156c2a74a9703e39f2b7ee19b84165fd77))
|
|
401
|
+
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
## 1.3.11 (2021-05-07)
|
|
407
|
+
|
|
408
|
+
**Note:** Version bump only for package next-intl
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
## 1.3.10 (2021-05-02)
|
|
415
|
+
|
|
416
|
+
**Note:** Version bump only for package next-intl
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
## 1.3.9 (2021-05-02)
|
|
423
|
+
|
|
424
|
+
**Note:** Version bump only for package next-intl
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
## 1.3.8 (2021-03-26)
|
|
431
|
+
|
|
432
|
+
**Note:** Version bump only for package next-intl
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
|
|
438
|
+
## 1.3.7 (2021-02-12)
|
|
439
|
+
|
|
440
|
+
**Note:** Version bump only for package next-intl
|
|
441
|
+
|
|
442
|
+
|
|
443
|
+
|
|
444
|
+
|
|
445
|
+
|
|
446
|
+
## 1.3.6 (2021-02-09)
|
|
447
|
+
|
|
448
|
+
**Note:** Version bump only for package next-intl
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
## 1.3.5 (2021-02-09)
|
|
455
|
+
|
|
456
|
+
**Note:** Version bump only for package next-intl
|
|
457
|
+
|
|
458
|
+
|
|
459
|
+
|
|
460
|
+
|
|
461
|
+
|
|
462
|
+
## 1.3.4 (2021-02-09)
|
|
463
|
+
|
|
464
|
+
**Note:** Version bump only for package next-intl
|
|
465
|
+
|
|
466
|
+
|
|
467
|
+
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+
## [1.3.3](https://github.com/amannn/next-intl/compare/v1.3.2...v1.3.3) (2021-02-09)
|
|
471
|
+
|
|
472
|
+
**Note:** Version bump only for package next-intl
|
|
@@ -45,17 +45,22 @@ function _objectWithoutPropertiesLoose(source, excluded) {
|
|
|
45
45
|
|
|
46
46
|
var _excluded = ["locale"];
|
|
47
47
|
function NextIntlProvider(_ref) {
|
|
48
|
-
var _useRouter;
|
|
49
|
-
|
|
50
48
|
var locale = _ref.locale,
|
|
51
49
|
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
52
50
|
|
|
53
|
-
|
|
51
|
+
var router$1;
|
|
52
|
+
|
|
53
|
+
try {
|
|
54
|
+
// Reading from context is practically ok to do conditionally
|
|
55
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
56
|
+
router$1 = router.useRouter();
|
|
57
|
+
} catch (error) {// Calling `useRouter` is not supported in the app folder
|
|
58
|
+
} // The router can be undefined if used in a context outside
|
|
54
59
|
// of Next.js (e.g. unit tests, Storybook, ...)
|
|
55
|
-
var nextLocale = (_useRouter = router.useRouter()) == null ? void 0 : _useRouter.locale;
|
|
56
60
|
|
|
57
|
-
|
|
58
|
-
|
|
61
|
+
|
|
62
|
+
if (!locale && router$1) {
|
|
63
|
+
locale = router$1.locale;
|
|
59
64
|
}
|
|
60
65
|
|
|
61
66
|
if (!locale) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"next-intl.cjs.development.js","sources":["../src/NextIntlProvider.tsx"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"next-intl.cjs.development.js","sources":["../src/NextIntlProvider.tsx"],"sourcesContent":["'use client';\n\nimport {useRouter} from 'next/router';\nimport React, {ComponentProps} from 'react';\nimport {IntlProvider} from 'use-intl';\n\ntype Props = Omit<ComponentProps<typeof IntlProvider>, 'locale'> & {\n locale?: string;\n};\n\nexport default function NextIntlProvider({locale, ...rest}: Props) {\n let router;\n try {\n // Reading from context is practically ok to do conditionally\n // eslint-disable-next-line react-hooks/rules-of-hooks\n router = useRouter();\n } catch (error) {\n // Calling `useRouter` is not supported in the app folder\n }\n\n // The router can be undefined if used in a context outside\n // of Next.js (e.g. unit tests, Storybook, ...)\n if (!locale && router) {\n locale = router.locale;\n }\n\n if (!locale) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? \"Couldn't determine locale. Please make sure you use internationalized routing or alternatively pass an explicit locale to `NextIntlProvider`.\"\n : undefined\n );\n }\n\n return <IntlProvider locale={locale} {...rest} />;\n}\n"],"names":["NextIntlProvider","locale","rest","router","useRouter","error","Error","React","createElement","IntlProvider"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUc,SAAUA,gBAAV,CAAmD,IAAA,EAAA;AAAA,EAAvBC,IAAAA,MAAuB,QAAvBA,MAAuB;AAAA,MAAZC,IAAY,GAAA,6BAAA,CAAA,IAAA,EAAA,SAAA,CAAA,CAAA;;AAC/D,EAAA,IAAIC,QAAJ,CAAA;;AACA,EAAI,IAAA;AACF;AACA;AACAA,IAAAA,QAAM,GAAGC,gBAAS,EAAlB,CAAA;AACD,GAJD,CAIE,OAAOC,KAAP,EAAc;AAEf,GAR8D;AAW/D;;;AACA,EAAA,IAAI,CAACJ,MAAD,IAAWE,QAAf,EAAuB;AACrBF,IAAAA,MAAM,GAAGE,QAAM,CAACF,MAAhB,CAAA;AACD,GAAA;;AAED,EAAI,IAAA,CAACA,MAAL,EAAa;AACX,IAAA,MAAM,IAAIK,KAAJ,CAEA,+IADJ,CADI,CAAN,CAAA;AAKD,GAAA;;AAED,EAAA,OAAOC,yBAAA,CAAAC,aAAA,CAACC,oBAAD,EAAA,QAAA,CAAA;AAAcR,IAAAA,MAAM,EAAEA,MAAAA;AAAtB,GAAA,EAAkCC,IAAlC,CAAP,CAAA,CAAA;AACD;;;;;;;;;;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("next/router"),r=require("react"),t=require("use-intl");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=n(r);function u(){return u=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e},u.apply(this,arguments)}var
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("next/router"),r=require("react"),t=require("use-intl");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=n(r);function u(){return u=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e},u.apply(this,arguments)}var a=["locale"];exports.NextIntlProvider=function(r){var n,l=r.locale,c=function(e,r){if(null==e)return{};var t,n,o={},u=Object.keys(e);for(n=0;n<u.length;n++)r.indexOf(t=u[n])>=0||(o[t]=e[t]);return o}(r,a);try{n=e.useRouter()}catch(e){}if(!l&&n&&(l=n.locale),!l)throw new Error(void 0);return o.default.createElement(t.IntlProvider,u({locale:l},c))},Object.keys(t).forEach((function(e){"default"===e||exports.hasOwnProperty(e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return t[e]}})}));
|
|
2
2
|
//# sourceMappingURL=next-intl.cjs.production.min.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"next-intl.cjs.production.min.js","sources":["../src/NextIntlProvider.tsx"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"next-intl.cjs.production.min.js","sources":["../src/NextIntlProvider.tsx"],"sourcesContent":["'use client';\n\nimport {useRouter} from 'next/router';\nimport React, {ComponentProps} from 'react';\nimport {IntlProvider} from 'use-intl';\n\ntype Props = Omit<ComponentProps<typeof IntlProvider>, 'locale'> & {\n locale?: string;\n};\n\nexport default function NextIntlProvider({locale, ...rest}: Props) {\n let router;\n try {\n // Reading from context is practically ok to do conditionally\n // eslint-disable-next-line react-hooks/rules-of-hooks\n router = useRouter();\n } catch (error) {\n // Calling `useRouter` is not supported in the app folder\n }\n\n // The router can be undefined if used in a context outside\n // of Next.js (e.g. unit tests, Storybook, ...)\n if (!locale && router) {\n locale = router.locale;\n }\n\n if (!locale) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? \"Couldn't determine locale. Please make sure you use internationalized routing or alternatively pass an explicit locale to `NextIntlProvider`.\"\n : undefined\n );\n }\n\n return <IntlProvider locale={locale} {...rest} />;\n}\n"],"names":["_ref","locale","router","rest","_objectWithoutPropertiesLoose","_excluded","useRouter","error","Error","undefined","React","createElement","IntlProvider","_extends"],"mappings":"udAUc,SAAmDA,GAAvBC,IACpCC,EADoCD,IAAAA,OAAWE,oIAAYC,CAAAJ,EAAAK,GAE3D,IAGFH,EAASI,EAASA,YAClB,MAAOC,IAUL,IAJCN,GAAUC,IACbD,EAASC,EAAOD,SAGbA,EACH,MAAM,IAAIO,WAGJC,GAIR,OAAOC,UAAAC,cAACC,EAADA,aAAAC,EAAA,CAAcZ,OAAQA,GAAYE"}
|
package/dist/next-intl.esm2.js
CHANGED
|
@@ -5,21 +5,26 @@ import { IntlProvider } from 'use-intl';
|
|
|
5
5
|
|
|
6
6
|
var _excluded = ["locale"];
|
|
7
7
|
function NextIntlProvider(_ref) {
|
|
8
|
-
var _useRouter;
|
|
9
|
-
|
|
10
8
|
var locale = _ref.locale,
|
|
11
9
|
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
12
10
|
|
|
13
|
-
|
|
11
|
+
var router;
|
|
12
|
+
|
|
13
|
+
try {
|
|
14
|
+
// Reading from context is practically ok to do conditionally
|
|
15
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
16
|
+
router = useRouter();
|
|
17
|
+
} catch (error) {// Calling `useRouter` is not supported in the app folder
|
|
18
|
+
} // The router can be undefined if used in a context outside
|
|
14
19
|
// of Next.js (e.g. unit tests, Storybook, ...)
|
|
15
|
-
var nextLocale = (_useRouter = useRouter()) == null ? void 0 : _useRouter.locale;
|
|
16
20
|
|
|
17
|
-
|
|
18
|
-
|
|
21
|
+
|
|
22
|
+
if (!locale && router) {
|
|
23
|
+
locale = router.locale;
|
|
19
24
|
}
|
|
20
25
|
|
|
21
26
|
if (!locale) {
|
|
22
|
-
throw new Error(process.env.NODE_ENV !==
|
|
27
|
+
throw new Error(process.env.NODE_ENV !== 'production' ? "Couldn't determine locale. Please make sure you use internationalized routing or alternatively pass an explicit locale to `NextIntlProvider`." : undefined);
|
|
23
28
|
}
|
|
24
29
|
|
|
25
30
|
return React.createElement(IntlProvider, _extends({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"next-intl.esm2.js","sources":["../src/NextIntlProvider.tsx"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"next-intl.esm2.js","sources":["../src/NextIntlProvider.tsx"],"sourcesContent":["'use client';\n\nimport {useRouter} from 'next/router';\nimport React, {ComponentProps} from 'react';\nimport {IntlProvider} from 'use-intl';\n\ntype Props = Omit<ComponentProps<typeof IntlProvider>, 'locale'> & {\n locale?: string;\n};\n\nexport default function NextIntlProvider({locale, ...rest}: Props) {\n let router;\n try {\n // Reading from context is practically ok to do conditionally\n // eslint-disable-next-line react-hooks/rules-of-hooks\n router = useRouter();\n } catch (error) {\n // Calling `useRouter` is not supported in the app folder\n }\n\n // The router can be undefined if used in a context outside\n // of Next.js (e.g. unit tests, Storybook, ...)\n if (!locale && router) {\n locale = router.locale;\n }\n\n if (!locale) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? \"Couldn't determine locale. Please make sure you use internationalized routing or alternatively pass an explicit locale to `NextIntlProvider`.\"\n : undefined\n );\n }\n\n return <IntlProvider locale={locale} {...rest} />;\n}\n"],"names":["NextIntlProvider","locale","rest","router","useRouter","error","Error","process","env","NODE_ENV","undefined","React","createElement","IntlProvider"],"mappings":";;;;;;AAUc,SAAUA,gBAAV,CAAmD,IAAA,EAAA;AAAA,EAAvBC,IAAAA,MAAuB,QAAvBA,MAAuB;AAAA,MAAZC,IAAY,GAAA,6BAAA,CAAA,IAAA,EAAA,SAAA,CAAA,CAAA;;AAC/D,EAAA,IAAIC,MAAJ,CAAA;;AACA,EAAI,IAAA;AACF;AACA;AACAA,IAAAA,MAAM,GAAGC,SAAS,EAAlB,CAAA;AACD,GAJD,CAIE,OAAOC,KAAP,EAAc;AAEf,GAR8D;AAW/D;;;AACA,EAAA,IAAI,CAACJ,MAAD,IAAWE,MAAf,EAAuB;AACrBF,IAAAA,MAAM,GAAGE,MAAM,CAACF,MAAhB,CAAA;AACD,GAAA;;AAED,EAAI,IAAA,CAACA,MAAL,EAAa;AACX,IAAA,MAAM,IAAIK,KAAJ,CACJC,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAAzB,GACI,+IADJ,GAEIC,SAHA,CAAN,CAAA;AAKD,GAAA;;AAED,EAAA,OAAOC,KAAA,CAAAC,aAAA,CAACC,YAAD,EAAA,QAAA,CAAA;AAAcZ,IAAAA,MAAM,EAAEA,MAAAA;AAAtB,GAAA,EAAkCC,IAAlC,CAAP,CAAA,CAAA;AACD;;;;"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ReadonlyRequestCookies } from 'next/dist/server/app-render';
|
|
2
|
+
import { RequestCookies, ResponseCookies } from 'next/dist/server/web/spec-extension/cookies';
|
|
3
|
+
declare type Cookies = ReadonlyRequestCookies | ResponseCookies | RequestCookies;
|
|
4
|
+
export default class NextIntlCookie {
|
|
5
|
+
private requestCookies;
|
|
6
|
+
constructor(requestCookies: Cookies);
|
|
7
|
+
hasLocale(): boolean;
|
|
8
|
+
getLocale(): string | undefined;
|
|
9
|
+
setLocale(locale: string): void;
|
|
10
|
+
}
|
|
11
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as createIntlMiddleware } from './createIntlMiddleware';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ReadonlyRequestCookies } from 'next/dist/server/app-render';
|
|
2
|
+
import { RequestCookies, ResponseCookies } from 'next/dist/server/web/spec-extension/cookies';
|
|
3
|
+
import NextI18nConfig from './NextI18nConfig';
|
|
4
|
+
export default function resolveLocale(i18n: NextI18nConfig, requestHeaders?: Headers, requestCookies?: ReadonlyRequestCookies | ResponseCookies | RequestCookies, pathname?: string): string;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ComponentProps } from 'react';
|
|
2
|
+
import { IntlProvider } from 'use-intl';
|
|
3
|
+
declare type Props = Omit<ComponentProps<typeof IntlProvider>, 'locale'> & {
|
|
4
|
+
locale?: string;
|
|
5
|
+
};
|
|
6
|
+
export default function NextIntlProvider({ locale, ...rest }: Props): JSX.Element;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useRouter } from 'next/router';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { IntlProvider } from 'use-intl';
|
|
5
|
+
export default function NextIntlProvider({ locale, ...rest }) {
|
|
6
|
+
let router;
|
|
7
|
+
try {
|
|
8
|
+
// Reading from context is practically ok to do conditionally
|
|
9
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
10
|
+
router = useRouter();
|
|
11
|
+
}
|
|
12
|
+
catch (error) {
|
|
13
|
+
// Calling `useRouter` is not supported in the app folder
|
|
14
|
+
}
|
|
15
|
+
// The router can be undefined if used in a context outside
|
|
16
|
+
// of Next.js (e.g. unit tests, Storybook, ...)
|
|
17
|
+
if (!locale && router) {
|
|
18
|
+
locale = router.locale;
|
|
19
|
+
}
|
|
20
|
+
if (!locale) {
|
|
21
|
+
throw new Error(process.env.NODE_ENV !== 'production'
|
|
22
|
+
? "Couldn't determine locale. Please make sure you use internationalized routing or alternatively pass an explicit locale to `NextIntlProvider`."
|
|
23
|
+
: undefined);
|
|
24
|
+
}
|
|
25
|
+
return React.createElement(IntlProvider, { locale: locale, ...rest });
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=NextIntlProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NextIntlProvider.js","sourceRoot":"","sources":["../../src/NextIntlProvider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AACtC,OAAO,KAAuB,MAAM,OAAO,CAAC;AAC5C,OAAO,EAAC,YAAY,EAAC,MAAM,UAAU,CAAC;AAMtC,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,EAAC,MAAM,EAAE,GAAG,IAAI,EAAQ;IAC/D,IAAI,MAAM,CAAC;IACX,IAAI;QACF,6DAA6D;QAC7D,sDAAsD;QACtD,MAAM,GAAG,SAAS,EAAE,CAAC;KACtB;IAAC,OAAO,KAAK,EAAE;QACd,yDAAyD;KAC1D;IAED,2DAA2D;IAC3D,+CAA+C;IAC/C,IAAI,CAAC,MAAM,IAAI,MAAM,EAAE;QACrB,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;KACxB;IAED,IAAI,CAAC,MAAM,EAAE;QACX,MAAM,IAAI,KAAK,CACb,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY;YACnC,CAAC,CAAC,+IAA+I;YACjJ,CAAC,CAAC,SAAS,CACd,CAAC;KACH;IAED,OAAO,oBAAC,YAAY,IAAC,MAAM,EAAE,MAAM,KAAM,IAAI,GAAI,CAAC;AACpD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,IAAI,gBAAgB,EAAC,MAAM,oBAAoB,CAAC;AAC/D,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NextI18nConfig.js","sourceRoot":"","sources":["../../../src/server/NextI18nConfig.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ReadonlyRequestCookies } from 'next/dist/server/app-render';
|
|
2
|
+
import { RequestCookies, ResponseCookies } from 'next/dist/server/web/spec-extension/cookies';
|
|
3
|
+
declare type Cookies = ReadonlyRequestCookies | ResponseCookies | RequestCookies;
|
|
4
|
+
export default class NextIntlCookie {
|
|
5
|
+
private requestCookies;
|
|
6
|
+
constructor(requestCookies: Cookies);
|
|
7
|
+
hasLocale(): boolean;
|
|
8
|
+
getLocale(): string | undefined;
|
|
9
|
+
setLocale(locale: string): void;
|
|
10
|
+
}
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Reuse the legacy cookie name
|
|
2
|
+
// https://nextjs.org/docs/advanced-features/i18n-routing#leveraging-the-next_locale-cookie
|
|
3
|
+
const COOKIE_NAME = 'NEXT_LOCALE';
|
|
4
|
+
export default class NextIntlCookie {
|
|
5
|
+
constructor(requestCookies) {
|
|
6
|
+
this.requestCookies = requestCookies;
|
|
7
|
+
}
|
|
8
|
+
hasLocale() {
|
|
9
|
+
return 'has' in this.requestCookies && this.requestCookies.has(COOKIE_NAME);
|
|
10
|
+
}
|
|
11
|
+
getLocale() {
|
|
12
|
+
return this.requestCookies.get(COOKIE_NAME)?.value;
|
|
13
|
+
}
|
|
14
|
+
setLocale(locale) {
|
|
15
|
+
// TODO: Waiting for https://beta.nextjs.org/docs/api-reference/cookies#thread-id=6YOM0
|
|
16
|
+
this.requestCookies.set(COOKIE_NAME, locale);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=NextIntlCookie.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NextIntlCookie.js","sourceRoot":"","sources":["../../../src/server/NextIntlCookie.tsx"],"names":[],"mappings":"AAOA,+BAA+B;AAC/B,2FAA2F;AAC3F,MAAM,WAAW,GAAG,aAAa,CAAC;AAIlC,MAAM,CAAC,OAAO,OAAO,cAAc;IAGjC,YAAY,cAAuB;QACjC,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;IACvC,CAAC;IAEM,SAAS;QACd,OAAO,KAAK,IAAI,IAAI,CAAC,cAAc,IAAI,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IAC9E,CAAC;IAEM,SAAS;QACd,OAAO,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,KAAK,CAAC;IACrD,CAAC;IAEM,SAAS,CAAC,MAAc;QAC7B,uFAAuF;QACvF,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;IAC/C,CAAC;CACF"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { NextResponse } from 'next/server';
|
|
2
|
+
import NextIntlCookie from './NextIntlCookie';
|
|
3
|
+
import resolveLocale from './resolveLocale';
|
|
4
|
+
// If there's an exact match for this path, we'll add the locale to the URL
|
|
5
|
+
const REDIRECT_URL = '/';
|
|
6
|
+
export default function createIntlMiddleware(i18n) {
|
|
7
|
+
return function middleware(request) {
|
|
8
|
+
// Ideally we could use the `headers()` and `cookies()` API here
|
|
9
|
+
// as well, but they are currently not available in middleware.
|
|
10
|
+
const locale = resolveLocale(i18n, request.headers, request.cookies, request.nextUrl.pathname);
|
|
11
|
+
let response;
|
|
12
|
+
if (request.nextUrl.pathname === REDIRECT_URL) {
|
|
13
|
+
response = NextResponse.redirect(new URL(REDIRECT_URL + locale, request.url));
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
response = NextResponse.next();
|
|
17
|
+
}
|
|
18
|
+
new NextIntlCookie(response.cookies).setLocale(locale);
|
|
19
|
+
return response;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=createIntlMiddleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createIntlMiddleware.js","sourceRoot":"","sources":["../../../src/server/createIntlMiddleware.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAc,YAAY,EAAC,MAAM,aAAa,CAAC;AAEtD,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAC9C,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAE5C,2EAA2E;AAC3E,MAAM,YAAY,GAAG,GAAG,CAAC;AAEzB,MAAM,CAAC,OAAO,UAAU,oBAAoB,CAAC,IAAoB;IAC/D,OAAO,SAAS,UAAU,CAAC,OAAoB;QAC7C,gEAAgE;QAChE,+DAA+D;QAC/D,MAAM,MAAM,GAAG,aAAa,CAC1B,IAAI,EACJ,OAAO,CAAC,OAAO,EACf,OAAO,CAAC,OAAO,EACf,OAAO,CAAC,OAAO,CAAC,QAAQ,CACzB,CAAC;QAEF,IAAI,QAAQ,CAAC;QACb,IAAI,OAAO,CAAC,OAAO,CAAC,QAAQ,KAAK,YAAY,EAAE;YAC7C,QAAQ,GAAG,YAAY,CAAC,QAAQ,CAC9B,IAAI,GAAG,CAAC,YAAY,GAAG,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,CAC5C,CAAC;SACH;aAAM;YACL,QAAQ,GAAG,YAAY,CAAC,IAAI,EAAE,CAAC;SAChC;QAED,IAAI,cAAc,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QAEvD,OAAO,QAAQ,CAAC;IAClB,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as createIntlMiddleware } from './createIntlMiddleware';
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ReadonlyRequestCookies } from 'next/dist/server/app-render';
|
|
2
|
+
import { RequestCookies, ResponseCookies } from 'next/dist/server/web/spec-extension/cookies';
|
|
3
|
+
import NextI18nConfig from './NextI18nConfig';
|
|
4
|
+
export default function resolveLocale(i18n: NextI18nConfig, requestHeaders?: Headers, requestCookies?: ReadonlyRequestCookies | ResponseCookies | RequestCookies, pathname?: string): string;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import acceptLanguageParser from 'accept-language-parser';
|
|
2
|
+
import NextIntlCookie from './NextIntlCookie';
|
|
3
|
+
export default function resolveLocale(i18n, requestHeaders, requestCookies, pathname) {
|
|
4
|
+
if (!requestHeaders)
|
|
5
|
+
requestHeaders = require('next/headers').headers();
|
|
6
|
+
if (!requestCookies)
|
|
7
|
+
requestCookies = require('next/headers').cookies();
|
|
8
|
+
let locale;
|
|
9
|
+
// Prio 1: Use route prefix
|
|
10
|
+
if (pathname) {
|
|
11
|
+
const segments = pathname.split('/');
|
|
12
|
+
if (segments.length > 1) {
|
|
13
|
+
const segment = segments[1];
|
|
14
|
+
if (i18n.locales.includes(segment)) {
|
|
15
|
+
locale = segment;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
// Prio 2: Use existing cookie
|
|
20
|
+
if (!locale && requestCookies) {
|
|
21
|
+
const nextIntlCookie = new NextIntlCookie(requestCookies);
|
|
22
|
+
if (nextIntlCookie.hasLocale()) {
|
|
23
|
+
locale = nextIntlCookie.getLocale();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
// Prio 3: Use accept-language header
|
|
27
|
+
if (!locale && requestHeaders) {
|
|
28
|
+
locale =
|
|
29
|
+
acceptLanguageParser.pick(i18n.locales, requestHeaders.get('accept-language') || i18n.defaultLocale) || i18n.defaultLocale;
|
|
30
|
+
}
|
|
31
|
+
// Prio 5: Use default locale
|
|
32
|
+
if (!locale) {
|
|
33
|
+
locale = i18n.defaultLocale;
|
|
34
|
+
}
|
|
35
|
+
return locale;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=resolveLocale.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveLocale.js","sourceRoot":"","sources":["../../../src/server/resolveLocale.tsx"],"names":[],"mappings":"AAAA,OAAO,oBAAoB,MAAM,wBAAwB,CAAC;AAO1D,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAE9C,MAAM,CAAC,OAAO,UAAU,aAAa,CACnC,IAAoB,EACpB,cAAwB,EACxB,cAA0E,EAC1E,QAAiB;IAEjB,IAAI,CAAC,cAAc;QAAE,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC,OAAO,EAAE,CAAC;IACxE,IAAI,CAAC,cAAc;QAAE,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC,OAAO,EAAE,CAAC;IAExE,IAAI,MAAM,CAAC;IAEX,2BAA2B;IAC3B,IAAI,QAAQ,EAAE;QACZ,MAAM,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACrC,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE;YACvB,MAAM,OAAO,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;YAC5B,IAAI,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;gBAClC,MAAM,GAAG,OAAO,CAAC;aAClB;SACF;KACF;IAED,8BAA8B;IAC9B,IAAI,CAAC,MAAM,IAAI,cAAc,EAAE;QAC7B,MAAM,cAAc,GAAG,IAAI,cAAc,CAAC,cAAc,CAAC,CAAC;QAE1D,IAAI,cAAc,CAAC,SAAS,EAAE,EAAE;YAC9B,MAAM,GAAG,cAAc,CAAC,SAAS,EAAE,CAAC;SACrC;KACF;IAED,qCAAqC;IACrC,IAAI,CAAC,MAAM,IAAI,cAAc,EAAE;QAC7B,MAAM;YACJ,oBAAoB,CAAC,IAAI,CACvB,IAAI,CAAC,OAAO,EACZ,cAAc,CAAC,GAAG,CAAC,iBAAiB,CAAC,IAAI,IAAI,CAAC,aAAa,CAC5D,IAAI,IAAI,CAAC,aAAa,CAAC;KAC3B;IAED,6BAA6B;IAC7B,IAAI,CAAC,MAAM,EAAE;QACX,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC;KAC7B;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/package.json
CHANGED
|
@@ -12,18 +12,32 @@
|
|
|
12
12
|
},
|
|
13
13
|
"scripts": {
|
|
14
14
|
"start": "dts watch",
|
|
15
|
-
"build": "
|
|
16
|
-
"
|
|
17
|
-
"
|
|
15
|
+
"build": "yarn build:default && yarn build:rsc",
|
|
16
|
+
"build:default": "rm -rf dist && dts build",
|
|
17
|
+
"build:rsc": "tsc && rm -rf dist/test",
|
|
18
|
+
"test": "TZ=Europe/Berlin dts test --testPathIgnorePatterns=dist",
|
|
19
|
+
"lint": "eslint src test && tsc --noEmit",
|
|
18
20
|
"prepublishOnly": "yarn test && yarn lint && yarn build && cp ../../README.md . && git checkout .",
|
|
19
21
|
"postpublish": "rm ./README.md"
|
|
20
22
|
},
|
|
21
23
|
"main": "dist/index.js",
|
|
22
|
-
"module": "dist/
|
|
23
|
-
"typings": "dist/index.d.ts",
|
|
24
|
+
"module": "dist/src/index.esm.js",
|
|
25
|
+
"typings": "dist/src/index.d.ts",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"react-server": "./dist/src/index.js",
|
|
29
|
+
"default": "./dist/index.js"
|
|
30
|
+
},
|
|
31
|
+
"./server": {
|
|
32
|
+
"react-server": "./dist/src/index.js",
|
|
33
|
+
"default": "./dist/src/server/index.js"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
24
36
|
"files": [
|
|
25
37
|
"dist",
|
|
26
|
-
"src"
|
|
38
|
+
"src",
|
|
39
|
+
"./server.js",
|
|
40
|
+
"./server.d.ts"
|
|
27
41
|
],
|
|
28
42
|
"keywords": [
|
|
29
43
|
"react",
|
|
@@ -42,6 +56,7 @@
|
|
|
42
56
|
"testEnvironment": "jsdom"
|
|
43
57
|
},
|
|
44
58
|
"dependencies": {
|
|
59
|
+
"accept-language-parser": "^1.5.0",
|
|
45
60
|
"use-intl": "^2.9.1"
|
|
46
61
|
},
|
|
47
62
|
"peerDependencies": {
|
|
@@ -54,10 +69,9 @@
|
|
|
54
69
|
"dts-cli": "1.4.0",
|
|
55
70
|
"eslint": "8.12.0",
|
|
56
71
|
"eslint-config-molindo": "6.0.0",
|
|
57
|
-
"next": "^13.0.
|
|
72
|
+
"next": "^13.0.5",
|
|
58
73
|
"react": "^18.2.0",
|
|
59
74
|
"react-dom": "^18.2.0",
|
|
60
|
-
"tslib": "^2.3.1",
|
|
61
75
|
"typescript": "^4.4.4"
|
|
62
76
|
},
|
|
63
77
|
"engines": {
|
package/src/NextIntlProvider.tsx
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
1
3
|
import {useRouter} from 'next/router';
|
|
2
4
|
import React, {ComponentProps} from 'react';
|
|
3
5
|
import {IntlProvider} from 'use-intl';
|
|
@@ -7,17 +9,24 @@ type Props = Omit<ComponentProps<typeof IntlProvider>, 'locale'> & {
|
|
|
7
9
|
};
|
|
8
10
|
|
|
9
11
|
export default function NextIntlProvider({locale, ...rest}: Props) {
|
|
12
|
+
let router;
|
|
13
|
+
try {
|
|
14
|
+
// Reading from context is practically ok to do conditionally
|
|
15
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
16
|
+
router = useRouter();
|
|
17
|
+
} catch (error) {
|
|
18
|
+
// Calling `useRouter` is not supported in the app folder
|
|
19
|
+
}
|
|
20
|
+
|
|
10
21
|
// The router can be undefined if used in a context outside
|
|
11
22
|
// of Next.js (e.g. unit tests, Storybook, ...)
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if (!locale && nextLocale) {
|
|
15
|
-
locale = nextLocale;
|
|
23
|
+
if (!locale && router) {
|
|
24
|
+
locale = router.locale;
|
|
16
25
|
}
|
|
17
26
|
|
|
18
27
|
if (!locale) {
|
|
19
28
|
throw new Error(
|
|
20
|
-
|
|
29
|
+
process.env.NODE_ENV !== 'production'
|
|
21
30
|
? "Couldn't determine locale. Please make sure you use internationalized routing or alternatively pass an explicit locale to `NextIntlProvider`."
|
|
22
31
|
: undefined
|
|
23
32
|
);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// We're using internals here, but if they are not found, worst case they become `any`
|
|
2
|
+
import {ReadonlyRequestCookies} from 'next/dist/server/app-render';
|
|
3
|
+
import {
|
|
4
|
+
RequestCookies,
|
|
5
|
+
ResponseCookies
|
|
6
|
+
} from 'next/dist/server/web/spec-extension/cookies';
|
|
7
|
+
|
|
8
|
+
// Reuse the legacy cookie name
|
|
9
|
+
// https://nextjs.org/docs/advanced-features/i18n-routing#leveraging-the-next_locale-cookie
|
|
10
|
+
const COOKIE_NAME = 'NEXT_LOCALE';
|
|
11
|
+
|
|
12
|
+
type Cookies = ReadonlyRequestCookies | ResponseCookies | RequestCookies;
|
|
13
|
+
|
|
14
|
+
export default class NextIntlCookie {
|
|
15
|
+
private requestCookies: Cookies;
|
|
16
|
+
|
|
17
|
+
constructor(requestCookies: Cookies) {
|
|
18
|
+
this.requestCookies = requestCookies;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public hasLocale() {
|
|
22
|
+
return 'has' in this.requestCookies && this.requestCookies.has(COOKIE_NAME);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public getLocale() {
|
|
26
|
+
return this.requestCookies.get(COOKIE_NAME)?.value;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public setLocale(locale: string) {
|
|
30
|
+
// TODO: Waiting for https://beta.nextjs.org/docs/api-reference/cookies#thread-id=6YOM0
|
|
31
|
+
this.requestCookies.set(COOKIE_NAME, locale);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import {NextRequest, NextResponse} from 'next/server';
|
|
2
|
+
import NextI18nConfig from './NextI18nConfig';
|
|
3
|
+
import NextIntlCookie from './NextIntlCookie';
|
|
4
|
+
import resolveLocale from './resolveLocale';
|
|
5
|
+
|
|
6
|
+
// If there's an exact match for this path, we'll add the locale to the URL
|
|
7
|
+
const REDIRECT_URL = '/';
|
|
8
|
+
|
|
9
|
+
export default function createIntlMiddleware(i18n: NextI18nConfig) {
|
|
10
|
+
return function middleware(request: NextRequest) {
|
|
11
|
+
// Ideally we could use the `headers()` and `cookies()` API here
|
|
12
|
+
// as well, but they are currently not available in middleware.
|
|
13
|
+
const locale = resolveLocale(
|
|
14
|
+
i18n,
|
|
15
|
+
request.headers,
|
|
16
|
+
request.cookies,
|
|
17
|
+
request.nextUrl.pathname
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
let response;
|
|
21
|
+
if (request.nextUrl.pathname === REDIRECT_URL) {
|
|
22
|
+
response = NextResponse.redirect(
|
|
23
|
+
new URL(REDIRECT_URL + locale, request.url)
|
|
24
|
+
);
|
|
25
|
+
} else {
|
|
26
|
+
response = NextResponse.next();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
new NextIntlCookie(response.cookies).setLocale(locale);
|
|
30
|
+
|
|
31
|
+
return response;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {default as createIntlMiddleware} from './createIntlMiddleware';
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import acceptLanguageParser from 'accept-language-parser';
|
|
2
|
+
import {ReadonlyRequestCookies} from 'next/dist/server/app-render';
|
|
3
|
+
import {
|
|
4
|
+
RequestCookies,
|
|
5
|
+
ResponseCookies
|
|
6
|
+
} from 'next/dist/server/web/spec-extension/cookies';
|
|
7
|
+
import NextI18nConfig from './NextI18nConfig';
|
|
8
|
+
import NextIntlCookie from './NextIntlCookie';
|
|
9
|
+
|
|
10
|
+
export default function resolveLocale(
|
|
11
|
+
i18n: NextI18nConfig,
|
|
12
|
+
requestHeaders?: Headers,
|
|
13
|
+
requestCookies?: ReadonlyRequestCookies | ResponseCookies | RequestCookies,
|
|
14
|
+
pathname?: string
|
|
15
|
+
) {
|
|
16
|
+
if (!requestHeaders) requestHeaders = require('next/headers').headers();
|
|
17
|
+
if (!requestCookies) requestCookies = require('next/headers').cookies();
|
|
18
|
+
|
|
19
|
+
let locale;
|
|
20
|
+
|
|
21
|
+
// Prio 1: Use route prefix
|
|
22
|
+
if (pathname) {
|
|
23
|
+
const segments = pathname.split('/');
|
|
24
|
+
if (segments.length > 1) {
|
|
25
|
+
const segment = segments[1];
|
|
26
|
+
if (i18n.locales.includes(segment)) {
|
|
27
|
+
locale = segment;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Prio 2: Use existing cookie
|
|
33
|
+
if (!locale && requestCookies) {
|
|
34
|
+
const nextIntlCookie = new NextIntlCookie(requestCookies);
|
|
35
|
+
|
|
36
|
+
if (nextIntlCookie.hasLocale()) {
|
|
37
|
+
locale = nextIntlCookie.getLocale();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Prio 3: Use accept-language header
|
|
42
|
+
if (!locale && requestHeaders) {
|
|
43
|
+
locale =
|
|
44
|
+
acceptLanguageParser.pick(
|
|
45
|
+
i18n.locales,
|
|
46
|
+
requestHeaders.get('accept-language') || i18n.defaultLocale
|
|
47
|
+
) || i18n.defaultLocale;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Prio 5: Use default locale
|
|
51
|
+
if (!locale) {
|
|
52
|
+
locale = i18n.defaultLocale;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return locale;
|
|
56
|
+
}
|
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.
|