Skip to content

Commit 9b7c9fe

Browse files
amannncursoragentkdy1
authored
fix: Improvements for useExtracted (#2152)
Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: DongYun Kang <kdy.1997.dev@gmail.com>
1 parent 224c25e commit 9b7c9fe

File tree

61 files changed

+347
-194
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+347
-194
lines changed

packages/next-intl/src/extractor/ExtractionCompiler.test.tsx

Lines changed: 98 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,12 @@ describe('json format', () => {
7373
{
7474
"de.json": "{
7575
"+YJVTi": "Hallo!"
76-
}",
76+
}
77+
",
7778
"en.json": "{
7879
"+YJVTi": "Hey!"
79-
}",
80+
}
81+
",
8082
}
8183
`);
8284
});
@@ -115,10 +117,12 @@ describe('json format', () => {
115117
{
116118
"de.json": "{
117119
"OpKKos": ""
118-
}",
120+
}
121+
",
119122
"en.json": "{
120123
"OpKKos": "Hello!"
121-
}",
124+
}
125+
",
122126
}
123127
`);
124128
});
@@ -150,17 +154,19 @@ describe('json format', () => {
150154
await waitForWriteFileCalls(4);
151155

152156
expect(vi.mocked(fs.writeFile).mock.calls.slice(2)).toMatchInlineSnapshot(`
153-
[
154-
[
155-
"messages/en.json",
156-
"{}",
157-
],
158157
[
159-
"messages/de.json",
160-
"{}",
161-
],
162-
]
163-
`);
158+
[
159+
"messages/en.json",
160+
"{}
161+
",
162+
],
163+
[
164+
"messages/de.json",
165+
"{}
166+
",
167+
],
168+
]
169+
`);
164170
});
165171

166172
it('restores previous translations when messages are added back', async () => {
@@ -190,17 +196,19 @@ describe('json format', () => {
190196
await waitForWriteFileCalls(4);
191197

192198
expect(vi.mocked(fs.writeFile).mock.calls.slice(2)).toMatchInlineSnapshot(`
193-
[
194199
[
195-
"messages/en.json",
196-
"{}",
197-
],
198-
[
199-
"messages/de.json",
200-
"{}",
201-
],
202-
]
203-
`);
200+
[
201+
"messages/en.json",
202+
"{}
203+
",
204+
],
205+
[
206+
"messages/de.json",
207+
"{}
208+
",
209+
],
210+
]
211+
`);
204212

205213
await compiler.compile(
206214
'/project/src/Greeting.tsx',
@@ -216,21 +224,23 @@ describe('json format', () => {
216224
await waitForWriteFileCalls(6);
217225

218226
expect(vi.mocked(fs.writeFile).mock.calls.slice(4)).toMatchInlineSnapshot(`
219-
[
220227
[
221-
"messages/en.json",
222-
"{
223-
"+YJVTi": "Hey!"
224-
}",
225-
],
226-
[
227-
"messages/de.json",
228-
"{
229-
"+YJVTi": "Hallo!"
230-
}",
231-
],
232-
]
233-
`);
228+
[
229+
"messages/en.json",
230+
"{
231+
"+YJVTi": "Hey!"
232+
}
233+
",
234+
],
235+
[
236+
"messages/de.json",
237+
"{
238+
"+YJVTi": "Hallo!"
239+
}
240+
",
241+
],
242+
]
243+
`);
234244
});
235245

236246
it('handles namespaces when storing messages', async () => {
@@ -262,25 +272,27 @@ describe('json format', () => {
262272
await waitForWriteFileCalls(4);
263273

264274
expect(vi.mocked(fs.writeFile).mock.calls.slice(2)).toMatchInlineSnapshot(`
265-
[
266275
[
267-
"messages/en.json",
268-
"{
269-
"ui": {
270-
"OpKKos": "Hello!"
276+
[
277+
"messages/en.json",
278+
"{
279+
"ui": {
280+
"OpKKos": "Hello!"
281+
}
271282
}
272-
}",
273-
],
274-
[
275-
"messages/de.json",
276-
"{
277-
"ui": {
278-
"OpKKos": ""
283+
",
284+
],
285+
[
286+
"messages/de.json",
287+
"{
288+
"ui": {
289+
"OpKKos": ""
290+
}
279291
}
280-
}",
281-
],
282-
]
283-
`);
292+
",
293+
],
294+
]
295+
`);
284296
});
285297

