@intlify/core 12.0.0-alpha.1 → 12.0.0-alpha.11
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/README.md +1 -1
- package/dist/core.d.ts +1 -4
- package/dist/core.esm-browser.js +2462 -3041
- package/dist/core.esm-browser.prod.js +1498 -6
- package/dist/core.esm-bundler.js +1 -1
- package/dist/core.global.js +2741 -3317
- package/dist/core.global.prod.js +1520 -6
- package/dist/core.js +5 -30
- package/dist/core.node.js +5 -30
- package/dist/core.runtime.esm-browser.js +1530 -1845
- package/dist/core.runtime.esm-browser.prod.js +914 -6
- package/dist/core.runtime.esm-bundler.js +1 -1
- package/dist/core.runtime.global.js +1784 -2096
- package/dist/core.runtime.global.prod.js +917 -6
- package/dist/core.runtime.js +14 -28
- package/dist/core.runtime.node.js +14 -28
- package/package.json +40 -39
|
@@ -1,2097 +1,1785 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var IntlifyCore = (function
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
let startTag;
|
|
1786
|
-
let endTag;
|
|
1787
|
-
if (inBrowser) {
|
|
1788
|
-
start = window.performance.now();
|
|
1789
|
-
startTag = 'intlify-message-resolve-start';
|
|
1790
|
-
endTag = 'intlify-message-resolve-end';
|
|
1791
|
-
mark && mark(startTag);
|
|
1792
|
-
}
|
|
1793
|
-
if ((format = resolveValue(message, key)) === null) {
|
|
1794
|
-
// if null, resolve with object key path
|
|
1795
|
-
format = message[key]; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
1796
|
-
}
|
|
1797
|
-
// for vue-devtools timeline event
|
|
1798
|
-
if (inBrowser) {
|
|
1799
|
-
const end = window.performance.now();
|
|
1800
|
-
const emitter = context.__v_emitter;
|
|
1801
|
-
if (emitter && start && format) {
|
|
1802
|
-
emitter.emit('message-resolve', {
|
|
1803
|
-
type: 'message-resolve',
|
|
1804
|
-
key,
|
|
1805
|
-
message: format,
|
|
1806
|
-
time: end - start,
|
|
1807
|
-
groupId: `${type}:${key}`
|
|
1808
|
-
});
|
|
1809
|
-
}
|
|
1810
|
-
if (startTag && endTag && mark && measure) {
|
|
1811
|
-
mark(endTag);
|
|
1812
|
-
measure('intlify message resolve', startTag, endTag);
|
|
1813
|
-
}
|
|
1814
|
-
}
|
|
1815
|
-
if (isString(format) || isMessageAST(format) || isMessageFunction(format)) {
|
|
1816
|
-
break;
|
|
1817
|
-
}
|
|
1818
|
-
if (!isImplicitFallback(targetLocale, locales)) {
|
|
1819
|
-
const missingRet = handleMissing(context, // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
1820
|
-
key, targetLocale, missingWarn, type);
|
|
1821
|
-
if (missingRet !== key) {
|
|
1822
|
-
format = missingRet;
|
|
1823
|
-
}
|
|
1824
|
-
}
|
|
1825
|
-
from = to;
|
|
1826
|
-
}
|
|
1827
|
-
return [format, targetLocale, message];
|
|
1828
|
-
}
|
|
1829
|
-
function compileMessageFormat(context, key, targetLocale, format, cacheBaseKey, onError) {
|
|
1830
|
-
const { messageCompiler, warnHtmlMessage } = context;
|
|
1831
|
-
if (isMessageFunction(format)) {
|
|
1832
|
-
const msg = format;
|
|
1833
|
-
msg.locale = msg.locale || targetLocale;
|
|
1834
|
-
msg.key = msg.key || key;
|
|
1835
|
-
return msg;
|
|
1836
|
-
}
|
|
1837
|
-
if (messageCompiler == null) {
|
|
1838
|
-
const msg = (() => format);
|
|
1839
|
-
msg.locale = targetLocale;
|
|
1840
|
-
msg.key = key;
|
|
1841
|
-
return msg;
|
|
1842
|
-
}
|
|
1843
|
-
// for vue-devtools timeline event
|
|
1844
|
-
let start = null;
|
|
1845
|
-
let startTag;
|
|
1846
|
-
let endTag;
|
|
1847
|
-
if (inBrowser) {
|
|
1848
|
-
start = window.performance.now();
|
|
1849
|
-
startTag = 'intlify-message-compilation-start';
|
|
1850
|
-
endTag = 'intlify-message-compilation-end';
|
|
1851
|
-
mark && mark(startTag);
|
|
1852
|
-
}
|
|
1853
|
-
const msg = messageCompiler(format, getCompileContext(context, targetLocale, cacheBaseKey, format, warnHtmlMessage, onError));
|
|
1854
|
-
// for vue-devtools timeline event
|
|
1855
|
-
if (inBrowser) {
|
|
1856
|
-
const end = window.performance.now();
|
|
1857
|
-
const emitter = context.__v_emitter;
|
|
1858
|
-
if (emitter && start) {
|
|
1859
|
-
emitter.emit('message-compilation', {
|
|
1860
|
-
type: 'message-compilation',
|
|
1861
|
-
message: format,
|
|
1862
|
-
time: end - start,
|
|
1863
|
-
groupId: `${'translate'}:${key}`
|
|
1864
|
-
});
|
|
1865
|
-
}
|
|
1866
|
-
if (startTag && endTag && mark && measure) {
|
|
1867
|
-
mark(endTag);
|
|
1868
|
-
measure('intlify message compilation', startTag, endTag);
|
|
1869
|
-
}
|
|
1870
|
-
}
|
|
1871
|
-
msg.locale = targetLocale;
|
|
1872
|
-
msg.key = key;
|
|
1873
|
-
msg.source = format;
|
|
1874
|
-
return msg;
|
|
1875
|
-
}
|
|
1876
|
-
function evaluateMessage(context, msg, msgCtx) {
|
|
1877
|
-
// for vue-devtools timeline event
|
|
1878
|
-
let start = null;
|
|
1879
|
-
let startTag;
|
|
1880
|
-
let endTag;
|
|
1881
|
-
if (inBrowser) {
|
|
1882
|
-
start = window.performance.now();
|
|
1883
|
-
startTag = 'intlify-message-evaluation-start';
|
|
1884
|
-
endTag = 'intlify-message-evaluation-end';
|
|
1885
|
-
mark && mark(startTag);
|
|
1886
|
-
}
|
|
1887
|
-
const messaged = msg(msgCtx);
|
|
1888
|
-
// for vue-devtools timeline event
|
|
1889
|
-
if (inBrowser) {
|
|
1890
|
-
const end = window.performance.now();
|
|
1891
|
-
const emitter = context.__v_emitter;
|
|
1892
|
-
if (emitter && start) {
|
|
1893
|
-
emitter.emit('message-evaluation', {
|
|
1894
|
-
type: 'message-evaluation',
|
|
1895
|
-
value: messaged,
|
|
1896
|
-
time: end - start,
|
|
1897
|
-
groupId: `${'translate'}:${msg.key}`
|
|
1898
|
-
});
|
|
1899
|
-
}
|
|
1900
|
-
if (startTag && endTag && mark && measure) {
|
|
1901
|
-
mark(endTag);
|
|
1902
|
-
measure('intlify message evaluation', startTag, endTag);
|
|
1903
|
-
}
|
|
1904
|
-
}
|
|
1905
|
-
return messaged;
|
|
1906
|
-
}
|
|
1907
|
-
/** @internal */
|
|
1908
|
-
function parseTranslateArgs(...args) {
|
|
1909
|
-
const [arg1, arg2, arg3] = args;
|
|
1910
|
-
const options = create();
|
|
1911
|
-
if (!isString(arg1) &&
|
|
1912
|
-
!isNumber(arg1) &&
|
|
1913
|
-
!isMessageFunction(arg1) &&
|
|
1914
|
-
!isMessageAST(arg1)) {
|
|
1915
|
-
throw createCoreError(CoreErrorCodes.INVALID_ARGUMENT);
|
|
1916
|
-
}
|
|
1917
|
-
// prettier-ignore
|
|
1918
|
-
const key = isNumber(arg1)
|
|
1919
|
-
? String(arg1)
|
|
1920
|
-
: isMessageFunction(arg1)
|
|
1921
|
-
? arg1
|
|
1922
|
-
: arg1;
|
|
1923
|
-
if (isNumber(arg2)) {
|
|
1924
|
-
options.plural = arg2;
|
|
1925
|
-
}
|
|
1926
|
-
else if (isString(arg2)) {
|
|
1927
|
-
options.default = arg2;
|
|
1928
|
-
}
|
|
1929
|
-
else if (isPlainObject(arg2) && !isEmptyObject(arg2)) {
|
|
1930
|
-
options.named = arg2;
|
|
1931
|
-
}
|
|
1932
|
-
else if (isArray(arg2)) {
|
|
1933
|
-
options.list = arg2;
|
|
1934
|
-
}
|
|
1935
|
-
if (isNumber(arg3)) {
|
|
1936
|
-
options.plural = arg3;
|
|
1937
|
-
}
|
|
1938
|
-
else if (isString(arg3)) {
|
|
1939
|
-
options.default = arg3;
|
|
1940
|
-
}
|
|
1941
|
-
else if (isPlainObject(arg3)) {
|
|
1942
|
-
assign(options, arg3);
|
|
1943
|
-
}
|
|
1944
|
-
return [key, options];
|
|
1945
|
-
}
|
|
1946
|
-
function getCompileContext(context, locale, key, source, warnHtmlMessage, onError) {
|
|
1947
|
-
return {
|
|
1948
|
-
locale,
|
|
1949
|
-
key,
|
|
1950
|
-
warnHtmlMessage,
|
|
1951
|
-
onError: (err) => {
|
|
1952
|
-
onError && onError(err);
|
|
1953
|
-
{
|
|
1954
|
-
const _source = getSourceForCodeFrame(source);
|
|
1955
|
-
const message = `Message compilation error: ${err.message}`;
|
|
1956
|
-
const codeFrame = err.location &&
|
|
1957
|
-
_source &&
|
|
1958
|
-
generateCodeFrame(_source, err.location.start.offset, err.location.end.offset);
|
|
1959
|
-
const emitter = context.__v_emitter;
|
|
1960
|
-
if (emitter && _source) {
|
|
1961
|
-
emitter.emit('compile-error', {
|
|
1962
|
-
message: _source,
|
|
1963
|
-
error: err.message,
|
|
1964
|
-
start: err.location && err.location.start.offset,
|
|
1965
|
-
end: err.location && err.location.end.offset,
|
|
1966
|
-
groupId: `${'translate'}:${key}`
|
|
1967
|
-
});
|
|
1968
|
-
}
|
|
1969
|
-
console.error(codeFrame ? `${message}\n${codeFrame}` : message);
|
|
1970
|
-
}
|
|
1971
|
-
},
|
|
1972
|
-
onCacheKey: (source) => generateFormatCacheKey(locale, key, source)
|
|
1973
|
-
};
|
|
1974
|
-
}
|
|
1975
|
-
function getSourceForCodeFrame(source) {
|
|
1976
|
-
if (isString(source)) {
|
|
1977
|
-
return source;
|
|
1978
|
-
}
|
|
1979
|
-
else {
|
|
1980
|
-
if (source.loc && source.loc.source) {
|
|
1981
|
-
return source.loc.source;
|
|
1982
|
-
}
|
|
1983
|
-
}
|
|
1984
|
-
}
|
|
1985
|
-
function getMessageContextOptions(context, locale, message, options) {
|
|
1986
|
-
const { modifiers, pluralRules, messageResolver: resolveValue, fallbackLocale, fallbackWarn, missingWarn, fallbackContext } = context;
|
|
1987
|
-
const resolveMessage = (key, useLinked) => {
|
|
1988
|
-
let val = resolveValue(message, key);
|
|
1989
|
-
// fallback
|
|
1990
|
-
if (val == null && (fallbackContext || useLinked)) {
|
|
1991
|
-
const [, , message] = resolveMessageFormat(fallbackContext || context, // NOTE: if has fallbackContext, fallback to root, else if use linked, fallback to local context
|
|
1992
|
-
key, locale, fallbackLocale, fallbackWarn, missingWarn);
|
|
1993
|
-
val = resolveValue(message, key);
|
|
1994
|
-
}
|
|
1995
|
-
if (isString(val) || isMessageAST(val)) {
|
|
1996
|
-
let occurred = false;
|
|
1997
|
-
const onError = () => {
|
|
1998
|
-
occurred = true;
|
|
1999
|
-
};
|
|
2000
|
-
const msg = compileMessageFormat(context, key, locale, val, key, onError);
|
|
2001
|
-
return !occurred
|
|
2002
|
-
? msg
|
|
2003
|
-
: NOOP_MESSAGE_FUNCTION;
|
|
2004
|
-
}
|
|
2005
|
-
else if (isMessageFunction(val)) {
|
|
2006
|
-
return val;
|
|
2007
|
-
}
|
|
2008
|
-
else {
|
|
2009
|
-
// TODO: should be implemented warning message
|
|
2010
|
-
return NOOP_MESSAGE_FUNCTION;
|
|
2011
|
-
}
|
|
2012
|
-
};
|
|
2013
|
-
const ctxOptions = {
|
|
2014
|
-
locale,
|
|
2015
|
-
modifiers,
|
|
2016
|
-
pluralRules,
|
|
2017
|
-
messages: resolveMessage
|
|
2018
|
-
};
|
|
2019
|
-
if (context.processor) {
|
|
2020
|
-
ctxOptions.processor = context.processor;
|
|
2021
|
-
}
|
|
2022
|
-
if (options.list) {
|
|
2023
|
-
ctxOptions.list = options.list;
|
|
2024
|
-
}
|
|
2025
|
-
if (options.named) {
|
|
2026
|
-
ctxOptions.named = options.named;
|
|
2027
|
-
}
|
|
2028
|
-
if (isNumber(options.plural)) {
|
|
2029
|
-
ctxOptions.pluralIndex = options.plural;
|
|
2030
|
-
}
|
|
2031
|
-
return ctxOptions;
|
|
2032
|
-
}
|
|
2033
|
-
|
|
2034
|
-
// register message compiler for jit compilation
|
|
2035
|
-
registerMessageCompiler(compile);
|
|
2036
|
-
// register message resolver at @intlify/core
|
|
2037
|
-
registerMessageResolver(resolveValue);
|
|
2038
|
-
// register fallback locale at @intlify/core
|
|
2039
|
-
registerLocaleFallbacker(fallbackWithLocaleChain);
|
|
2040
|
-
|
|
2041
|
-
exports.CORE_ERROR_CODES_EXTEND_POINT = CORE_ERROR_CODES_EXTEND_POINT;
|
|
2042
|
-
exports.CORE_WARN_CODES_EXTEND_POINT = CORE_WARN_CODES_EXTEND_POINT;
|
|
2043
|
-
exports.CoreWarnCodes = CoreWarnCodes;
|
|
2044
|
-
exports.DATETIME_FORMAT_OPTIONS_KEYS = DATETIME_FORMAT_OPTIONS_KEYS;
|
|
2045
|
-
exports.DEFAULT_LOCALE = DEFAULT_LOCALE;
|
|
2046
|
-
exports.DEFAULT_MESSAGE_DATA_TYPE = DEFAULT_MESSAGE_DATA_TYPE;
|
|
2047
|
-
exports.MISSING_RESOLVE_VALUE = MISSING_RESOLVE_VALUE;
|
|
2048
|
-
exports.NOT_REOSLVED = NOT_REOSLVED;
|
|
2049
|
-
exports.NUMBER_FORMAT_OPTIONS_KEYS = NUMBER_FORMAT_OPTIONS_KEYS;
|
|
2050
|
-
exports.VERSION = VERSION;
|
|
2051
|
-
exports.clearCompileCache = clearCompileCache;
|
|
2052
|
-
exports.clearDateTimeFormat = clearDateTimeFormat;
|
|
2053
|
-
exports.clearNumberFormat = clearNumberFormat;
|
|
2054
|
-
exports.compile = compile;
|
|
2055
|
-
exports.createCompileError = createCompileError;
|
|
2056
|
-
exports.createCoreContext = createCoreContext;
|
|
2057
|
-
exports.createCoreError = createCoreError;
|
|
2058
|
-
exports.createMessageContext = createMessageContext;
|
|
2059
|
-
exports.datetime = datetime;
|
|
2060
|
-
exports.fallbackWithLocaleChain = fallbackWithLocaleChain;
|
|
2061
|
-
exports.fallbackWithSimple = fallbackWithSimple;
|
|
2062
|
-
exports.getAdditionalMeta = getAdditionalMeta;
|
|
2063
|
-
exports.getDevToolsHook = getDevToolsHook;
|
|
2064
|
-
exports.getFallbackContext = getFallbackContext;
|
|
2065
|
-
exports.getLocale = getLocale;
|
|
2066
|
-
exports.getLocaleMessage = getLocaleMessage;
|
|
2067
|
-
exports.getWarnMessage = getWarnMessage;
|
|
2068
|
-
exports.handleMissing = handleMissing;
|
|
2069
|
-
exports.initI18nDevTools = initI18nDevTools;
|
|
2070
|
-
exports.isAlmostSameLocale = isAlmostSameLocale;
|
|
2071
|
-
exports.isImplicitFallback = isImplicitFallback;
|
|
2072
|
-
exports.isMessageAST = isMessageAST;
|
|
2073
|
-
exports.isMessageFunction = isMessageFunction;
|
|
2074
|
-
exports.isTranslateFallbackWarn = isTranslateFallbackWarn;
|
|
2075
|
-
exports.isTranslateMissingWarn = isTranslateMissingWarn;
|
|
2076
|
-
exports.number = number;
|
|
2077
|
-
exports.parse = parse;
|
|
2078
|
-
exports.parseDateTimeArgs = parseDateTimeArgs;
|
|
2079
|
-
exports.parseNumberArgs = parseNumberArgs;
|
|
2080
|
-
exports.parseTranslateArgs = parseTranslateArgs;
|
|
2081
|
-
exports.registerLocaleFallbacker = registerLocaleFallbacker;
|
|
2082
|
-
exports.registerMessageCompiler = registerMessageCompiler;
|
|
2083
|
-
exports.registerMessageResolver = registerMessageResolver;
|
|
2084
|
-
exports.resolveLocale = resolveLocale;
|
|
2085
|
-
exports.resolveValue = resolveValue;
|
|
2086
|
-
exports.resolveWithKeyValue = resolveWithKeyValue;
|
|
2087
|
-
exports.setAdditionalMeta = setAdditionalMeta;
|
|
2088
|
-
exports.setDevToolsHook = setDevToolsHook;
|
|
2089
|
-
exports.setFallbackContext = setFallbackContext;
|
|
2090
|
-
exports.setLocaleMessage = setLocaleMessage;
|
|
2091
|
-
exports.translate = translate;
|
|
2092
|
-
exports.translateDevTools = translateDevTools;
|
|
2093
|
-
exports.updateFallbackLocale = updateFallbackLocale;
|
|
2094
|
-
|
|
2095
|
-
return exports;
|
|
2096
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @intlify/core v12.0.0-alpha.11
|
|
3
|
+
* (c) 2016-present kazuya kawaguchi and contributors
|
|
4
|
+
* @license MIT
|
|
5
|
+
**/
|
|
6
|
+
var IntlifyCore = (function(exports) {
|
|
7
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
8
|
+
// packages/shared/src/utils.ts
|
|
9
|
+
/**
|
|
10
|
+
* Original Utilities
|
|
11
|
+
* written by kazuya kawaguchi
|
|
12
|
+
*/
|
|
13
|
+
const inBrowser = typeof window !== "undefined";
|
|
14
|
+
let mark;
|
|
15
|
+
let measure;
|
|
16
|
+
{
|
|
17
|
+
const perf = inBrowser && window.performance;
|
|
18
|
+
if (perf && perf.mark && perf.measure && perf.clearMarks && perf.clearMeasures) {
|
|
19
|
+
mark = (tag) => {
|
|
20
|
+
perf.mark(tag);
|
|
21
|
+
};
|
|
22
|
+
measure = (name, startTag, endTag) => {
|
|
23
|
+
perf.measure(name, startTag, endTag);
|
|
24
|
+
perf.clearMarks(startTag);
|
|
25
|
+
perf.clearMarks(endTag);
|
|
26
|
+
perf.clearMeasures(name);
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const RE_ARGS = /\{([0-9a-z]+)\}/gi;
|
|
31
|
+
function format$1(message, ...args) {
|
|
32
|
+
if (args.length === 1 && isObject(args[0])) args = args[0];
|
|
33
|
+
if (!args || !args.hasOwnProperty) args = {};
|
|
34
|
+
return message.replace(RE_ARGS, (_match, identifier) => {
|
|
35
|
+
return args.hasOwnProperty(identifier) ? args[identifier] : "";
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
const generateFormatCacheKey = (locale, key, source) => friendlyJSONstringify({
|
|
39
|
+
l: locale,
|
|
40
|
+
k: key,
|
|
41
|
+
s: source
|
|
42
|
+
});
|
|
43
|
+
const friendlyJSONstringify = (json) => JSON.stringify(json).replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029").replace(/\u0027/g, "\\u0027");
|
|
44
|
+
const isNumber = (val) => typeof val === "number" && isFinite(val);
|
|
45
|
+
function toDevtoolsGroupId(type, key) {
|
|
46
|
+
return isString(key) || isNumber(key) ? `${type}:${key}` : type;
|
|
47
|
+
}
|
|
48
|
+
const isDate = (val) => toTypeString(val) === "[object Date]";
|
|
49
|
+
const isRegExp = (val) => toTypeString(val) === "[object RegExp]";
|
|
50
|
+
const isKeylessObject = (val) => Object.keys(val).length === 0;
|
|
51
|
+
const assign = Object.assign;
|
|
52
|
+
const _create = Object.create;
|
|
53
|
+
const create = (obj = null) => _create(obj);
|
|
54
|
+
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
55
|
+
function hasOwn(obj, key) {
|
|
56
|
+
return hasOwnProperty.call(obj, key);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Get `obj[key]` only when `key` is an own property of `obj`, so that a key such as `constructor`
|
|
60
|
+
* does not read a property inherited from `Object.prototype`.
|
|
61
|
+
* The property is read before the check, so that a reactive `obj` tracks `key` even when it is missing.
|
|
62
|
+
*/
|
|
63
|
+
function getOwn(obj, key) {
|
|
64
|
+
const value = obj[key];
|
|
65
|
+
return hasOwn(obj, key) ? value : void 0;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Whether `key` is a property name of `Object.prototype`, such as `__proto__`, `constructor` or `toString`.
|
|
69
|
+
* On a plain object, such a key reads a built-in, and assigning to `__proto__` replaces the prototype.
|
|
70
|
+
*/
|
|
71
|
+
function isObjectPrototypeKey(key) {
|
|
72
|
+
return hasOwn(Object.prototype, key);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Useful Utilities By Evan you
|
|
76
|
+
* Modified by kazuya kawaguchi
|
|
77
|
+
* MIT License
|
|
78
|
+
* https://github.com/vuejs/vue-next/blob/master/packages/shared/src/index.ts
|
|
79
|
+
* https://github.com/vuejs/vue-next/blob/master/packages/shared/src/codeframe.ts
|
|
80
|
+
*/
|
|
81
|
+
const isArray = Array.isArray;
|
|
82
|
+
const isFunction = (val) => typeof val === "function";
|
|
83
|
+
const isString = (val) => typeof val === "string";
|
|
84
|
+
const isBoolean = (val) => typeof val === "boolean";
|
|
85
|
+
const isObject = (val) => val !== null && typeof val === "object";
|
|
86
|
+
const isPromise = (val) => {
|
|
87
|
+
return isObject(val) && isFunction(val.then) && isFunction(val.catch);
|
|
88
|
+
};
|
|
89
|
+
const objectToString = Object.prototype.toString;
|
|
90
|
+
const toTypeString = (value) => objectToString.call(value);
|
|
91
|
+
const isPlainObject = (val) => toTypeString(val) === "[object Object]";
|
|
92
|
+
const toDisplayString = (val) => {
|
|
93
|
+
return val == null ? "" : isArray(val) || isPlainObject(val) && val.toString === objectToString ? JSON.stringify(val, null, 2) : String(val);
|
|
94
|
+
};
|
|
95
|
+
function join(items, separator = "") {
|
|
96
|
+
return items.reduce((str, item, index) => index === 0 ? str + item : str + separator + item, "");
|
|
97
|
+
}
|
|
98
|
+
const RANGE = 2;
|
|
99
|
+
function generateCodeFrame(source, start = 0, end = source.length) {
|
|
100
|
+
const lines = source.split(/\r?\n/);
|
|
101
|
+
let count = 0;
|
|
102
|
+
const res = [];
|
|
103
|
+
for (let i = 0; i < lines.length; i++) {
|
|
104
|
+
count += lines[i].length + 1;
|
|
105
|
+
if (count >= start) {
|
|
106
|
+
for (let j = i - RANGE; j <= i + RANGE || end > count; j++) {
|
|
107
|
+
if (j < 0 || j >= lines.length) continue;
|
|
108
|
+
const line = j + 1;
|
|
109
|
+
res.push(`${line}${" ".repeat(3 - String(line).length)}| ${lines[j]}`);
|
|
110
|
+
const lineLength = lines[j].length;
|
|
111
|
+
if (j === i) {
|
|
112
|
+
const pad = start - (count - lineLength) + 1;
|
|
113
|
+
const length = Math.max(1, end > count ? lineLength - pad : end - start);
|
|
114
|
+
res.push(` | ` + " ".repeat(pad) + "^".repeat(length));
|
|
115
|
+
} else if (j > i) {
|
|
116
|
+
if (end > count) {
|
|
117
|
+
const length = Math.max(Math.min(end - count, lineLength), 1);
|
|
118
|
+
res.push(` | ` + "^".repeat(length));
|
|
119
|
+
}
|
|
120
|
+
count += lineLength + 1;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return res.join("\n");
|
|
127
|
+
}
|
|
128
|
+
// packages/shared/src/warn.ts
|
|
129
|
+
function warn(msg, err) {
|
|
130
|
+
if (typeof console !== "undefined") {
|
|
131
|
+
console.warn(`[intlify] ` + msg);
|
|
132
|
+
/* istanbul ignore if */
|
|
133
|
+
if (err) console.warn(err.stack);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
const hasWarned = {};
|
|
137
|
+
function warnOnce(msg) {
|
|
138
|
+
if (!hasWarned[msg]) {
|
|
139
|
+
hasWarned[msg] = true;
|
|
140
|
+
warn(msg);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
// packages/shared/src/sanitize.ts
|
|
144
|
+
function escapeHtml(rawText) {
|
|
145
|
+
return rawText.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'").replace(/\//g, "/").replace(/=/g, "=");
|
|
146
|
+
}
|
|
147
|
+
function escapeAttributeValue(value) {
|
|
148
|
+
return value.replace(/&(?![a-z0-9#]{2,6};)/gi, "&").replace(/"/g, """).replace(/'/g, "'").replace(/</g, "<").replace(/>/g, ">");
|
|
149
|
+
}
|
|
150
|
+
const javascriptSchemePattern = /^javascript:/i;
|
|
151
|
+
const urlAttributePattern = /^(?:href|xlink:href|src|action|formaction)$/i;
|
|
152
|
+
const numericCharacterReferencePattern = /&#(?:x([0-9a-f]+)|(\d+));?/gi;
|
|
153
|
+
const namedWhitespaceCharacterReferencePattern = /&(?:Tab|NewLine);/g;
|
|
154
|
+
const colonCharacterReferencePattern = /:?/gi;
|
|
155
|
+
const controlOrWhitespacePattern = /[\u0000-\u0020\u007f-\u009f]/g;
|
|
156
|
+
const eventHandlerPattern = /^on\w/i;
|
|
157
|
+
const srcdocPattern = /^srcdoc$/i;
|
|
158
|
+
const dangerousElementPattern = /^(?:base|animate|set|script|plaintext)$/i;
|
|
159
|
+
const textContentElementPattern = /^(?:iframe|noembed|noframes|noscript|style|textarea|title|xmp)$/i;
|
|
160
|
+
const tagStartPattern = /<(\/?)([a-z][^\t\n\f\r />]*)/iy;
|
|
161
|
+
const tagStepPattern = /([\t\n\f\r /]*)(?:(>)|([^\t\n\f\r />][^\t\n\f\r />=]*)(?:[\t\n\f\r ]*=[\t\n\f\r ]*(?:(["'])([\s\S]*?)(\4|$)|([^\t\n\f\r >]*)))?)/y;
|
|
162
|
+
const commentPattern = /<!--(?:>|->|[\s\S]*?--!?>)/y;
|
|
163
|
+
function decodeNumericCharacterReference(match, hex, decimal) {
|
|
164
|
+
const digits = hex || decimal;
|
|
165
|
+
if (!digits) return match;
|
|
166
|
+
const codePoint = Number.parseInt(digits, hex ? 16 : 10);
|
|
167
|
+
return codePoint <= 127 ? String.fromCharCode(codePoint) : match;
|
|
168
|
+
}
|
|
169
|
+
function hasJavascriptScheme(value) {
|
|
170
|
+
const normalized = value.replace(numericCharacterReferencePattern, decodeNumericCharacterReference).replace(namedWhitespaceCharacterReferencePattern, "").replace(colonCharacterReferencePattern, ":").replace(controlOrWhitespacePattern, "");
|
|
171
|
+
return javascriptSchemePattern.test(normalized);
|
|
172
|
+
}
|
|
173
|
+
function sanitizeStyleValue(value) {
|
|
174
|
+
const urlPattern = /url\s*\(/gi;
|
|
175
|
+
let sanitized = "";
|
|
176
|
+
let cursor = 0;
|
|
177
|
+
let match;
|
|
178
|
+
while ((match = urlPattern.exec(value)) !== null) {
|
|
179
|
+
const urlStart = match.index;
|
|
180
|
+
const openParenIndex = urlPattern.lastIndex - 1;
|
|
181
|
+
let index = openParenIndex + 1;
|
|
182
|
+
let depth = 1;
|
|
183
|
+
let quote = null;
|
|
184
|
+
for (; index < value.length; index++) {
|
|
185
|
+
const char = value[index];
|
|
186
|
+
if (quote) {
|
|
187
|
+
if (char === quote) quote = null;
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
if (char === "\"" || char === "'") quote = char;
|
|
191
|
+
else if (char === "(") depth++;
|
|
192
|
+
else if (char === ")") {
|
|
193
|
+
depth--;
|
|
194
|
+
if (depth === 0) break;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
if (depth !== 0) break;
|
|
198
|
+
const rawUrlValue = value.slice(openParenIndex + 1, index).trim();
|
|
199
|
+
const unquotedUrlValue = rawUrlValue.startsWith("\"") && rawUrlValue.endsWith("\"") || rawUrlValue.startsWith("'") && rawUrlValue.endsWith("'") ? rawUrlValue.slice(1, -1).trim() : rawUrlValue;
|
|
200
|
+
sanitized += value.slice(cursor, urlStart);
|
|
201
|
+
sanitized += hasJavascriptScheme(unquotedUrlValue) ? "url(about:blank)" : value.slice(urlStart, index + 1);
|
|
202
|
+
cursor = index + 1;
|
|
203
|
+
}
|
|
204
|
+
return sanitized + value.slice(cursor);
|
|
205
|
+
}
|
|
206
|
+
function sanitizeAttributeValue(attrName, value) {
|
|
207
|
+
if (urlAttributePattern.test(attrName) && hasJavascriptScheme(value)) return "about:blank";
|
|
208
|
+
return escapeAttributeValue(attrName.toLowerCase() === "style" ? sanitizeStyleValue(value) : value);
|
|
209
|
+
}
|
|
210
|
+
function escapeLessThan(text) {
|
|
211
|
+
return text.replace(/</g, "<");
|
|
212
|
+
}
|
|
213
|
+
function serializeAttribute(attrName, value, quote, neutralized) {
|
|
214
|
+
let name = attrName;
|
|
215
|
+
if (eventHandlerPattern.test(attrName)) {
|
|
216
|
+
neutralized.eventHandler = true;
|
|
217
|
+
name = `on${attrName.slice(2)}`;
|
|
218
|
+
} else if (srcdocPattern.test(attrName)) {
|
|
219
|
+
neutralized.srcdoc = true;
|
|
220
|
+
name = `s${attrName.slice(1)}`;
|
|
221
|
+
}
|
|
222
|
+
if (value === void 0) return name;
|
|
223
|
+
const valueQuote = quote || "";
|
|
224
|
+
return `${name}=${valueQuote}${sanitizeAttributeValue(attrName, value)}${valueQuote}`;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Read a tag with the rules of the HTML tokenizer.
|
|
228
|
+
* A start tag is written again with its attributes sanitized, and an end tag is kept as it is
|
|
229
|
+
*
|
|
230
|
+
* @param html - The HTML
|
|
231
|
+
* @param start - The index of `<`
|
|
232
|
+
* @param neutralized - What has been neutralized
|
|
233
|
+
* @returns The tag, the tag name, and the index after the tag (-1 when the tag is not closed),
|
|
234
|
+
* or `undefined` when `<` does not start a tag
|
|
235
|
+
*/
|
|
236
|
+
function readTag(html, start, neutralized) {
|
|
237
|
+
tagStartPattern.lastIndex = start;
|
|
238
|
+
const tagStart = tagStartPattern.exec(html);
|
|
239
|
+
if (!tagStart) return;
|
|
240
|
+
const [, slash, tagName] = tagStart;
|
|
241
|
+
let tag = tagStart[0];
|
|
242
|
+
let step;
|
|
243
|
+
tagStepPattern.lastIndex = tagStartPattern.lastIndex;
|
|
244
|
+
while (step = tagStepPattern.exec(html)) {
|
|
245
|
+
const [raw, separator, close, attrName, quote, quotedValue, closingQuote, unquotedValue] = step;
|
|
246
|
+
if (close) {
|
|
247
|
+
const end = tagStepPattern.lastIndex;
|
|
248
|
+
return [
|
|
249
|
+
slash ? html.slice(start, end) : tag + raw,
|
|
250
|
+
tagName,
|
|
251
|
+
end
|
|
252
|
+
];
|
|
253
|
+
}
|
|
254
|
+
if (quote && !closingQuote) break;
|
|
255
|
+
if (!slash) tag += separator + serializeAttribute(attrName, quote ? quotedValue : unquotedValue, quote, neutralized);
|
|
256
|
+
}
|
|
257
|
+
return [
|
|
258
|
+
tag,
|
|
259
|
+
tagName,
|
|
260
|
+
-1
|
|
261
|
+
];
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Find the end tag of an element whose content is text, as the HTML tokenizer does:
|
|
265
|
+
* the first `</` followed by the tag name, and by whitespace, `/` or `>`
|
|
266
|
+
*
|
|
267
|
+
* @returns The index of the end tag, or -1 when it is not found or not closed in the string
|
|
268
|
+
*/
|
|
269
|
+
function findTextContentEnd(html, from, tagName) {
|
|
270
|
+
for (let index = html.indexOf("</", from); index !== -1; index = html.indexOf("</", index + 2)) {
|
|
271
|
+
const endTag = readTag(html, index, {});
|
|
272
|
+
if (endTag && endTag[1].toLowerCase() === tagName.toLowerCase()) return endTag[2] === -1 ? -1 : index;
|
|
273
|
+
}
|
|
274
|
+
return -1;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Sanitize the translated HTML
|
|
278
|
+
*
|
|
279
|
+
* @remarks
|
|
280
|
+
* Tags are read with the rules of the HTML tokenizer, so that the sanitizer and browsers agree on
|
|
281
|
+
* where each tag and each attribute starts and ends, and every attribute of every start tag is checked.
|
|
282
|
+
* What is still open at the end of the string (a tag, a comment, or an element whose content is text,
|
|
283
|
+
* like `<textarea>`) becomes text: on the server (SSR), the rest of the page follows the translation,
|
|
284
|
+
* and it would be read as a part of what is open
|
|
285
|
+
*
|
|
286
|
+
* @param html - The translated HTML
|
|
287
|
+
* @returns The sanitized HTML
|
|
288
|
+
*/
|
|
289
|
+
function sanitizeTranslatedHtml(html) {
|
|
290
|
+
const neutralized = {};
|
|
291
|
+
let result = "";
|
|
292
|
+
let index = 0;
|
|
293
|
+
let lessThan;
|
|
294
|
+
while ((lessThan = html.indexOf("<", index)) !== -1) {
|
|
295
|
+
result += html.slice(index, lessThan);
|
|
296
|
+
index = lessThan + 1;
|
|
297
|
+
const read = readTag(html, lessThan, neutralized);
|
|
298
|
+
if (read) {
|
|
299
|
+
const [tag, tagName, end] = read;
|
|
300
|
+
if (end === -1) {
|
|
301
|
+
neutralized.unclosed = true;
|
|
302
|
+
result += escapeLessThan(html.slice(lessThan));
|
|
303
|
+
index = html.length;
|
|
304
|
+
break;
|
|
305
|
+
}
|
|
306
|
+
index = end;
|
|
307
|
+
if (tag[1] === "/") result += tag;
|
|
308
|
+
else if (dangerousElementPattern.test(tagName)) {
|
|
309
|
+
neutralized.element = true;
|
|
310
|
+
result += escapeLessThan(tag);
|
|
311
|
+
} else if (textContentElementPattern.test(tagName)) {
|
|
312
|
+
const contentEnd = findTextContentEnd(html, end, tagName);
|
|
313
|
+
if (contentEnd === -1) {
|
|
314
|
+
neutralized.unclosed = true;
|
|
315
|
+
result += escapeLessThan(tag);
|
|
316
|
+
} else {
|
|
317
|
+
result += tag + escapeLessThan(html.slice(end, contentEnd));
|
|
318
|
+
index = contentEnd;
|
|
319
|
+
}
|
|
320
|
+
} else result += tag;
|
|
321
|
+
continue;
|
|
322
|
+
}
|
|
323
|
+
commentPattern.lastIndex = lessThan;
|
|
324
|
+
if (commentPattern.test(html)) {
|
|
325
|
+
result += html.slice(lessThan, commentPattern.lastIndex);
|
|
326
|
+
index = commentPattern.lastIndex;
|
|
327
|
+
continue;
|
|
328
|
+
}
|
|
329
|
+
if (html.startsWith("<!--", lessThan)) neutralized.unclosed = true;
|
|
330
|
+
result += "<";
|
|
331
|
+
}
|
|
332
|
+
result += html.slice(index);
|
|
333
|
+
if (neutralized.eventHandler) warn("Potentially dangerous event handlers detected in translation. Consider removing onclick, onerror, etc. from your translation messages.");
|
|
334
|
+
if (neutralized.srcdoc) warn("Potentially dangerous srcdoc attribute detected in translation. Consider removing srcdoc from your translation messages.");
|
|
335
|
+
if (neutralized.element) warn("Potentially dangerous element (<base>, <animate>, <set>, <script> or <plaintext>) detected in translation. Consider removing it from your translation messages.");
|
|
336
|
+
if (neutralized.unclosed) warn("Unclosed tag, comment or element (such as <textarea>) detected in translation. Consider closing it in your translation messages.");
|
|
337
|
+
return result;
|
|
338
|
+
}
|
|
339
|
+
// packages/shared/src/messages.ts
|
|
340
|
+
const isNotObjectOrIsArray = (val) => !isObject(val) || isArray(val);
|
|
341
|
+
function deepCopy(src, des) {
|
|
342
|
+
if (isNotObjectOrIsArray(src) || isNotObjectOrIsArray(des) || des === Object.prototype) throw new Error("Invalid value");
|
|
343
|
+
const stack = [src, des];
|
|
344
|
+
while (stack.length) {
|
|
345
|
+
const des = stack.pop();
|
|
346
|
+
const src = stack.pop();
|
|
347
|
+
const keys = Object.keys(src);
|
|
348
|
+
for (let i = 0; i < keys.length; i++) {
|
|
349
|
+
const key = keys[i];
|
|
350
|
+
if (key === "__proto__") continue;
|
|
351
|
+
const value = src[key];
|
|
352
|
+
if (!isObject(value)) {
|
|
353
|
+
des[key] = value;
|
|
354
|
+
continue;
|
|
355
|
+
}
|
|
356
|
+
if (isArray(value)) {
|
|
357
|
+
const copied = [];
|
|
358
|
+
copied.length = value.length;
|
|
359
|
+
des[key] = copied;
|
|
360
|
+
stack.push(value, copied);
|
|
361
|
+
continue;
|
|
362
|
+
}
|
|
363
|
+
let desValue = des[key];
|
|
364
|
+
if (!isObject(desValue) || isArray(desValue)) desValue = des[key] = create();
|
|
365
|
+
stack.push(value, desValue);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
// packages/message-compiler/src/errors.ts
|
|
370
|
+
const CompileErrorCodes = {
|
|
371
|
+
EXPECTED_TOKEN: 1,
|
|
372
|
+
INVALID_TOKEN_IN_PLACEHOLDER: 2,
|
|
373
|
+
UNTERMINATED_SINGLE_QUOTE_IN_PLACEHOLDER: 3,
|
|
374
|
+
UNKNOWN_ESCAPE_SEQUENCE: 4,
|
|
375
|
+
INVALID_UNICODE_ESCAPE_SEQUENCE: 5,
|
|
376
|
+
UNBALANCED_CLOSING_BRACE: 6,
|
|
377
|
+
UNTERMINATED_CLOSING_BRACE: 7,
|
|
378
|
+
EMPTY_PLACEHOLDER: 8,
|
|
379
|
+
NOT_ALLOW_NEST_PLACEHOLDER: 9,
|
|
380
|
+
INVALID_LINKED_FORMAT: 10,
|
|
381
|
+
MUST_HAVE_MESSAGES_IN_PLURAL: 11,
|
|
382
|
+
UNEXPECTED_EMPTY_LINKED_MODIFIER: 12,
|
|
383
|
+
UNEXPECTED_EMPTY_LINKED_KEY: 13,
|
|
384
|
+
UNEXPECTED_LEXICAL_ANALYSIS: 14,
|
|
385
|
+
UNHANDLED_CODEGEN_NODE_TYPE: 15,
|
|
386
|
+
UNHANDLED_MINIFIER_NODE_TYPE: 16
|
|
387
|
+
};
|
|
388
|
+
/** @internal */
|
|
389
|
+
const errorMessages$1 = {
|
|
390
|
+
[CompileErrorCodes.EXPECTED_TOKEN]: `Expected token: '{0}'`,
|
|
391
|
+
[CompileErrorCodes.INVALID_TOKEN_IN_PLACEHOLDER]: `Invalid token in placeholder: '{0}'`,
|
|
392
|
+
[CompileErrorCodes.UNTERMINATED_SINGLE_QUOTE_IN_PLACEHOLDER]: `Unterminated single quote in placeholder`,
|
|
393
|
+
[CompileErrorCodes.UNKNOWN_ESCAPE_SEQUENCE]: `Unknown escape sequence: \\{0}`,
|
|
394
|
+
[CompileErrorCodes.INVALID_UNICODE_ESCAPE_SEQUENCE]: `Invalid unicode escape sequence: {0}`,
|
|
395
|
+
[CompileErrorCodes.UNBALANCED_CLOSING_BRACE]: `Unbalanced closing brace`,
|
|
396
|
+
[CompileErrorCodes.UNTERMINATED_CLOSING_BRACE]: `Unterminated closing brace`,
|
|
397
|
+
[CompileErrorCodes.EMPTY_PLACEHOLDER]: `Empty placeholder`,
|
|
398
|
+
[CompileErrorCodes.NOT_ALLOW_NEST_PLACEHOLDER]: `Not allowed nest placeholder`,
|
|
399
|
+
[CompileErrorCodes.INVALID_LINKED_FORMAT]: `Invalid linked format`,
|
|
400
|
+
[CompileErrorCodes.MUST_HAVE_MESSAGES_IN_PLURAL]: `Plural must have messages`,
|
|
401
|
+
[CompileErrorCodes.UNEXPECTED_EMPTY_LINKED_MODIFIER]: `Unexpected empty linked modifier`,
|
|
402
|
+
[CompileErrorCodes.UNEXPECTED_EMPTY_LINKED_KEY]: `Unexpected empty linked key`,
|
|
403
|
+
[CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS]: `Unexpected lexical analysis in token: '{0}'`,
|
|
404
|
+
[CompileErrorCodes.UNHANDLED_CODEGEN_NODE_TYPE]: `unhandled codegen node type: '{0}'`,
|
|
405
|
+
[CompileErrorCodes.UNHANDLED_MINIFIER_NODE_TYPE]: `unhandled mimifier node type: '{0}'`
|
|
406
|
+
};
|
|
407
|
+
function createCompileError(code, loc, options = {}) {
|
|
408
|
+
const { domain, messages, args } = options;
|
|
409
|
+
const msg = format$1((messages || errorMessages$1)[code] || "", ...args || []);
|
|
410
|
+
const error = new SyntaxError(String(msg));
|
|
411
|
+
error.code = code;
|
|
412
|
+
if (loc) error.location = loc;
|
|
413
|
+
error.domain = domain;
|
|
414
|
+
return error;
|
|
415
|
+
}
|
|
416
|
+
// packages/core-base/src/ast.ts
|
|
417
|
+
function isMessageAST(val) {
|
|
418
|
+
return isObject(val) && resolveType(val) === 0 && (hasOwn(val, "b") || hasOwn(val, "body"));
|
|
419
|
+
}
|
|
420
|
+
const PROPS_BODY = ["b", "body"];
|
|
421
|
+
function resolveBody(node) {
|
|
422
|
+
return resolveProps(node, PROPS_BODY);
|
|
423
|
+
}
|
|
424
|
+
const PROPS_CASES = ["c", "cases"];
|
|
425
|
+
function resolveCases(node) {
|
|
426
|
+
return resolveProps(node, PROPS_CASES, []);
|
|
427
|
+
}
|
|
428
|
+
const PROPS_STATIC = ["s", "static"];
|
|
429
|
+
function resolveStatic(node) {
|
|
430
|
+
return resolveProps(node, PROPS_STATIC);
|
|
431
|
+
}
|
|
432
|
+
const PROPS_ITEMS = ["i", "items"];
|
|
433
|
+
function resolveItems(node) {
|
|
434
|
+
return resolveProps(node, PROPS_ITEMS, []);
|
|
435
|
+
}
|
|
436
|
+
const PROPS_TYPE = ["t", "type"];
|
|
437
|
+
function resolveType(node) {
|
|
438
|
+
return resolveProps(node, PROPS_TYPE);
|
|
439
|
+
}
|
|
440
|
+
const PROPS_VALUE = ["v", "value"];
|
|
441
|
+
function resolveValue$1(node, type) {
|
|
442
|
+
const resolved = resolveProps(node, PROPS_VALUE);
|
|
443
|
+
if (resolved != null) return resolved;
|
|
444
|
+
else throw createUnhandleNodeError(type);
|
|
445
|
+
}
|
|
446
|
+
const PROPS_MODIFIER = ["m", "modifier"];
|
|
447
|
+
function resolveLinkedModifier(node) {
|
|
448
|
+
return resolveProps(node, PROPS_MODIFIER);
|
|
449
|
+
}
|
|
450
|
+
const PROPS_KEY = ["k", "key"];
|
|
451
|
+
function resolveLinkedKey(node) {
|
|
452
|
+
const resolved = resolveProps(node, PROPS_KEY);
|
|
453
|
+
if (resolved) return resolved;
|
|
454
|
+
else throw createUnhandleNodeError(6);
|
|
455
|
+
}
|
|
456
|
+
function resolveProps(node, props, defaultValue) {
|
|
457
|
+
for (let i = 0; i < props.length; i++) {
|
|
458
|
+
const prop = props[i];
|
|
459
|
+
if (hasOwn(node, prop) && node[prop] != null) return node[prop];
|
|
460
|
+
}
|
|
461
|
+
return defaultValue;
|
|
462
|
+
}
|
|
463
|
+
const AST_NODE_PROPS_KEYS = [
|
|
464
|
+
...PROPS_BODY,
|
|
465
|
+
...PROPS_CASES,
|
|
466
|
+
...PROPS_STATIC,
|
|
467
|
+
...PROPS_ITEMS,
|
|
468
|
+
...PROPS_KEY,
|
|
469
|
+
...PROPS_MODIFIER,
|
|
470
|
+
...PROPS_VALUE,
|
|
471
|
+
...PROPS_TYPE
|
|
472
|
+
];
|
|
473
|
+
function createUnhandleNodeError(type) {
|
|
474
|
+
return /* @__PURE__ */ new Error(`unhandled node type: ${type}`);
|
|
475
|
+
}
|
|
476
|
+
// packages/core-base/src/format.ts
|
|
477
|
+
function format(ast) {
|
|
478
|
+
return (ctx) => formatParts(ctx, ast);
|
|
479
|
+
}
|
|
480
|
+
function formatParts(ctx, ast) {
|
|
481
|
+
const body = resolveBody(ast);
|
|
482
|
+
if (body == null) throw createUnhandleNodeError(0);
|
|
483
|
+
if (resolveType(body) === 1) {
|
|
484
|
+
const cases = resolveCases(body);
|
|
485
|
+
return ctx.plural(cases.reduce((messages, c) => [...isArray(messages) ? messages : [messages], formatMessageParts(ctx, c)], []));
|
|
486
|
+
} else return formatMessageParts(ctx, body);
|
|
487
|
+
}
|
|
488
|
+
function formatMessageParts(ctx, node) {
|
|
489
|
+
const static_ = resolveStatic(node);
|
|
490
|
+
if (static_ != null) return ctx.type === "text" ? static_ : ctx.normalize([static_]);
|
|
491
|
+
else {
|
|
492
|
+
const messages = resolveItems(node).reduce((acm, c) => [...acm, formatMessagePart(ctx, c)], []);
|
|
493
|
+
return ctx.normalize(messages);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
function formatMessagePart(ctx, node) {
|
|
497
|
+
const type = resolveType(node);
|
|
498
|
+
switch (type) {
|
|
499
|
+
case 3: return resolveValue$1(node, type);
|
|
500
|
+
case 9: return resolveValue$1(node, type);
|
|
501
|
+
case 4: {
|
|
502
|
+
const named = node;
|
|
503
|
+
if (hasOwn(named, "k") && named.k) return ctx.interpolate(ctx.named(named.k));
|
|
504
|
+
if (hasOwn(named, "key") && named.key) return ctx.interpolate(ctx.named(named.key));
|
|
505
|
+
throw createUnhandleNodeError(type);
|
|
506
|
+
}
|
|
507
|
+
case 5: {
|
|
508
|
+
const list = node;
|
|
509
|
+
if (hasOwn(list, "i") && isNumber(list.i)) return ctx.interpolate(ctx.list(list.i));
|
|
510
|
+
if (hasOwn(list, "index") && isNumber(list.index)) return ctx.interpolate(ctx.list(list.index));
|
|
511
|
+
throw createUnhandleNodeError(type);
|
|
512
|
+
}
|
|
513
|
+
case 6: {
|
|
514
|
+
const linked = node;
|
|
515
|
+
const modifier = resolveLinkedModifier(linked);
|
|
516
|
+
const key = resolveLinkedKey(linked);
|
|
517
|
+
return ctx.linked(formatMessagePart(ctx, key), modifier ? formatMessagePart(ctx, modifier) : void 0, ctx.type);
|
|
518
|
+
}
|
|
519
|
+
case 7: return resolveValue$1(node, type);
|
|
520
|
+
case 8: return resolveValue$1(node, type);
|
|
521
|
+
default: throw new Error(`unhandled node on format message part: ${type}`);
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
// packages/core-base/src/compilation.ts
|
|
525
|
+
let compileCache = create();
|
|
526
|
+
function clearCompileCache() {
|
|
527
|
+
compileCache = create();
|
|
528
|
+
}
|
|
529
|
+
/* #__NO_SIDE_EFFECTS__ */
|
|
530
|
+
function compile(message, context) {
|
|
531
|
+
{
|
|
532
|
+
if (!isMessageAST(message)) {
|
|
533
|
+
warn(`Cannot compile the message of '${context.key}' key, because the message compiler is not included in this build. Pre-compile the message. So translate function returns the message as is.`);
|
|
534
|
+
return (() => message);
|
|
535
|
+
}
|
|
536
|
+
const cacheKey = message.cacheKey;
|
|
537
|
+
if (cacheKey) {
|
|
538
|
+
const cached = compileCache[cacheKey];
|
|
539
|
+
if (cached) return cached;
|
|
540
|
+
return compileCache[cacheKey] = format(message);
|
|
541
|
+
} else return format(message);
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
// packages/core-base/src/errors.ts
|
|
545
|
+
const CoreErrorCodes = {
|
|
546
|
+
INVALID_ARGUMENT: 17,
|
|
547
|
+
INVALID_DATE_ARGUMENT: 18,
|
|
548
|
+
INVALID_ISO_DATE_ARGUMENT: 19,
|
|
549
|
+
NOT_SUPPORT_LOCALE_PROMISE_VALUE: 20,
|
|
550
|
+
NOT_SUPPORT_LOCALE_ASYNC_FUNCTION: 21,
|
|
551
|
+
NOT_SUPPORT_LOCALE_TYPE: 22
|
|
552
|
+
};
|
|
553
|
+
const CORE_ERROR_CODES_EXTEND_POINT = 23;
|
|
554
|
+
function createCoreError(code) {
|
|
555
|
+
return createCompileError(code, null, { messages: errorMessages });
|
|
556
|
+
}
|
|
557
|
+
/** @internal */
|
|
558
|
+
const errorMessages = {
|
|
559
|
+
[CoreErrorCodes.INVALID_ARGUMENT]: "Invalid arguments",
|
|
560
|
+
[CoreErrorCodes.INVALID_DATE_ARGUMENT]: "The date provided is an invalid Date object.Make sure your Date represents a valid date.",
|
|
561
|
+
[CoreErrorCodes.INVALID_ISO_DATE_ARGUMENT]: "The argument provided is not a valid ISO date string",
|
|
562
|
+
[CoreErrorCodes.NOT_SUPPORT_LOCALE_PROMISE_VALUE]: "cannot support promise value",
|
|
563
|
+
[CoreErrorCodes.NOT_SUPPORT_LOCALE_ASYNC_FUNCTION]: "cannot support async function",
|
|
564
|
+
[CoreErrorCodes.NOT_SUPPORT_LOCALE_TYPE]: "cannot support locale type"
|
|
565
|
+
};
|
|
566
|
+
// packages/core-base/src/fallbacker.ts
|
|
567
|
+
/** @internal */
|
|
568
|
+
function getLocale(context, options) {
|
|
569
|
+
return options.locale != null ? resolveLocale(options.locale) : resolveLocale(context.locale);
|
|
570
|
+
}
|
|
571
|
+
let _resolveLocale;
|
|
572
|
+
/** @internal */
|
|
573
|
+
function resolveLocale(locale) {
|
|
574
|
+
if (isString(locale)) return locale;
|
|
575
|
+
else if (isFunction(locale)) {
|
|
576
|
+
if (locale.resolvedOnce && _resolveLocale != null) return _resolveLocale;
|
|
577
|
+
else if (locale.constructor.name === "Function") {
|
|
578
|
+
const resolve = locale();
|
|
579
|
+
if (isPromise(resolve)) throw createCoreError(CoreErrorCodes.NOT_SUPPORT_LOCALE_PROMISE_VALUE);
|
|
580
|
+
return _resolveLocale = resolve;
|
|
581
|
+
} else throw createCoreError(CoreErrorCodes.NOT_SUPPORT_LOCALE_ASYNC_FUNCTION);
|
|
582
|
+
} else throw createCoreError(CoreErrorCodes.NOT_SUPPORT_LOCALE_TYPE);
|
|
583
|
+
}
|
|
584
|
+
/**
|
|
585
|
+
* Fallback with simple implemenation
|
|
586
|
+
*
|
|
587
|
+
* @remarks
|
|
588
|
+
* A fallback locale function implemented with a simple fallback algorithm.
|
|
589
|
+
*
|
|
590
|
+
* Basically, the chain consists of `start` plus the specified fallback: for a string or array `fallbackLocale`, the value as specified in the props is used; for a map `fallbackLocale`, the map's **keys** are used and the `default` key is skipped since it is not a locale name.
|
|
591
|
+
*
|
|
592
|
+
* @param ctx - A {@link CoreContext | context}
|
|
593
|
+
* @param fallback - A {@link FallbackLocale | fallback locale}
|
|
594
|
+
* @param start - A starting {@link Locale | locale}
|
|
595
|
+
*
|
|
596
|
+
* @returns Fallback locales
|
|
597
|
+
*
|
|
598
|
+
* @VueI18nGeneral
|
|
599
|
+
*/
|
|
600
|
+
function fallbackWithSimple(_ctx, fallback, start) {
|
|
601
|
+
return [.../* @__PURE__ */ new Set([start, ...isArray(fallback) ? fallback : isObject(fallback) ? Object.keys(fallback).filter((locale) => locale !== "default") : isString(fallback) ? [fallback] : [start]])];
|
|
602
|
+
}
|
|
603
|
+
/**
|
|
604
|
+
* Fallback with locale chain
|
|
605
|
+
*
|
|
606
|
+
* @remarks
|
|
607
|
+
* A fallback locale function implemented with a fallback chain algorithm. It's used in VueI18n as default.
|
|
608
|
+
*
|
|
609
|
+
* Chains are cached per fallback identity. If you mutate an object or array fallback in place,
|
|
610
|
+
* pass a new object or array instead so that the chain is recomputed.
|
|
611
|
+
*
|
|
612
|
+
* @param ctx - A {@link CoreContext | context}
|
|
613
|
+
* @param fallback - A {@link FallbackLocale | fallback locale}
|
|
614
|
+
* @param start - A starting {@link Locale | locale}
|
|
615
|
+
*
|
|
616
|
+
* @returns Fallback locales
|
|
617
|
+
*
|
|
618
|
+
* @VueI18nSee [Fallbacking](../../guide/essentials/fallback)
|
|
619
|
+
*
|
|
620
|
+
* @VueI18nGeneral
|
|
621
|
+
*/
|
|
622
|
+
function fallbackWithLocaleChain(ctx, fallback, start) {
|
|
623
|
+
const startLocale = isString(start) ? start : DEFAULT_LOCALE;
|
|
624
|
+
const context = ctx;
|
|
625
|
+
let chains;
|
|
626
|
+
if (isObject(fallback)) {
|
|
627
|
+
if (!context.__localeChainObjectCache) context.__localeChainObjectCache = /* @__PURE__ */ new WeakMap();
|
|
628
|
+
chains = context.__localeChainObjectCache.get(fallback);
|
|
629
|
+
if (!chains) {
|
|
630
|
+
chains = /* @__PURE__ */ new Map();
|
|
631
|
+
context.__localeChainObjectCache.set(fallback, chains);
|
|
632
|
+
}
|
|
633
|
+
} else {
|
|
634
|
+
if (!context.__localeChainCache) context.__localeChainCache = /* @__PURE__ */ new Map();
|
|
635
|
+
chains = context.__localeChainCache.get(fallback);
|
|
636
|
+
if (!chains) {
|
|
637
|
+
chains = /* @__PURE__ */ new Map();
|
|
638
|
+
context.__localeChainCache.set(fallback, chains);
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
const cached = chains.get(startLocale);
|
|
642
|
+
if (cached) return cached;
|
|
643
|
+
const chain = [];
|
|
644
|
+
let block = [start];
|
|
645
|
+
while (isArray(block)) block = appendBlockToChain(chain, block, fallback);
|
|
646
|
+
const defaults = isArray(fallback) || !isPlainObject(fallback) ? fallback : fallback["default"] ? fallback["default"] : null;
|
|
647
|
+
block = isString(defaults) ? [defaults] : defaults;
|
|
648
|
+
if (isArray(block)) appendBlockToChain(chain, block, false);
|
|
649
|
+
chains.set(startLocale, chain);
|
|
650
|
+
return chain;
|
|
651
|
+
}
|
|
652
|
+
function appendBlockToChain(chain, block, blocks) {
|
|
653
|
+
let follow = true;
|
|
654
|
+
for (let i = 0; i < block.length && isBoolean(follow); i++) {
|
|
655
|
+
const locale = block[i];
|
|
656
|
+
if (isString(locale)) follow = appendLocaleToChain(chain, block[i], blocks);
|
|
657
|
+
}
|
|
658
|
+
return follow;
|
|
659
|
+
}
|
|
660
|
+
function appendLocaleToChain(chain, locale, blocks) {
|
|
661
|
+
let follow;
|
|
662
|
+
const tokens = locale.split("-");
|
|
663
|
+
do {
|
|
664
|
+
follow = appendItemToChain(chain, tokens.join("-"), blocks);
|
|
665
|
+
tokens.splice(-1, 1);
|
|
666
|
+
} while (tokens.length && follow === true);
|
|
667
|
+
return follow;
|
|
668
|
+
}
|
|
669
|
+
function appendItemToChain(chain, target, blocks) {
|
|
670
|
+
let follow = false;
|
|
671
|
+
if (!chain.includes(target)) {
|
|
672
|
+
follow = true;
|
|
673
|
+
if (target) {
|
|
674
|
+
follow = target[target.length - 1] !== "!";
|
|
675
|
+
const locale = target.replace(/!/g, "");
|
|
676
|
+
chain.push(locale);
|
|
677
|
+
if ((isArray(blocks) || isPlainObject(blocks)) && blocks[locale]) follow = blocks[locale];
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
return follow;
|
|
681
|
+
}
|
|
682
|
+
// packages/core-base/src/resolver.ts
|
|
683
|
+
const pathStateMachine = [];
|
|
684
|
+
pathStateMachine[0] = {
|
|
685
|
+
["w"]: [0],
|
|
686
|
+
["i"]: [3, 0],
|
|
687
|
+
["["]: [4],
|
|
688
|
+
["o"]: [7]
|
|
689
|
+
};
|
|
690
|
+
pathStateMachine[1] = {
|
|
691
|
+
["w"]: [1],
|
|
692
|
+
["."]: [2],
|
|
693
|
+
["["]: [4],
|
|
694
|
+
["o"]: [7]
|
|
695
|
+
};
|
|
696
|
+
pathStateMachine[2] = {
|
|
697
|
+
["w"]: [2],
|
|
698
|
+
["i"]: [3, 0],
|
|
699
|
+
["0"]: [3, 0]
|
|
700
|
+
};
|
|
701
|
+
pathStateMachine[3] = {
|
|
702
|
+
["i"]: [3, 0],
|
|
703
|
+
["0"]: [3, 0],
|
|
704
|
+
["w"]: [1, 1],
|
|
705
|
+
["."]: [2, 1],
|
|
706
|
+
["["]: [4, 1],
|
|
707
|
+
["o"]: [7, 1]
|
|
708
|
+
};
|
|
709
|
+
pathStateMachine[4] = {
|
|
710
|
+
["'"]: [5, 0],
|
|
711
|
+
["\""]: [6, 0],
|
|
712
|
+
["["]: [4, 2],
|
|
713
|
+
["]"]: [1, 3],
|
|
714
|
+
["o"]: 8,
|
|
715
|
+
["l"]: [4, 0]
|
|
716
|
+
};
|
|
717
|
+
pathStateMachine[5] = {
|
|
718
|
+
["'"]: [4, 0],
|
|
719
|
+
["o"]: 8,
|
|
720
|
+
["l"]: [5, 0]
|
|
721
|
+
};
|
|
722
|
+
pathStateMachine[6] = {
|
|
723
|
+
["\""]: [4, 0],
|
|
724
|
+
["o"]: 8,
|
|
725
|
+
["l"]: [6, 0]
|
|
726
|
+
};
|
|
727
|
+
/**
|
|
728
|
+
* Check if an expression is a literal value.
|
|
729
|
+
*/
|
|
730
|
+
const literalValueRE = /^\s?(?:true|false|-?[\d.]+|'[^']*'|"[^"]*")\s?$/;
|
|
731
|
+
function isLiteral(exp) {
|
|
732
|
+
return literalValueRE.test(exp);
|
|
733
|
+
}
|
|
734
|
+
/**
|
|
735
|
+
* Strip quotes from a string
|
|
736
|
+
*/
|
|
737
|
+
function stripQuotes(str) {
|
|
738
|
+
const a = str.charCodeAt(0);
|
|
739
|
+
return a === str.charCodeAt(str.length - 1) && (a === 34 || a === 39) ? str.slice(1, -1) : str;
|
|
740
|
+
}
|
|
741
|
+
/**
|
|
742
|
+
* Determine the type of a character in a keypath.
|
|
743
|
+
*/
|
|
744
|
+
function getPathCharType(ch) {
|
|
745
|
+
if (ch === void 0 || ch === null) return "o";
|
|
746
|
+
switch (ch.charCodeAt(0)) {
|
|
747
|
+
case 91:
|
|
748
|
+
case 93:
|
|
749
|
+
case 46:
|
|
750
|
+
case 34:
|
|
751
|
+
case 39: return ch;
|
|
752
|
+
case 95:
|
|
753
|
+
case 36:
|
|
754
|
+
case 45: return "i";
|
|
755
|
+
case 9:
|
|
756
|
+
case 10:
|
|
757
|
+
case 13:
|
|
758
|
+
case 160:
|
|
759
|
+
case 65279:
|
|
760
|
+
case 8232:
|
|
761
|
+
case 8233: return "w";
|
|
762
|
+
}
|
|
763
|
+
return "i";
|
|
764
|
+
}
|
|
765
|
+
/**
|
|
766
|
+
* Format a subPath, return its plain form if it is
|
|
767
|
+
* a literal string or number. Otherwise prepend the
|
|
768
|
+
* dynamic indicator (*).
|
|
769
|
+
*/
|
|
770
|
+
function formatSubPath(path) {
|
|
771
|
+
const trimmed = path.trim();
|
|
772
|
+
if (path.charAt(0) === "0" && isNaN(parseInt(path))) return false;
|
|
773
|
+
return isLiteral(trimmed) ? stripQuotes(trimmed) : "*" + trimmed;
|
|
774
|
+
}
|
|
775
|
+
/**
|
|
776
|
+
* Parse a string path into an array of segments
|
|
777
|
+
*/
|
|
778
|
+
function parse(path) {
|
|
779
|
+
const keys = [];
|
|
780
|
+
let index = -1;
|
|
781
|
+
let mode = 0;
|
|
782
|
+
let subPathDepth = 0;
|
|
783
|
+
let c;
|
|
784
|
+
let key;
|
|
785
|
+
let newChar;
|
|
786
|
+
let type;
|
|
787
|
+
let transition;
|
|
788
|
+
let action;
|
|
789
|
+
let typeMap;
|
|
790
|
+
const actions = [];
|
|
791
|
+
actions[0] = () => {
|
|
792
|
+
if (key === void 0) key = newChar;
|
|
793
|
+
else key += newChar;
|
|
794
|
+
};
|
|
795
|
+
actions[1] = () => {
|
|
796
|
+
if (key !== void 0) {
|
|
797
|
+
keys.push(key);
|
|
798
|
+
key = void 0;
|
|
799
|
+
}
|
|
800
|
+
};
|
|
801
|
+
actions[2] = () => {
|
|
802
|
+
actions[0]();
|
|
803
|
+
subPathDepth++;
|
|
804
|
+
};
|
|
805
|
+
actions[3] = () => {
|
|
806
|
+
if (subPathDepth > 0) {
|
|
807
|
+
subPathDepth--;
|
|
808
|
+
mode = 4;
|
|
809
|
+
actions[0]();
|
|
810
|
+
} else {
|
|
811
|
+
subPathDepth = 0;
|
|
812
|
+
if (key === void 0) return false;
|
|
813
|
+
key = formatSubPath(key);
|
|
814
|
+
if (key === false) return false;
|
|
815
|
+
else actions[1]();
|
|
816
|
+
}
|
|
817
|
+
};
|
|
818
|
+
function maybeUnescapeQuote() {
|
|
819
|
+
const nextChar = path[index + 1];
|
|
820
|
+
if (mode === 5 && nextChar === "'" || mode === 6 && nextChar === "\"") {
|
|
821
|
+
index++;
|
|
822
|
+
newChar = "\\" + nextChar;
|
|
823
|
+
actions[0]();
|
|
824
|
+
return true;
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
while (mode !== null) {
|
|
828
|
+
index++;
|
|
829
|
+
c = path[index];
|
|
830
|
+
if (c === "\\" && maybeUnescapeQuote()) continue;
|
|
831
|
+
type = getPathCharType(c);
|
|
832
|
+
typeMap = pathStateMachine[mode];
|
|
833
|
+
transition = typeMap[type] || typeMap["l"] || 8;
|
|
834
|
+
if (transition === 8) return;
|
|
835
|
+
mode = transition[0];
|
|
836
|
+
if (transition[1] !== void 0) {
|
|
837
|
+
action = actions[transition[1]];
|
|
838
|
+
if (action) {
|
|
839
|
+
newChar = c;
|
|
840
|
+
if (action() === false) return;
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
if (mode === 7) return keys;
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
const cache = /* @__PURE__ */ new Map();
|
|
847
|
+
/**
|
|
848
|
+
* key-value message resolver
|
|
849
|
+
*
|
|
850
|
+
* @remarks
|
|
851
|
+
* Resolves messages with the key-value structure. Note that messages with a hierarchical structure such as objects cannot be resolved
|
|
852
|
+
*
|
|
853
|
+
* @param obj - A target object to be resolved with path
|
|
854
|
+
* @param path - A {@link Path | path} to resolve the value of message
|
|
855
|
+
*
|
|
856
|
+
* @returns A resolved {@link PathValue | path value}
|
|
857
|
+
*
|
|
858
|
+
* @VueI18nGeneral
|
|
859
|
+
*/
|
|
860
|
+
function resolveWithKeyValue(obj, path) {
|
|
861
|
+
return isObject(obj) ? getOwn(obj, path) : null;
|
|
862
|
+
}
|
|
863
|
+
/**
|
|
864
|
+
* message resolver
|
|
865
|
+
*
|
|
866
|
+
* @remarks
|
|
867
|
+
* Resolves messages. messages with a hierarchical structure such as objects can be resolved. This resolver is used in VueI18n as default.
|
|
868
|
+
*
|
|
869
|
+
* @param obj - A target object to be resolved with path
|
|
870
|
+
* @param path - A {@link Path | path} to resolve the value of message
|
|
871
|
+
*
|
|
872
|
+
* @returns A resolved {@link PathValue | path value}
|
|
873
|
+
*
|
|
874
|
+
* @VueI18nGeneral
|
|
875
|
+
*/
|
|
876
|
+
function resolveValue(obj, path) {
|
|
877
|
+
if (!isObject(obj)) return null;
|
|
878
|
+
let hit = cache.get(path);
|
|
879
|
+
if (!hit) {
|
|
880
|
+
hit = parse(path);
|
|
881
|
+
if (hit) cache.set(path, hit);
|
|
882
|
+
}
|
|
883
|
+
if (!hit) return null;
|
|
884
|
+
const len = hit.length;
|
|
885
|
+
let last = obj;
|
|
886
|
+
let i = 0;
|
|
887
|
+
while (i < len) {
|
|
888
|
+
const key = hit[i];
|
|
889
|
+
/**
|
|
890
|
+
* NOTE:
|
|
891
|
+
* if `key` is intlify message format AST node key and `last` is intlify message format AST, skip it.
|
|
892
|
+
* because the AST node is not a key-value structure.
|
|
893
|
+
*/
|
|
894
|
+
if (AST_NODE_PROPS_KEYS.includes(key) && isMessageAST(last)) return null;
|
|
895
|
+
if (!isObject(last)) return null;
|
|
896
|
+
if (!hasOwn(last, key)) return null;
|
|
897
|
+
const val = last[key];
|
|
898
|
+
if (val === void 0) return null;
|
|
899
|
+
if (isFunction(last)) return null;
|
|
900
|
+
last = val;
|
|
901
|
+
i++;
|
|
902
|
+
}
|
|
903
|
+
return last;
|
|
904
|
+
}
|
|
905
|
+
// packages/core-base/src/warnings.ts
|
|
906
|
+
const CoreWarnCodes = {
|
|
907
|
+
NOT_FOUND_KEY: 1,
|
|
908
|
+
FALLBACK_TO_TRANSLATE: 2,
|
|
909
|
+
CANNOT_FORMAT_NUMBER: 3,
|
|
910
|
+
FALLBACK_TO_NUMBER_FORMAT: 4,
|
|
911
|
+
CANNOT_FORMAT_DATE: 5,
|
|
912
|
+
FALLBACK_TO_DATE_FORMAT: 6,
|
|
913
|
+
EXPERIMENTAL_CUSTOM_MESSAGE_COMPILER: 7,
|
|
914
|
+
INVALID_NUMBER_ARGUMENT: 8,
|
|
915
|
+
INVALID_DATE_ARGUMENT: 9,
|
|
916
|
+
IGNORE_UNSAFE_LOCALE: 10,
|
|
917
|
+
FALLBACK_TO_DEFAULT_PLURAL_RULE: 11,
|
|
918
|
+
FALLBACK_FROM_INVALID_LOCALE: 12
|
|
919
|
+
};
|
|
920
|
+
const CORE_WARN_CODES_EXTEND_POINT = 13;
|
|
921
|
+
/** @internal */
|
|
922
|
+
const warnMessages = {
|
|
923
|
+
[CoreWarnCodes.NOT_FOUND_KEY]: `Not found '{key}' key in '{locale}' locale {resource}.`,
|
|
924
|
+
[CoreWarnCodes.FALLBACK_TO_TRANSLATE]: `Fall back to translate '{key}' key with '{target}' locale.`,
|
|
925
|
+
[CoreWarnCodes.CANNOT_FORMAT_NUMBER]: `Cannot format a number value due to not supported Intl.NumberFormat.`,
|
|
926
|
+
[CoreWarnCodes.FALLBACK_TO_NUMBER_FORMAT]: `Fall back to number format '{key}' key with '{target}' locale.`,
|
|
927
|
+
[CoreWarnCodes.CANNOT_FORMAT_DATE]: `Cannot format a date value due to not supported Intl.DateTimeFormat.`,
|
|
928
|
+
[CoreWarnCodes.FALLBACK_TO_DATE_FORMAT]: `Fall back to datetime format '{key}' key with '{target}' locale.`,
|
|
929
|
+
[CoreWarnCodes.EXPERIMENTAL_CUSTOM_MESSAGE_COMPILER]: `This project is using Custom Message Compiler, which is an experimental feature. It may receive breaking changes or be removed in the future.`,
|
|
930
|
+
[CoreWarnCodes.INVALID_NUMBER_ARGUMENT]: `Invalid argument for number formatting: expected a number but received '{value}'.`,
|
|
931
|
+
[CoreWarnCodes.INVALID_DATE_ARGUMENT]: `Invalid argument for datetime formatting: expected a Date, number, or ISO string but received '{value}'.`,
|
|
932
|
+
[CoreWarnCodes.IGNORE_UNSAFE_LOCALE]: `Ignore '{locale}' locale: it is a property name of Object.prototype`,
|
|
933
|
+
[CoreWarnCodes.FALLBACK_TO_DEFAULT_PLURAL_RULE]: `Fall back to the default plural rule for '{locale}' locale: Intl.PluralRules does not support it`,
|
|
934
|
+
[CoreWarnCodes.FALLBACK_FROM_INVALID_LOCALE]: `Fall back to '{target}' locale for {type} formatting with '{locale}' locale: it is not a BCP 47 language tag`
|
|
935
|
+
};
|
|
936
|
+
function getWarnMessage(code, ...args) {
|
|
937
|
+
return format$1(warnMessages[code], ...args);
|
|
938
|
+
}
|
|
939
|
+
// packages/core-base/src/context.ts
|
|
940
|
+
/**
|
|
941
|
+
* Intlify core-base version
|
|
942
|
+
* @internal
|
|
943
|
+
*/
|
|
944
|
+
const VERSION = "12.0.0-alpha.11";
|
|
945
|
+
const NOT_RESOLVED = -1;
|
|
946
|
+
const DEFAULT_LOCALE = "en-US";
|
|
947
|
+
const MISSING_RESOLVE_VALUE = "";
|
|
948
|
+
const capitalize = (str) => `${str.charAt(0).toLocaleUpperCase()}${str.substr(1)}`;
|
|
949
|
+
function getDefaultLinkedModifiers() {
|
|
950
|
+
return {
|
|
951
|
+
upper: (val, type) => {
|
|
952
|
+
return type === "text" && isString(val) ? val.toUpperCase() : type === "vnode" && isObject(val) && "__v_isVNode" in val ? val.children.toUpperCase() : val;
|
|
953
|
+
},
|
|
954
|
+
lower: (val, type) => {
|
|
955
|
+
return type === "text" && isString(val) ? val.toLowerCase() : type === "vnode" && isObject(val) && "__v_isVNode" in val ? val.children.toLowerCase() : val;
|
|
956
|
+
},
|
|
957
|
+
capitalize: (val, type) => {
|
|
958
|
+
return type === "text" && isString(val) ? capitalize(val) : type === "vnode" && isObject(val) && "__v_isVNode" in val ? capitalize(val.children) : val;
|
|
959
|
+
}
|
|
960
|
+
};
|
|
961
|
+
}
|
|
962
|
+
let _compiler;
|
|
963
|
+
/**
|
|
964
|
+
* Register the message compiler
|
|
965
|
+
*
|
|
966
|
+
* @param compiler - A {@link MessageCompiler} function
|
|
967
|
+
*
|
|
968
|
+
* @deprecated Use `messageCompiler` option of `createI18n` or `createCoreContext` instead. This function will be removed in v13.
|
|
969
|
+
*
|
|
970
|
+
* @VueI18nGeneral
|
|
971
|
+
*/
|
|
972
|
+
function registerMessageCompiler(compiler) {
|
|
973
|
+
warnOnce(`registerMessageCompiler is deprecated. Use 'messageCompiler' option of 'createI18n' or 'createCoreContext' instead.`);
|
|
974
|
+
_compiler = compiler;
|
|
975
|
+
}
|
|
976
|
+
let _resolver;
|
|
977
|
+
/**
|
|
978
|
+
* Register the message resolver
|
|
979
|
+
*
|
|
980
|
+
* @param resolver - A {@link MessageResolver} function
|
|
981
|
+
*
|
|
982
|
+
* @deprecated Use `messageResolver` option of `createI18n` or `createCoreContext` instead. This function will be removed in v13.
|
|
983
|
+
*
|
|
984
|
+
* @VueI18nGeneral
|
|
985
|
+
*/
|
|
986
|
+
function registerMessageResolver(resolver) {
|
|
987
|
+
warnOnce(`registerMessageResolver is deprecated. Use 'messageResolver' option of 'createI18n' or 'createCoreContext' instead.`);
|
|
988
|
+
_resolver = resolver;
|
|
989
|
+
}
|
|
990
|
+
let _fallbacker;
|
|
991
|
+
/**
|
|
992
|
+
* Register the locale fallbacker
|
|
993
|
+
*
|
|
994
|
+
* @param fallbacker - A {@link LocaleFallbacker} function
|
|
995
|
+
*
|
|
996
|
+
* @deprecated Use `localeFallbacker` option of `createI18n` or `createCoreContext` instead. This function will be removed in v13.
|
|
997
|
+
*
|
|
998
|
+
* @VueI18nGeneral
|
|
999
|
+
*/
|
|
1000
|
+
function registerLocaleFallbacker(fallbacker) {
|
|
1001
|
+
warnOnce(`registerLocaleFallbacker is deprecated. Use 'localeFallbacker' option of 'createI18n' or 'createCoreContext' instead.`);
|
|
1002
|
+
_fallbacker = fallbacker;
|
|
1003
|
+
}
|
|
1004
|
+
let _cid = 0;
|
|
1005
|
+
function createCoreContext(options = {}) {
|
|
1006
|
+
const onWarn = isFunction(options.onWarn) ? options.onWarn : warn;
|
|
1007
|
+
const version = isString(options.version) ? options.version : VERSION;
|
|
1008
|
+
const locale = isString(options.locale) || isFunction(options.locale) ? options.locale : DEFAULT_LOCALE;
|
|
1009
|
+
const _locale = isFunction(locale) ? DEFAULT_LOCALE : locale;
|
|
1010
|
+
const fallbackLocale = isFallbackLocale(options.fallbackLocale) ? options.fallbackLocale : _locale;
|
|
1011
|
+
const messages = isPlainObject(options.messages) ? options.messages : createResources(_locale);
|
|
1012
|
+
const datetimeFormats = isPlainObject(options.datetimeFormats) ? options.datetimeFormats : createResources(_locale);
|
|
1013
|
+
const numberFormats = isPlainObject(options.numberFormats) ? options.numberFormats : createResources(_locale);
|
|
1014
|
+
const modifiers = assign(create(), options.modifiers, getDefaultLinkedModifiers());
|
|
1015
|
+
const pluralRules = options.pluralRules || create();
|
|
1016
|
+
const missing = isFunction(options.missing) ? options.missing : null;
|
|
1017
|
+
const missingWarn = isWarnOption(options.missingWarn) ? options.missingWarn : true;
|
|
1018
|
+
const fallbackWarn = isWarnOption(options.fallbackWarn) ? options.fallbackWarn : true;
|
|
1019
|
+
const fallbackFormat = !!options.fallbackFormat;
|
|
1020
|
+
const unresolving = !!options.unresolving;
|
|
1021
|
+
const postTranslation = isFunction(options.postTranslation) ? options.postTranslation : null;
|
|
1022
|
+
const processor = isPlainObject(options.processor) ? options.processor : null;
|
|
1023
|
+
const warnHtmlMessage = isBoolean(options.warnHtmlMessage) ? options.warnHtmlMessage : true;
|
|
1024
|
+
const escapeParameter = !!options.escapeParameter;
|
|
1025
|
+
const messageCompiler = isFunction(options.messageCompiler) ? options.messageCompiler : _compiler || null;
|
|
1026
|
+
const messageResolver = isFunction(options.messageResolver) ? options.messageResolver : _resolver || resolveWithKeyValue;
|
|
1027
|
+
const localeFallbacker = isFunction(options.localeFallbacker) ? options.localeFallbacker : _fallbacker || fallbackWithSimple;
|
|
1028
|
+
const fallbackContext = isObject(options.fallbackContext) ? options.fallbackContext : void 0;
|
|
1029
|
+
_cid++;
|
|
1030
|
+
const context = {
|
|
1031
|
+
version,
|
|
1032
|
+
cid: _cid,
|
|
1033
|
+
locale,
|
|
1034
|
+
fallbackLocale,
|
|
1035
|
+
messages,
|
|
1036
|
+
modifiers,
|
|
1037
|
+
pluralRules,
|
|
1038
|
+
missing,
|
|
1039
|
+
missingWarn,
|
|
1040
|
+
fallbackWarn,
|
|
1041
|
+
fallbackFormat,
|
|
1042
|
+
unresolving,
|
|
1043
|
+
postTranslation,
|
|
1044
|
+
processor,
|
|
1045
|
+
warnHtmlMessage,
|
|
1046
|
+
escapeParameter,
|
|
1047
|
+
messageCompiler,
|
|
1048
|
+
messageResolver,
|
|
1049
|
+
localeFallbacker,
|
|
1050
|
+
fallbackContext,
|
|
1051
|
+
onWarn
|
|
1052
|
+
};
|
|
1053
|
+
context.datetimeFormats = datetimeFormats;
|
|
1054
|
+
context.numberFormats = numberFormats;
|
|
1055
|
+
context.__datetimeFormatters = /* @__PURE__ */ new Map();
|
|
1056
|
+
context.__numberFormatters = /* @__PURE__ */ new Map();
|
|
1057
|
+
return context;
|
|
1058
|
+
}
|
|
1059
|
+
const createResources = (locale) => ({ [locale]: create() });
|
|
1060
|
+
/**
|
|
1061
|
+
* @version 12.0.0
|
|
1062
|
+
*/
|
|
1063
|
+
function getLocaleMessage(ctx, locale) {
|
|
1064
|
+
const src = getOwn(ctx.messages, locale);
|
|
1065
|
+
if (src == null) return;
|
|
1066
|
+
const dest = create();
|
|
1067
|
+
deepCopy(src, dest);
|
|
1068
|
+
return dest;
|
|
1069
|
+
}
|
|
1070
|
+
/**
|
|
1071
|
+
* @version 12.0.0
|
|
1072
|
+
*/
|
|
1073
|
+
function setLocaleMessage(ctx, locale, messages) {
|
|
1074
|
+
if (isObjectPrototypeKey(locale)) {
|
|
1075
|
+
ctx.onWarn(getWarnMessage(CoreWarnCodes.IGNORE_UNSAFE_LOCALE, { locale }));
|
|
1076
|
+
return;
|
|
1077
|
+
}
|
|
1078
|
+
ctx.messages[locale] = messages;
|
|
1079
|
+
}
|
|
1080
|
+
/** @internal */
|
|
1081
|
+
function isFallbackLocale(val) {
|
|
1082
|
+
return isString(val) || isArray(val) || isPlainObject(val) || val === false;
|
|
1083
|
+
}
|
|
1084
|
+
/** @internal */
|
|
1085
|
+
function isWarnOption(val) {
|
|
1086
|
+
return isBoolean(val) || isRegExp(val);
|
|
1087
|
+
}
|
|
1088
|
+
/** @internal */
|
|
1089
|
+
function isTranslateFallbackWarn(fallback, key) {
|
|
1090
|
+
return isRegExp(fallback) ? fallback.test(key) : fallback;
|
|
1091
|
+
}
|
|
1092
|
+
/** @internal */
|
|
1093
|
+
function isTranslateMissingWarn(missing, key) {
|
|
1094
|
+
return isRegExp(missing) ? missing.test(key) : missing;
|
|
1095
|
+
}
|
|
1096
|
+
/** @internal */
|
|
1097
|
+
function handleMissing(context, key, locale, missingWarn, type) {
|
|
1098
|
+
const { missing, onWarn } = context;
|
|
1099
|
+
{
|
|
1100
|
+
const emitter = context.__v_emitter;
|
|
1101
|
+
if (emitter) emitter.emit("missing", {
|
|
1102
|
+
locale,
|
|
1103
|
+
key,
|
|
1104
|
+
type,
|
|
1105
|
+
groupId: toDevtoolsGroupId(type, key)
|
|
1106
|
+
});
|
|
1107
|
+
}
|
|
1108
|
+
if (missing !== null) {
|
|
1109
|
+
const ret = missing(context, locale, key, type);
|
|
1110
|
+
return isString(ret) ? ret : key;
|
|
1111
|
+
} else {
|
|
1112
|
+
if (isTranslateMissingWarn(missingWarn, key)) onWarn(getWarnMessage(CoreWarnCodes.NOT_FOUND_KEY, {
|
|
1113
|
+
key,
|
|
1114
|
+
locale,
|
|
1115
|
+
resource: type === "datetime format" ? "datetime formats" : type === "number format" ? "number formats" : "messages"
|
|
1116
|
+
}));
|
|
1117
|
+
return key;
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
function invalidateLocaleChainCache(ctx, fallback) {
|
|
1121
|
+
const context = ctx;
|
|
1122
|
+
if (isObject(fallback)) context.__localeChainObjectCache?.delete(fallback);
|
|
1123
|
+
else context.__localeChainCache?.delete(fallback);
|
|
1124
|
+
}
|
|
1125
|
+
/** @internal */
|
|
1126
|
+
function updateFallbackLocale(ctx, locale, fallback) {
|
|
1127
|
+
invalidateLocaleChainCache(ctx, fallback);
|
|
1128
|
+
if (ctx.fallbackContext) invalidateLocaleChainCache(ctx.fallbackContext, fallback);
|
|
1129
|
+
{
|
|
1130
|
+
const { __datetimeFormatters, __numberFormatters } = ctx;
|
|
1131
|
+
__datetimeFormatters.clear();
|
|
1132
|
+
__numberFormatters.clear();
|
|
1133
|
+
}
|
|
1134
|
+
ctx.localeFallbacker(ctx, fallback, locale);
|
|
1135
|
+
}
|
|
1136
|
+
/** @internal */
|
|
1137
|
+
function isAlmostSameLocale(locale, compareLocale) {
|
|
1138
|
+
if (locale === compareLocale) return false;
|
|
1139
|
+
return locale.split("-")[0] === compareLocale.split("-")[0];
|
|
1140
|
+
}
|
|
1141
|
+
/** @internal */
|
|
1142
|
+
function isImplicitFallback(targetLocale, locales) {
|
|
1143
|
+
const index = locales.indexOf(targetLocale);
|
|
1144
|
+
if (index === -1) return false;
|
|
1145
|
+
for (let i = index + 1; i < locales.length; i++) if (isAlmostSameLocale(targetLocale, locales[i])) return true;
|
|
1146
|
+
return false;
|
|
1147
|
+
}
|
|
1148
|
+
// packages/core-base/src/formatter.ts
|
|
1149
|
+
function resolveFormatLocale(context, key, locale, formats, missingWarn, fallbackWarn, type) {
|
|
1150
|
+
const { fallbackLocale, localeFallbacker, onWarn } = context;
|
|
1151
|
+
const locales = localeFallbacker(context, fallbackLocale, locale);
|
|
1152
|
+
let from = locale;
|
|
1153
|
+
for (let i = 0; i < locales.length; i++) {
|
|
1154
|
+
const targetLocale = locales[i];
|
|
1155
|
+
if (locale !== targetLocale && isTranslateFallbackWarn(fallbackWarn, key)) onWarn(getWarnMessage(type === "datetime format" ? CoreWarnCodes.FALLBACK_TO_DATE_FORMAT : CoreWarnCodes.FALLBACK_TO_NUMBER_FORMAT, {
|
|
1156
|
+
key,
|
|
1157
|
+
target: targetLocale
|
|
1158
|
+
}));
|
|
1159
|
+
if (locale !== targetLocale) {
|
|
1160
|
+
const emitter = context.__v_emitter;
|
|
1161
|
+
if (emitter) emitter.emit("fallback", {
|
|
1162
|
+
type,
|
|
1163
|
+
key,
|
|
1164
|
+
from,
|
|
1165
|
+
to: targetLocale,
|
|
1166
|
+
groupId: toDevtoolsGroupId(type, key)
|
|
1167
|
+
});
|
|
1168
|
+
}
|
|
1169
|
+
const format = getOwn(getOwn(formats, targetLocale) || {}, key);
|
|
1170
|
+
if (isPlainObject(format) && isString(targetLocale)) return targetLocale;
|
|
1171
|
+
handleMissing(context, key, targetLocale, missingWarn, type);
|
|
1172
|
+
from = targetLocale;
|
|
1173
|
+
}
|
|
1174
|
+
return null;
|
|
1175
|
+
}
|
|
1176
|
+
function isLanguageTag(locale) {
|
|
1177
|
+
try {
|
|
1178
|
+
Intl.getCanonicalLocales(locale);
|
|
1179
|
+
return true;
|
|
1180
|
+
} catch {
|
|
1181
|
+
return false;
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
/**
|
|
1185
|
+
* Create an `Intl.DateTimeFormat` or `Intl.NumberFormat` formatter
|
|
1186
|
+
*
|
|
1187
|
+
* @remarks
|
|
1188
|
+
* `Intl` throws a RangeError for a locale that is not a BCP 47 language tag (e.g. `pt_BR`),
|
|
1189
|
+
* so fall back to the first language tag in the locale chain, or the default locale
|
|
1190
|
+
*/
|
|
1191
|
+
function createFormatter(context, IntlFormatter, locale, options, type) {
|
|
1192
|
+
try {
|
|
1193
|
+
return new IntlFormatter(locale, options);
|
|
1194
|
+
} catch (error) {
|
|
1195
|
+
if (isLanguageTag(locale)) throw error;
|
|
1196
|
+
const { fallbackLocale, localeFallbacker, onWarn } = context;
|
|
1197
|
+
const target = localeFallbacker(context, fallbackLocale, locale).find(isLanguageTag) || "en-US";
|
|
1198
|
+
onWarn(getWarnMessage(CoreWarnCodes.FALLBACK_FROM_INVALID_LOCALE, {
|
|
1199
|
+
locale,
|
|
1200
|
+
target,
|
|
1201
|
+
type: type === "datetime format" ? "datetime" : "number"
|
|
1202
|
+
}));
|
|
1203
|
+
return new IntlFormatter(target, options);
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
/**
|
|
1207
|
+
* Format a value with the format of a key, or only with the overrides when no key is given
|
|
1208
|
+
*
|
|
1209
|
+
* @remarks
|
|
1210
|
+
* The common part of `datetime()` and `number()`, after they check and parse the arguments
|
|
1211
|
+
*/
|
|
1212
|
+
function formatValue(context, [key, value, options, overrides], IntlFormatter, formatters, formats, type) {
|
|
1213
|
+
const missingWarn = isBoolean(options.missingWarn) ? options.missingWarn : context.missingWarn;
|
|
1214
|
+
const fallbackWarn = isBoolean(options.fallbackWarn) ? options.fallbackWarn : context.fallbackWarn;
|
|
1215
|
+
const part = !!options.part;
|
|
1216
|
+
const locale = getLocale(context, options);
|
|
1217
|
+
if (!isString(key) || key === "") {
|
|
1218
|
+
const formatter = createFormatter(context, IntlFormatter, locale.replace(/!/g, ""), overrides, type);
|
|
1219
|
+
return !part ? formatter.format(value) : formatter.formatToParts(value);
|
|
1220
|
+
}
|
|
1221
|
+
const targetLocale = resolveFormatLocale(context, key, locale, formats, missingWarn, fallbackWarn, type);
|
|
1222
|
+
if (!isString(targetLocale)) return context.unresolving ? -1 : key;
|
|
1223
|
+
const format = formats[targetLocale][key];
|
|
1224
|
+
const id = getFormatterCacheKey(targetLocale, key, overrides);
|
|
1225
|
+
let formatter = formatters.get(id);
|
|
1226
|
+
if (!formatter) {
|
|
1227
|
+
formatter = createFormatter(context, IntlFormatter, targetLocale, assign({}, format, overrides), type);
|
|
1228
|
+
formatters.set(id, formatter);
|
|
1229
|
+
}
|
|
1230
|
+
return !part ? formatter.format(value) : formatter.formatToParts(value);
|
|
1231
|
+
}
|
|
1232
|
+
function getFormatterCacheKey(locale, key, overrides) {
|
|
1233
|
+
let id = `${locale}__${key}`;
|
|
1234
|
+
if (isPlainObject(overrides) && !isKeylessObject(overrides)) id = `${id}__${JSON.stringify(overrides)}`;
|
|
1235
|
+
return id;
|
|
1236
|
+
}
|
|
1237
|
+
function clearFormatCache(formatters, locale, format) {
|
|
1238
|
+
for (const key in format) {
|
|
1239
|
+
const prefix = `${locale}__${key}`;
|
|
1240
|
+
for (const id of formatters.keys()) if (id === prefix || id.startsWith(`${prefix}__`)) formatters.delete(id);
|
|
1241
|
+
}
|
|
1242
|
+
}
|
|
1243
|
+
function parseFormatArgs(args, options, initialOverrides, optionsKeys) {
|
|
1244
|
+
const [, arg2, arg3, arg4] = args;
|
|
1245
|
+
let overrides = initialOverrides;
|
|
1246
|
+
if (isString(arg2)) options.key = arg2;
|
|
1247
|
+
else if (isPlainObject(arg2)) Object.keys(arg2).forEach((key) => {
|
|
1248
|
+
if (optionsKeys.includes(key)) overrides[key] = arg2[key];
|
|
1249
|
+
else options[key] = arg2[key];
|
|
1250
|
+
});
|
|
1251
|
+
if (isString(arg3)) options.locale = arg3;
|
|
1252
|
+
else if (isPlainObject(arg3)) overrides = arg3;
|
|
1253
|
+
if (isPlainObject(arg4)) overrides = arg4;
|
|
1254
|
+
return overrides;
|
|
1255
|
+
}
|
|
1256
|
+
// packages/core-base/src/intl.ts
|
|
1257
|
+
const intlDefined = typeof Intl !== "undefined";
|
|
1258
|
+
const Availabilities = {
|
|
1259
|
+
dateTimeFormat: intlDefined && typeof Intl.DateTimeFormat !== "undefined",
|
|
1260
|
+
numberFormat: intlDefined && typeof Intl.NumberFormat !== "undefined"
|
|
1261
|
+
};
|
|
1262
|
+
// packages/core-base/src/datetime.ts
|
|
1263
|
+
function datetime(context, ...args) {
|
|
1264
|
+
const { datetimeFormats, onWarn } = context;
|
|
1265
|
+
const { __datetimeFormatters } = context;
|
|
1266
|
+
if (!Availabilities.dateTimeFormat) {
|
|
1267
|
+
onWarn(getWarnMessage(CoreWarnCodes.CANNOT_FORMAT_DATE));
|
|
1268
|
+
return "";
|
|
1269
|
+
}
|
|
1270
|
+
if (!isString(args[0]) && !isDate(args[0]) && !isNumber(args[0])) {
|
|
1271
|
+
onWarn(getWarnMessage(CoreWarnCodes.INVALID_DATE_ARGUMENT, { value: String(args[0]) }));
|
|
1272
|
+
return "";
|
|
1273
|
+
}
|
|
1274
|
+
return formatValue(context, parseDateTimeArgs(...args), Intl.DateTimeFormat, __datetimeFormatters, datetimeFormats, "datetime format");
|
|
1275
|
+
}
|
|
1276
|
+
/** @internal */
|
|
1277
|
+
const DATETIME_FORMAT_OPTIONS_KEYS = [
|
|
1278
|
+
"localeMatcher",
|
|
1279
|
+
"weekday",
|
|
1280
|
+
"era",
|
|
1281
|
+
"year",
|
|
1282
|
+
"month",
|
|
1283
|
+
"day",
|
|
1284
|
+
"hour",
|
|
1285
|
+
"minute",
|
|
1286
|
+
"second",
|
|
1287
|
+
"timeZoneName",
|
|
1288
|
+
"formatMatcher",
|
|
1289
|
+
"hour12",
|
|
1290
|
+
"timeZone",
|
|
1291
|
+
"dateStyle",
|
|
1292
|
+
"timeStyle",
|
|
1293
|
+
"calendar",
|
|
1294
|
+
"dayPeriod",
|
|
1295
|
+
"numberingSystem",
|
|
1296
|
+
"hourCycle",
|
|
1297
|
+
"fractionalSecondDigits"
|
|
1298
|
+
];
|
|
1299
|
+
/** @internal */
|
|
1300
|
+
function parseDateTimeArgs(...args) {
|
|
1301
|
+
const [arg1] = args;
|
|
1302
|
+
const options = create();
|
|
1303
|
+
const initialOverrides = create();
|
|
1304
|
+
let value;
|
|
1305
|
+
if (isString(arg1)) {
|
|
1306
|
+
const matches = arg1.match(/^(\d{4}-\d{2}-\d{2})(?:(T|\s)(.+))?$/);
|
|
1307
|
+
if (!matches) throw createCoreError(CoreErrorCodes.INVALID_ISO_DATE_ARGUMENT);
|
|
1308
|
+
const dateTime = matches[3] ? matches[3].trim().startsWith("T") ? `${matches[1].trim()}${matches[3].trim()}` : `${matches[1].trim()}T${matches[3].trim()}` : matches[1].trim();
|
|
1309
|
+
value = new Date(dateTime);
|
|
1310
|
+
try {
|
|
1311
|
+
value.toISOString();
|
|
1312
|
+
} catch {
|
|
1313
|
+
throw createCoreError(CoreErrorCodes.INVALID_ISO_DATE_ARGUMENT);
|
|
1314
|
+
}
|
|
1315
|
+
} else if (isDate(arg1)) {
|
|
1316
|
+
if (isNaN(arg1.getTime())) throw createCoreError(CoreErrorCodes.INVALID_DATE_ARGUMENT);
|
|
1317
|
+
value = arg1;
|
|
1318
|
+
} else if (isNumber(arg1)) value = arg1;
|
|
1319
|
+
else throw createCoreError(CoreErrorCodes.INVALID_ARGUMENT);
|
|
1320
|
+
const overrides = parseFormatArgs(args, options, initialOverrides, DATETIME_FORMAT_OPTIONS_KEYS);
|
|
1321
|
+
return [
|
|
1322
|
+
options.key || "",
|
|
1323
|
+
value,
|
|
1324
|
+
options,
|
|
1325
|
+
overrides
|
|
1326
|
+
];
|
|
1327
|
+
}
|
|
1328
|
+
/** @internal */
|
|
1329
|
+
function clearDateTimeFormat(ctx, locale, format) {
|
|
1330
|
+
clearFormatCache(ctx.__datetimeFormatters, locale, format);
|
|
1331
|
+
}
|
|
1332
|
+
// packages/core-base/src/number.ts
|
|
1333
|
+
function number(context, ...args) {
|
|
1334
|
+
const { numberFormats, onWarn } = context;
|
|
1335
|
+
const { __numberFormatters } = context;
|
|
1336
|
+
if (!Availabilities.numberFormat) {
|
|
1337
|
+
onWarn(getWarnMessage(CoreWarnCodes.CANNOT_FORMAT_NUMBER));
|
|
1338
|
+
return "";
|
|
1339
|
+
}
|
|
1340
|
+
if (!isNumber(args[0])) {
|
|
1341
|
+
onWarn(getWarnMessage(CoreWarnCodes.INVALID_NUMBER_ARGUMENT, { value: String(args[0]) }));
|
|
1342
|
+
return "";
|
|
1343
|
+
}
|
|
1344
|
+
return formatValue(context, parseNumberArgs(...args), Intl.NumberFormat, __numberFormatters, numberFormats, "number format");
|
|
1345
|
+
}
|
|
1346
|
+
/** @internal */
|
|
1347
|
+
const NUMBER_FORMAT_OPTIONS_KEYS = [
|
|
1348
|
+
"localeMatcher",
|
|
1349
|
+
"style",
|
|
1350
|
+
"currency",
|
|
1351
|
+
"currencyDisplay",
|
|
1352
|
+
"currencySign",
|
|
1353
|
+
"useGrouping",
|
|
1354
|
+
"minimumIntegerDigits",
|
|
1355
|
+
"minimumFractionDigits",
|
|
1356
|
+
"maximumFractionDigits",
|
|
1357
|
+
"minimumSignificantDigits",
|
|
1358
|
+
"maximumSignificantDigits",
|
|
1359
|
+
"compactDisplay",
|
|
1360
|
+
"notation",
|
|
1361
|
+
"signDisplay",
|
|
1362
|
+
"unit",
|
|
1363
|
+
"unitDisplay",
|
|
1364
|
+
"roundingMode",
|
|
1365
|
+
"roundingPriority",
|
|
1366
|
+
"roundingIncrement",
|
|
1367
|
+
"trailingZeroDisplay"
|
|
1368
|
+
];
|
|
1369
|
+
/** @internal */
|
|
1370
|
+
function parseNumberArgs(...args) {
|
|
1371
|
+
const [arg1] = args;
|
|
1372
|
+
const options = create();
|
|
1373
|
+
const initialOverrides = create();
|
|
1374
|
+
if (!isNumber(arg1)) throw createCoreError(CoreErrorCodes.INVALID_ARGUMENT);
|
|
1375
|
+
const value = arg1;
|
|
1376
|
+
const overrides = parseFormatArgs(args, options, initialOverrides, NUMBER_FORMAT_OPTIONS_KEYS);
|
|
1377
|
+
return [
|
|
1378
|
+
options.key || "",
|
|
1379
|
+
value,
|
|
1380
|
+
options,
|
|
1381
|
+
overrides
|
|
1382
|
+
];
|
|
1383
|
+
}
|
|
1384
|
+
/** @internal */
|
|
1385
|
+
function clearNumberFormat(ctx, locale, format) {
|
|
1386
|
+
clearFormatCache(ctx.__numberFormatters, locale, format);
|
|
1387
|
+
}
|
|
1388
|
+
// packages/core-base/src/runtime.ts
|
|
1389
|
+
const DEFAULT_MODIFIER = (str) => str;
|
|
1390
|
+
const DEFAULT_MESSAGE = (_ctx) => "";
|
|
1391
|
+
const DEFAULT_MESSAGE_DATA_TYPE = "text";
|
|
1392
|
+
const DEFAULT_NORMALIZE = (values) => values.length === 0 ? "" : join(values);
|
|
1393
|
+
const DEFAULT_INTERPOLATE = toDisplayString;
|
|
1394
|
+
function pluralDefault(choice, choicesLength) {
|
|
1395
|
+
choice = Math.abs(choice);
|
|
1396
|
+
if (choicesLength === 2) return choice === 1 ? 0 : 1;
|
|
1397
|
+
return Math.min(choice, 2);
|
|
1398
|
+
}
|
|
1399
|
+
const PLURAL_CATEGORY_ORDER = [
|
|
1400
|
+
"zero",
|
|
1401
|
+
"one",
|
|
1402
|
+
"two",
|
|
1403
|
+
"few",
|
|
1404
|
+
"many",
|
|
1405
|
+
"other"
|
|
1406
|
+
];
|
|
1407
|
+
const intlPluralRulesCache = /* @__PURE__ */ new Map();
|
|
1408
|
+
const INTL_PLURAL_RULES_CACHE_SIZE = 1e3;
|
|
1409
|
+
function createIntlPluralRules(locale) {
|
|
1410
|
+
try {
|
|
1411
|
+
if (Intl.PluralRules.supportedLocalesOf(locale).length === 0) return null;
|
|
1412
|
+
const rules = new Intl.PluralRules(locale);
|
|
1413
|
+
return {
|
|
1414
|
+
rules,
|
|
1415
|
+
categories: rules.resolvedOptions().pluralCategories.slice().sort((a, b) => PLURAL_CATEGORY_ORDER.indexOf(a) - PLURAL_CATEGORY_ORDER.indexOf(b))
|
|
1416
|
+
};
|
|
1417
|
+
} catch {
|
|
1418
|
+
return null;
|
|
1419
|
+
}
|
|
1420
|
+
}
|
|
1421
|
+
function getIntlPluralRules(locale) {
|
|
1422
|
+
let cached = intlPluralRulesCache.get(locale);
|
|
1423
|
+
if (cached === void 0) {
|
|
1424
|
+
cached = createIntlPluralRules(locale);
|
|
1425
|
+
if (cached === null) warn(getWarnMessage(CoreWarnCodes.FALLBACK_TO_DEFAULT_PLURAL_RULE, { locale }));
|
|
1426
|
+
if (intlPluralRulesCache.size >= INTL_PLURAL_RULES_CACHE_SIZE) intlPluralRulesCache.delete(intlPluralRulesCache.keys().next().value);
|
|
1427
|
+
intlPluralRulesCache.set(locale, cached);
|
|
1428
|
+
}
|
|
1429
|
+
return cached;
|
|
1430
|
+
}
|
|
1431
|
+
function getPluralIndex(options) {
|
|
1432
|
+
if (isNumber(options.pluralIndex)) return options.pluralIndex;
|
|
1433
|
+
return isNumber(options.named?.count) ? options.named.count : isNumber(options.named?.n) ? options.named.n : -1;
|
|
1434
|
+
}
|
|
1435
|
+
function createMessageContext(options = {}) {
|
|
1436
|
+
const locale = options.locale;
|
|
1437
|
+
const pluralIndex = getPluralIndex(options);
|
|
1438
|
+
let resolvedPluralRule;
|
|
1439
|
+
if (isString(locale) && options.pluralRules && isFunction(getOwn(options.pluralRules, locale))) resolvedPluralRule = options.pluralRules[locale];
|
|
1440
|
+
else if (isString(locale) && typeof Intl !== "undefined" && typeof Intl.PluralRules !== "undefined") resolvedPluralRule = (choice, choicesLength) => {
|
|
1441
|
+
const intlPluralRules = getIntlPluralRules(locale);
|
|
1442
|
+
if (intlPluralRules === null || choicesLength > intlPluralRules.categories.length) return pluralDefault(choice, choicesLength);
|
|
1443
|
+
const { rules, categories } = intlPluralRules;
|
|
1444
|
+
const category = rules.select(Math.abs(choice));
|
|
1445
|
+
const index = categories.indexOf(category);
|
|
1446
|
+
return Math.min(index === -1 ? choicesLength - 1 : index, choicesLength - 1);
|
|
1447
|
+
};
|
|
1448
|
+
else resolvedPluralRule = pluralDefault;
|
|
1449
|
+
const orgPluralRule = resolvedPluralRule === pluralDefault ? void 0 : pluralDefault;
|
|
1450
|
+
const plural = (messages) => messages[resolvedPluralRule(pluralIndex, messages.length, orgPluralRule)];
|
|
1451
|
+
const _list = options.list || [];
|
|
1452
|
+
const list = (index) => _list[index];
|
|
1453
|
+
const _named = options.named || create();
|
|
1454
|
+
const hasPluralIndex = isNumber(options.pluralIndex);
|
|
1455
|
+
const named = (key) => {
|
|
1456
|
+
const value = isObjectPrototypeKey(key) ? getOwn(_named, key) : _named[key];
|
|
1457
|
+
return hasPluralIndex && value == null && (key === "count" || key === "n") ? options.pluralIndex : value;
|
|
1458
|
+
};
|
|
1459
|
+
function message(key, useLinked) {
|
|
1460
|
+
const msg = isFunction(options.messages) ? options.messages(key, !!useLinked) : isObject(options.messages) ? options.messages[key] : false;
|
|
1461
|
+
return !msg ? options.parent ? options.parent.message(key) : DEFAULT_MESSAGE : msg;
|
|
1462
|
+
}
|
|
1463
|
+
const _modifier = (name) => options.modifiers ? getOwn(options.modifiers, name) : DEFAULT_MODIFIER;
|
|
1464
|
+
const normalize = isFunction(options.processor?.normalize) ? options.processor.normalize : DEFAULT_NORMALIZE;
|
|
1465
|
+
const interpolate = isFunction(options.processor?.interpolate) ? options.processor.interpolate : DEFAULT_INTERPOLATE;
|
|
1466
|
+
const type = isString(options.processor?.type) ? options.processor.type : DEFAULT_MESSAGE_DATA_TYPE;
|
|
1467
|
+
const linked = (key, ...args) => {
|
|
1468
|
+
const [arg1, arg2] = args;
|
|
1469
|
+
let type = "text";
|
|
1470
|
+
let modifier = "";
|
|
1471
|
+
if (args.length === 1) {
|
|
1472
|
+
if (isObject(arg1)) {
|
|
1473
|
+
modifier = arg1.modifier || modifier;
|
|
1474
|
+
type = arg1.type || type;
|
|
1475
|
+
} else if (isString(arg1)) modifier = arg1 || modifier;
|
|
1476
|
+
} else if (args.length === 2) {
|
|
1477
|
+
if (isString(arg1)) modifier = arg1 || modifier;
|
|
1478
|
+
if (isString(arg2)) type = arg2 || type;
|
|
1479
|
+
}
|
|
1480
|
+
const ret = message(key, true)(ctx);
|
|
1481
|
+
const resolved = ret === "" || ret === void 0 ? key : ret;
|
|
1482
|
+
const msg = type === "vnode" && isArray(resolved) && modifier ? resolved[0] : resolved;
|
|
1483
|
+
if (!modifier) return msg;
|
|
1484
|
+
const modify = _modifier(modifier);
|
|
1485
|
+
if (isFunction(modify)) return modify(msg, type);
|
|
1486
|
+
warnOnce(`Not found '${modifier}' modifier for the linked message of '${key}' key. Use a built-in modifier, or set a custom modifier with 'modifiers' option. So the linked message is used as is.`);
|
|
1487
|
+
return msg;
|
|
1488
|
+
};
|
|
1489
|
+
const ctx = {
|
|
1490
|
+
["list"]: list,
|
|
1491
|
+
["named"]: named,
|
|
1492
|
+
["plural"]: plural,
|
|
1493
|
+
["linked"]: linked,
|
|
1494
|
+
["message"]: message,
|
|
1495
|
+
["type"]: type,
|
|
1496
|
+
["interpolate"]: interpolate,
|
|
1497
|
+
["normalize"]: normalize,
|
|
1498
|
+
["values"]: assign(create(), _list, _named, hasPluralIndex ? {
|
|
1499
|
+
count: named("count"),
|
|
1500
|
+
n: named("n")
|
|
1501
|
+
} : {})
|
|
1502
|
+
};
|
|
1503
|
+
return ctx;
|
|
1504
|
+
}
|
|
1505
|
+
// packages/core-base/src/translate.ts
|
|
1506
|
+
const NOOP_MESSAGE_FUNCTION = () => "";
|
|
1507
|
+
const isMessageFunction = (val) => isFunction(val);
|
|
1508
|
+
/** @internal */
|
|
1509
|
+
const isMessageFormat = (val) => isString(val) || isMessageAST(val) || isMessageFunction(val);
|
|
1510
|
+
function translate(context, ...args) {
|
|
1511
|
+
const [key, options] = parseTranslateArgs(...args);
|
|
1512
|
+
const locale = getLocale(context, options);
|
|
1513
|
+
const escapeParameter = isBoolean(options.escapeParameter) ? options.escapeParameter : context.escapeParameter;
|
|
1514
|
+
escapeParameter && escapeParams(options);
|
|
1515
|
+
const resolvedMessage = !!options.resolvedMessage;
|
|
1516
|
+
let [format, targetLocale, message] = !resolvedMessage ? resolveMessageFormat(context, key, locale, context.fallbackLocale, isBoolean(options.fallbackWarn) ? options.fallbackWarn : context.fallbackWarn, isBoolean(options.missingWarn) ? options.missingWarn : context.missingWarn) : [
|
|
1517
|
+
key,
|
|
1518
|
+
locale,
|
|
1519
|
+
getOwn(context.messages, locale) || create()
|
|
1520
|
+
];
|
|
1521
|
+
let cacheBaseKey = key;
|
|
1522
|
+
if (!resolvedMessage && !isMessageFormat(format)) {
|
|
1523
|
+
const defaultMsgOrKey = isString(options.default) ? options.default : isBoolean(options.default) || context.fallbackFormat ? !context.messageCompiler ? () => key : key : null;
|
|
1524
|
+
if (context.fallbackFormat || defaultMsgOrKey != null && (isString(defaultMsgOrKey) || isFunction(defaultMsgOrKey))) {
|
|
1525
|
+
format = defaultMsgOrKey;
|
|
1526
|
+
cacheBaseKey = format;
|
|
1527
|
+
}
|
|
1528
|
+
}
|
|
1529
|
+
if (!resolvedMessage && (!isMessageFormat(format) || !isString(targetLocale))) return context.unresolving ? -1 : key;
|
|
1530
|
+
if (isString(format) && context.messageCompiler == null) warn(`Cannot compile the message of '${stringifyKey(key)}' key, because no message compiler is set. Use 'messageCompiler' option of 'createCoreContext', or pre-compile the message. So translate function returns the message as is.`);
|
|
1531
|
+
let occurred = false;
|
|
1532
|
+
const onError = () => {
|
|
1533
|
+
occurred = true;
|
|
1534
|
+
};
|
|
1535
|
+
const msg = !isMessageFunction(format) ? compileMessageFormat(context, key, targetLocale, format, cacheBaseKey, onError) : format;
|
|
1536
|
+
if (occurred) return format;
|
|
1537
|
+
const msgContext = createMessageContext(getMessageContextOptions(context, targetLocale, message, options));
|
|
1538
|
+
const timeline = startTimelineMeasure(context, "evaluation");
|
|
1539
|
+
const messaged = msg(msgContext);
|
|
1540
|
+
if (timeline) timeline.emitter.emit("message-evaluation", {
|
|
1541
|
+
type: "message-evaluation",
|
|
1542
|
+
value: messaged,
|
|
1543
|
+
time: endTimelineMeasure(timeline),
|
|
1544
|
+
groupId: toDevtoolsGroupId("translate", msg.key)
|
|
1545
|
+
});
|
|
1546
|
+
let ret = context.postTranslation ? context.postTranslation(messaged, key) : messaged;
|
|
1547
|
+
if (escapeParameter && isString(ret)) ret = sanitizeTranslatedHtml(ret);
|
|
1548
|
+
return ret;
|
|
1549
|
+
}
|
|
1550
|
+
function escapeParams(options) {
|
|
1551
|
+
if (isArray(options.list)) options.list = options.list.map((item) => isString(item) ? escapeHtml(item) : item);
|
|
1552
|
+
if (isObject(options.named)) {
|
|
1553
|
+
const source = options.named;
|
|
1554
|
+
const named = create();
|
|
1555
|
+
for (const key of Object.keys(source)) {
|
|
1556
|
+
const value = source[key];
|
|
1557
|
+
named[key] = isString(value) ? escapeHtml(value) : value;
|
|
1558
|
+
}
|
|
1559
|
+
options.named = named;
|
|
1560
|
+
}
|
|
1561
|
+
}
|
|
1562
|
+
function resolveMessageFormat(context, key, locale, fallbackLocale, fallbackWarn, missingWarn) {
|
|
1563
|
+
const { messages, onWarn, messageResolver: resolveValue, localeFallbacker } = context;
|
|
1564
|
+
const locales = localeFallbacker(context, fallbackLocale, locale);
|
|
1565
|
+
let message = create();
|
|
1566
|
+
let targetLocale;
|
|
1567
|
+
let format = null;
|
|
1568
|
+
let from = locale;
|
|
1569
|
+
const type = "translate";
|
|
1570
|
+
for (let i = 0; i < locales.length; i++) {
|
|
1571
|
+
targetLocale = locales[i];
|
|
1572
|
+
if (locale !== targetLocale && !isAlmostSameLocale(locale, targetLocale) && isTranslateFallbackWarn(fallbackWarn, key)) onWarn(getWarnMessage(CoreWarnCodes.FALLBACK_TO_TRANSLATE, {
|
|
1573
|
+
key,
|
|
1574
|
+
target: targetLocale
|
|
1575
|
+
}));
|
|
1576
|
+
if (locale !== targetLocale) {
|
|
1577
|
+
const emitter = context.__v_emitter;
|
|
1578
|
+
if (emitter) emitter.emit("fallback", {
|
|
1579
|
+
type,
|
|
1580
|
+
key,
|
|
1581
|
+
from,
|
|
1582
|
+
to: targetLocale,
|
|
1583
|
+
groupId: toDevtoolsGroupId(type, key)
|
|
1584
|
+
});
|
|
1585
|
+
}
|
|
1586
|
+
message = getOwn(messages, targetLocale) || create();
|
|
1587
|
+
const timeline = startTimelineMeasure(context, "resolve");
|
|
1588
|
+
if ((format = resolveValue(message, key)) === null) format = getOwn(message, key);
|
|
1589
|
+
if (timeline) {
|
|
1590
|
+
const time = endTimelineMeasure(timeline);
|
|
1591
|
+
if (format) timeline.emitter.emit("message-resolve", {
|
|
1592
|
+
type: "message-resolve",
|
|
1593
|
+
key,
|
|
1594
|
+
message: format,
|
|
1595
|
+
time,
|
|
1596
|
+
groupId: toDevtoolsGroupId(type, key)
|
|
1597
|
+
});
|
|
1598
|
+
}
|
|
1599
|
+
if (isMessageFormat(format)) break;
|
|
1600
|
+
if (!isImplicitFallback(targetLocale, locales)) {
|
|
1601
|
+
const missingRet = handleMissing(context, key, targetLocale, missingWarn, type);
|
|
1602
|
+
if (missingRet !== key) format = missingRet;
|
|
1603
|
+
}
|
|
1604
|
+
from = targetLocale;
|
|
1605
|
+
}
|
|
1606
|
+
return [
|
|
1607
|
+
format,
|
|
1608
|
+
targetLocale,
|
|
1609
|
+
message
|
|
1610
|
+
];
|
|
1611
|
+
}
|
|
1612
|
+
function stringifyKey(key) {
|
|
1613
|
+
return isString(key) ? key : isObject(key) ? JSON.stringify(key) : isFunction(key) ? key.name || "function" : "";
|
|
1614
|
+
}
|
|
1615
|
+
function compileMessageFormat(context, key, targetLocale, format, cacheBaseKey, onError) {
|
|
1616
|
+
if (isMessageFunction(format)) {
|
|
1617
|
+
const msg = format;
|
|
1618
|
+
msg.locale = msg.locale || targetLocale;
|
|
1619
|
+
msg.key = msg.key || key;
|
|
1620
|
+
return msg;
|
|
1621
|
+
}
|
|
1622
|
+
if (context.messageCompiler == null) {
|
|
1623
|
+
const msg = (() => format);
|
|
1624
|
+
msg.locale = targetLocale;
|
|
1625
|
+
msg.key = key;
|
|
1626
|
+
return msg;
|
|
1627
|
+
}
|
|
1628
|
+
const timeline = startTimelineMeasure(context, "compilation");
|
|
1629
|
+
const msg = context.messageCompiler(format, getCompileContext(context, targetLocale, cacheBaseKey, format, context.warnHtmlMessage, onError));
|
|
1630
|
+
if (timeline) timeline.emitter.emit("message-compilation", {
|
|
1631
|
+
type: "message-compilation",
|
|
1632
|
+
message: format,
|
|
1633
|
+
time: endTimelineMeasure(timeline),
|
|
1634
|
+
groupId: toDevtoolsGroupId("translate", key)
|
|
1635
|
+
});
|
|
1636
|
+
msg.locale = targetLocale;
|
|
1637
|
+
msg.key = key;
|
|
1638
|
+
msg.source = format;
|
|
1639
|
+
return msg;
|
|
1640
|
+
}
|
|
1641
|
+
function startTimelineMeasure(context, name) {
|
|
1642
|
+
const emitter = context.__v_emitter;
|
|
1643
|
+
if (!inBrowser || !emitter) return null;
|
|
1644
|
+
const start = window.performance.now();
|
|
1645
|
+
mark?.(`intlify-message-${name}-start`);
|
|
1646
|
+
return {
|
|
1647
|
+
emitter,
|
|
1648
|
+
name,
|
|
1649
|
+
start
|
|
1650
|
+
};
|
|
1651
|
+
}
|
|
1652
|
+
function endTimelineMeasure({ name, start }) {
|
|
1653
|
+
const time = window.performance.now() - start;
|
|
1654
|
+
if (mark && measure) {
|
|
1655
|
+
const startTag = `intlify-message-${name}-start`;
|
|
1656
|
+
const endTag = `intlify-message-${name}-end`;
|
|
1657
|
+
mark(endTag);
|
|
1658
|
+
measure(`intlify message ${name}`, startTag, endTag);
|
|
1659
|
+
}
|
|
1660
|
+
return time;
|
|
1661
|
+
}
|
|
1662
|
+
/** @internal */
|
|
1663
|
+
function parseTranslateArgs(...args) {
|
|
1664
|
+
const [arg1, arg2, arg3] = args;
|
|
1665
|
+
if (!isString(arg1) && !isNumber(arg1) && !isMessageFunction(arg1) && !isMessageAST(arg1)) throw createCoreError(CoreErrorCodes.INVALID_ARGUMENT);
|
|
1666
|
+
const key = isNumber(arg1) ? String(arg1) : isMessageFunction(arg1) ? arg1 : arg1;
|
|
1667
|
+
const options = create();
|
|
1668
|
+
if (isNumber(arg2)) options.plural = arg2;
|
|
1669
|
+
else if (isString(arg2)) options.default = arg2;
|
|
1670
|
+
else if (isPlainObject(arg2) && !isKeylessObject(arg2)) options.named = arg2;
|
|
1671
|
+
else if (isArray(arg2)) options.list = arg2;
|
|
1672
|
+
if (isNumber(arg3)) options.plural = arg3;
|
|
1673
|
+
else if (isString(arg3)) options.default = arg3;
|
|
1674
|
+
else if (isPlainObject(arg3)) assign(options, arg3);
|
|
1675
|
+
return [key, options];
|
|
1676
|
+
}
|
|
1677
|
+
function getCompileContext(context, locale, key, source, warnHtmlMessage, onError) {
|
|
1678
|
+
return {
|
|
1679
|
+
locale,
|
|
1680
|
+
key,
|
|
1681
|
+
warnHtmlMessage,
|
|
1682
|
+
onError: (err) => {
|
|
1683
|
+
onError?.(err);
|
|
1684
|
+
{
|
|
1685
|
+
const _source = getSourceForCodeFrame(source);
|
|
1686
|
+
const codeFrame = err.location && _source && generateCodeFrame(_source, err.location.start.offset, err.location.end.offset);
|
|
1687
|
+
const emitter = context.__v_emitter;
|
|
1688
|
+
if (emitter && _source) emitter.emit("compile-error", {
|
|
1689
|
+
message: _source,
|
|
1690
|
+
error: err.message,
|
|
1691
|
+
start: err.location && err.location.start.offset,
|
|
1692
|
+
end: err.location && err.location.end.offset,
|
|
1693
|
+
groupId: toDevtoolsGroupId("translate", key)
|
|
1694
|
+
});
|
|
1695
|
+
const message = `Message compilation error: ${err.message}`;
|
|
1696
|
+
throw new SyntaxError(codeFrame ? `${message}\n${codeFrame}` : message);
|
|
1697
|
+
}
|
|
1698
|
+
},
|
|
1699
|
+
onCacheKey: (source) => generateFormatCacheKey(locale, key, source)
|
|
1700
|
+
};
|
|
1701
|
+
}
|
|
1702
|
+
function getSourceForCodeFrame(source) {
|
|
1703
|
+
if (isString(source)) return source;
|
|
1704
|
+
else if (source.loc?.source) return source.loc.source;
|
|
1705
|
+
}
|
|
1706
|
+
function getMessageContextOptions(context, locale, message, options) {
|
|
1707
|
+
const { modifiers, pluralRules, messageResolver: resolveValue, fallbackLocale, fallbackWarn, missingWarn, fallbackContext } = context;
|
|
1708
|
+
const resolveMessage = (key, useLinked) => {
|
|
1709
|
+
let val = resolveValue(message, key);
|
|
1710
|
+
if (val == null && (fallbackContext || useLinked)) {
|
|
1711
|
+
const [format, , message] = resolveMessageFormat(fallbackContext || context, key, locale, fallbackLocale, fallbackWarn, missingWarn);
|
|
1712
|
+
val = format ?? resolveValue(message, key);
|
|
1713
|
+
}
|
|
1714
|
+
if (isString(val) || isMessageAST(val)) {
|
|
1715
|
+
let occurred = false;
|
|
1716
|
+
const onError = () => {
|
|
1717
|
+
occurred = true;
|
|
1718
|
+
};
|
|
1719
|
+
const msg = compileMessageFormat(context, key, locale, val, key, onError);
|
|
1720
|
+
return !occurred ? msg : NOOP_MESSAGE_FUNCTION;
|
|
1721
|
+
} else if (isMessageFunction(val)) return val;
|
|
1722
|
+
else return NOOP_MESSAGE_FUNCTION;
|
|
1723
|
+
};
|
|
1724
|
+
return {
|
|
1725
|
+
locale,
|
|
1726
|
+
modifiers,
|
|
1727
|
+
pluralRules,
|
|
1728
|
+
messages: resolveMessage,
|
|
1729
|
+
processor: context.processor ?? void 0,
|
|
1730
|
+
list: options.list ?? void 0,
|
|
1731
|
+
named: options.named ?? void 0,
|
|
1732
|
+
pluralIndex: isNumber(options.plural) ? options.plural : void 0
|
|
1733
|
+
};
|
|
1734
|
+
}
|
|
1735
|
+
exports.AST_NODE_PROPS_KEYS = AST_NODE_PROPS_KEYS;
|
|
1736
|
+
exports.CORE_ERROR_CODES_EXTEND_POINT = CORE_ERROR_CODES_EXTEND_POINT;
|
|
1737
|
+
exports.CORE_WARN_CODES_EXTEND_POINT = CORE_WARN_CODES_EXTEND_POINT;
|
|
1738
|
+
exports.CoreWarnCodes = CoreWarnCodes;
|
|
1739
|
+
exports.DATETIME_FORMAT_OPTIONS_KEYS = DATETIME_FORMAT_OPTIONS_KEYS;
|
|
1740
|
+
exports.DEFAULT_LOCALE = DEFAULT_LOCALE;
|
|
1741
|
+
exports.DEFAULT_MESSAGE_DATA_TYPE = DEFAULT_MESSAGE_DATA_TYPE;
|
|
1742
|
+
exports.MISSING_RESOLVE_VALUE = MISSING_RESOLVE_VALUE;
|
|
1743
|
+
exports.NOT_RESOLVED = NOT_RESOLVED;
|
|
1744
|
+
exports.NUMBER_FORMAT_OPTIONS_KEYS = NUMBER_FORMAT_OPTIONS_KEYS;
|
|
1745
|
+
exports.VERSION = VERSION;
|
|
1746
|
+
exports.clearCompileCache = clearCompileCache;
|
|
1747
|
+
exports.clearDateTimeFormat = clearDateTimeFormat;
|
|
1748
|
+
exports.clearNumberFormat = clearNumberFormat;
|
|
1749
|
+
exports.compile = compile;
|
|
1750
|
+
exports.createCompileError = createCompileError;
|
|
1751
|
+
exports.createCoreContext = createCoreContext;
|
|
1752
|
+
exports.createCoreError = createCoreError;
|
|
1753
|
+
exports.createMessageContext = createMessageContext;
|
|
1754
|
+
exports.datetime = datetime;
|
|
1755
|
+
exports.fallbackWithLocaleChain = fallbackWithLocaleChain;
|
|
1756
|
+
exports.fallbackWithSimple = fallbackWithSimple;
|
|
1757
|
+
exports.getLocale = getLocale;
|
|
1758
|
+
exports.getLocaleMessage = getLocaleMessage;
|
|
1759
|
+
exports.getWarnMessage = getWarnMessage;
|
|
1760
|
+
exports.handleMissing = handleMissing;
|
|
1761
|
+
exports.isAlmostSameLocale = isAlmostSameLocale;
|
|
1762
|
+
exports.isFallbackLocale = isFallbackLocale;
|
|
1763
|
+
exports.isImplicitFallback = isImplicitFallback;
|
|
1764
|
+
exports.isMessageAST = isMessageAST;
|
|
1765
|
+
exports.isMessageFormat = isMessageFormat;
|
|
1766
|
+
exports.isMessageFunction = isMessageFunction;
|
|
1767
|
+
exports.isTranslateFallbackWarn = isTranslateFallbackWarn;
|
|
1768
|
+
exports.isTranslateMissingWarn = isTranslateMissingWarn;
|
|
1769
|
+
exports.isWarnOption = isWarnOption;
|
|
1770
|
+
exports.number = number;
|
|
1771
|
+
exports.parse = parse;
|
|
1772
|
+
exports.parseDateTimeArgs = parseDateTimeArgs;
|
|
1773
|
+
exports.parseNumberArgs = parseNumberArgs;
|
|
1774
|
+
exports.parseTranslateArgs = parseTranslateArgs;
|
|
1775
|
+
exports.registerLocaleFallbacker = registerLocaleFallbacker;
|
|
1776
|
+
exports.registerMessageCompiler = registerMessageCompiler;
|
|
1777
|
+
exports.registerMessageResolver = registerMessageResolver;
|
|
1778
|
+
exports.resolveLocale = resolveLocale;
|
|
1779
|
+
exports.resolveValue = resolveValue;
|
|
1780
|
+
exports.resolveWithKeyValue = resolveWithKeyValue;
|
|
1781
|
+
exports.setLocaleMessage = setLocaleMessage;
|
|
1782
|
+
exports.translate = translate;
|
|
1783
|
+
exports.updateFallbackLocale = updateFallbackLocale;
|
|
1784
|
+
return exports;
|
|
2097
1785
|
})({});
|