286298
it('preserves manual translations in target catalogs when adding new messages', async () => {
@@ -314,10 +326,12 @@ describe('json format', () => {
314326
"messages": {
315327
"de.json": "{
316328
"+YJVTi": "Hallo!"
317-
}",
329+
}
330+
",
318331
"en.json": "{
319332
"+YJVTi": "Hey!"
320-
}",
333+
}
334+
",
321335
},
322336
"src": {
323337
"Greeting.tsx": "
@@ -353,11 +367,13 @@ describe('json format', () => {
353367
"de.json": "{
354368
"NnE1NP": "",
355369
"OpKKos": "Hallo!"
356-
}",
370+
}
371+
",
357372
"en.json": "{
358373
"NnE1NP": "Goodbye!",
359374
"OpKKos": "Hello!"
360-
}",
375+
}
376+
",
361377
}
362378
`);
363379
});
@@ -415,13 +431,15 @@ describe('json format', () => {
415431
"messages/en.json",
416432
"{
417433
"+YJVTi": "Hey!"
418-
}",
434+
}
435+
",
419436
],
420437
[
421438
"messages/de.json",
422439
"{
423440
"+YJVTi": "Hallo!"
424-
}",
441+
}
442+
",
425443
],
426444
]
427445
`);
@@ -484,7 +502,7 @@ describe('json format', () => {
484502
const calls = vi.mocked(fs.writeFile).mock.calls;
485503
expect(calls.find((cur) => cur[0] === 'messages/de.json')).toEqual([
486504
'messages/de.json',
487-
'{\n "OpKKos": ""\n}'
505+
'{\n "OpKKos": ""\n}\n'
488506
]);
489507
},
490508
{timeout: 500}
@@ -519,7 +537,7 @@ describe('json format', () => {
519537
const calls = vi.mocked(fs.writeFile).mock.calls;
520538
expect(calls.find((cur) => cur[0] === 'messages/de.json')).toEqual([
521539
'messages/de.json',
522-
'{\n "OpKKos": "Hallo!"\n}'
540+
'{\n "OpKKos": "Hallo!"\n}\n'
523541
]);
524542
},
525543
{timeout: 500}
@@ -547,7 +565,8 @@ describe('json format', () => {
547565
"{
548566
"7kKG3Q": "",
549567
"OpKKos": "Hallo!"
550-
}",
568+
}
569+
",
551570
],
552571
]
553572
`);
@@ -598,14 +617,16 @@ describe('json format', () => {
598617
"{
599618
"NnE1NP": "Goodbye!",
600619
"OpKKos": "Hello!"
601-
}",
620+
}
621+
",
602622
],
603623
[
604624
"messages/de.json",
605625
"{
606626
"NnE1NP": "",
607627
"OpKKos": "Hallo!"
608-
}",
628+
}
629+
",
609630
],
610631
]
611632
`);
@@ -647,19 +668,22 @@ describe('json format', () => {
647668
"messages/en.json",
648669
"{
649670
"OpKKos": "Hello!"
650-
}",
671+
}
672+
",
651673
],
652674
[
653675
"messages/de.json",
654676
"{
655677
"OpKKos": ""
656-
}",
678+
}
679+
",
657680
],
658681
[
659682
"messages/fr.json",
660683
"{
661684
"OpKKos": ""
662-
}",
685+
}
686+
",
663687
],
664688
]
665689
`);
@@ -704,7 +728,8 @@ describe('json format', () => {
704728
"{
705729
"7kKG3Q": "",
706730
"OpKKos": ""
707-
}",
731+
}
732+
",
708733
]
709734
`);
710735
});
@@ -2065,7 +2090,8 @@ describe('`srcPath` filtering', () => {
20652090
"messages/en.json",
20662091
"{
20672092
"+YJVTi": "Hey!"
2068-
}",
2093+
}
2094+
",
20692095
],
20702096
]
20712097
`);
@@ -2085,7 +2111,8 @@ describe('`srcPath` filtering', () => {
20852111
"{
20862112
"JwjlWH": "panel.source",
20872113
"+YJVTi": "Hey!"
2088-
}",
2114+
}
2115+
",
20892116
],
20902117
]
20912118
`);

0 commit comments

Comments
 (0)