react-i18next 12.3.0 → 13.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/LICENSE +1 -1
- package/TransWithoutContext.d.ts +26 -16
- package/dist/amd/react-i18next.js +827 -1104
- package/dist/amd/react-i18next.min.js +1 -1
- package/dist/commonjs/I18nextProvider.js +10 -13
- package/dist/commonjs/Trans.js +37 -52
- package/dist/commonjs/TransWithoutContext.js +130 -168
- package/dist/commonjs/Translation.js +8 -22
- package/dist/commonjs/context.js +45 -76
- package/dist/commonjs/defaults.js +7 -16
- package/dist/commonjs/i18nInstance.js +2 -4
- package/dist/commonjs/index.js +52 -86
- package/dist/commonjs/initReactI18next.js +2 -5
- package/dist/commonjs/unescape.js +4 -11
- package/dist/commonjs/useSSR.js +10 -14
- package/dist/commonjs/useTranslation.js +57 -79
- package/dist/commonjs/utils.js +38 -47
- package/dist/commonjs/withSSR.js +9 -23
- package/dist/commonjs/withTranslation.js +18 -45
- package/dist/es/I18nextProvider.js +10 -10
- package/dist/es/Trans.js +36 -43
- package/dist/es/TransWithoutContext.js +129 -159
- package/dist/es/Translation.js +7 -14
- package/dist/es/context.js +30 -50
- package/dist/es/defaults.js +7 -10
- package/dist/es/i18nInstance.js +1 -1
- package/dist/es/index.js +6 -18
- package/dist/es/initReactI18next.js +2 -2
- package/dist/es/package.json +1 -1
- package/dist/es/unescape.js +4 -10
- package/dist/es/useSSR.js +10 -11
- package/dist/es/useTranslation.js +58 -73
- package/dist/es/utils.js +34 -39
- package/dist/es/withSSR.js +9 -15
- package/dist/es/withTranslation.js +17 -35
- package/dist/umd/react-i18next.js +828 -1105
- package/dist/umd/react-i18next.min.js +1 -1
- package/helpers.d.ts +3 -0
- package/icu.macro.d.ts +37 -39
- package/index.d.ts +44 -37
- package/initReactI18next.d.ts +1 -1
- package/package.json +36 -36
- package/react-i18next.js +828 -1105
- package/react-i18next.min.js +1 -1
- package/src/useTranslation.js +17 -8
- package/src/utils.js +27 -15
|
@@ -1,1104 +1,827 @@
|
|
|
1
|
-
define(['exports', 'react'], function (exports, react) { 'use strict';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
}, [value, ignore]);
|
|
829
|
-
return ref.current;
|
|
830
|
-
};
|
|
831
|
-
|
|
832
|
-
function useTranslation(ns) {
|
|
833
|
-
var props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
834
|
-
var i18nFromProps = props.i18n;
|
|
835
|
-
|
|
836
|
-
var _ref = react.useContext(I18nContext) || {},
|
|
837
|
-
i18nFromContext = _ref.i18n,
|
|
838
|
-
defaultNSFromContext = _ref.defaultNS;
|
|
839
|
-
|
|
840
|
-
var i18n = i18nFromProps || i18nFromContext || getI18n();
|
|
841
|
-
if (i18n && !i18n.reportNamespaces) i18n.reportNamespaces = new ReportNamespaces();
|
|
842
|
-
|
|
843
|
-
if (!i18n) {
|
|
844
|
-
warnOnce('You will need to pass in an i18next instance by using initReactI18next');
|
|
845
|
-
|
|
846
|
-
var notReadyT = function notReadyT(k, optsOrDefaultValue) {
|
|
847
|
-
if (typeof optsOrDefaultValue === 'string') return optsOrDefaultValue;
|
|
848
|
-
if (optsOrDefaultValue && _typeof(optsOrDefaultValue) === 'object' && typeof optsOrDefaultValue.defaultValue === 'string') return optsOrDefaultValue.defaultValue;
|
|
849
|
-
return Array.isArray(k) ? k[k.length - 1] : k;
|
|
850
|
-
};
|
|
851
|
-
|
|
852
|
-
var retNotReady = [notReadyT, {}, false];
|
|
853
|
-
retNotReady.t = notReadyT;
|
|
854
|
-
retNotReady.i18n = {};
|
|
855
|
-
retNotReady.ready = false;
|
|
856
|
-
return retNotReady;
|
|
857
|
-
}
|
|
858
|
-
|
|
859
|
-
if (i18n.options.react && i18n.options.react.wait !== undefined) warnOnce('It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.');
|
|
860
|
-
|
|
861
|
-
var i18nOptions = _objectSpread2(_objectSpread2(_objectSpread2({}, getDefaults()), i18n.options.react), props);
|
|
862
|
-
|
|
863
|
-
var useSuspense = i18nOptions.useSuspense,
|
|
864
|
-
keyPrefix = i18nOptions.keyPrefix;
|
|
865
|
-
var namespaces = ns || defaultNSFromContext || i18n.options && i18n.options.defaultNS;
|
|
866
|
-
namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation'];
|
|
867
|
-
if (i18n.reportNamespaces.addUsedNamespaces) i18n.reportNamespaces.addUsedNamespaces(namespaces);
|
|
868
|
-
var ready = (i18n.isInitialized || i18n.initializedStoreOnce) && namespaces.every(function (n) {
|
|
869
|
-
return hasLoadedNamespace(n, i18n, i18nOptions);
|
|
870
|
-
});
|
|
871
|
-
|
|
872
|
-
function getT() {
|
|
873
|
-
return i18n.getFixedT(props.lng || null, i18nOptions.nsMode === 'fallback' ? namespaces : namespaces[0], keyPrefix);
|
|
874
|
-
}
|
|
875
|
-
|
|
876
|
-
var _useState = react.useState(getT),
|
|
877
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
878
|
-
t = _useState2[0],
|
|
879
|
-
setT = _useState2[1];
|
|
880
|
-
|
|
881
|
-
var joinedNS = namespaces.join();
|
|
882
|
-
var previousJoinedNS = usePrevious(joinedNS);
|
|
883
|
-
var isMounted = react.useRef(true);
|
|
884
|
-
react.useEffect(function () {
|
|
885
|
-
var bindI18n = i18nOptions.bindI18n,
|
|
886
|
-
bindI18nStore = i18nOptions.bindI18nStore;
|
|
887
|
-
isMounted.current = true;
|
|
888
|
-
|
|
889
|
-
if (!ready && !useSuspense) {
|
|
890
|
-
loadNamespaces(i18n, namespaces, function () {
|
|
891
|
-
if (isMounted.current) setT(getT);
|
|
892
|
-
});
|
|
893
|
-
}
|
|
894
|
-
|
|
895
|
-
if (ready && previousJoinedNS && previousJoinedNS !== joinedNS && isMounted.current) {
|
|
896
|
-
setT(getT);
|
|
897
|
-
}
|
|
898
|
-
|
|
899
|
-
function boundReset() {
|
|
900
|
-
if (isMounted.current) setT(getT);
|
|
901
|
-
}
|
|
902
|
-
|
|
903
|
-
if (bindI18n && i18n) i18n.on(bindI18n, boundReset);
|
|
904
|
-
if (bindI18nStore && i18n) i18n.store.on(bindI18nStore, boundReset);
|
|
905
|
-
return function () {
|
|
906
|
-
isMounted.current = false;
|
|
907
|
-
if (bindI18n && i18n) bindI18n.split(' ').forEach(function (e) {
|
|
908
|
-
return i18n.off(e, boundReset);
|
|
909
|
-
});
|
|
910
|
-
if (bindI18nStore && i18n) bindI18nStore.split(' ').forEach(function (e) {
|
|
911
|
-
return i18n.store.off(e, boundReset);
|
|
912
|
-
});
|
|
913
|
-
};
|
|
914
|
-
}, [i18n, joinedNS]);
|
|
915
|
-
var isInitial = react.useRef(true);
|
|
916
|
-
react.useEffect(function () {
|
|
917
|
-
if (isMounted.current && !isInitial.current) {
|
|
918
|
-
setT(getT);
|
|
919
|
-
}
|
|
920
|
-
|
|
921
|
-
isInitial.current = false;
|
|
922
|
-
}, [i18n, keyPrefix]);
|
|
923
|
-
var ret = [t, i18n, ready];
|
|
924
|
-
ret.t = t;
|
|
925
|
-
ret.i18n = i18n;
|
|
926
|
-
ret.ready = ready;
|
|
927
|
-
if (ready) return ret;
|
|
928
|
-
if (!ready && !useSuspense) return ret;
|
|
929
|
-
throw new Promise(function (resolve) {
|
|
930
|
-
loadNamespaces(i18n, namespaces, function () {
|
|
931
|
-
resolve();
|
|
932
|
-
});
|
|
933
|
-
});
|
|
934
|
-
}
|
|
935
|
-
|
|
936
|
-
var _excluded$2 = ["forwardedRef"];
|
|
937
|
-
function withTranslation(ns) {
|
|
938
|
-
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
939
|
-
return function Extend(WrappedComponent) {
|
|
940
|
-
function I18nextWithTranslation(_ref) {
|
|
941
|
-
var forwardedRef = _ref.forwardedRef,
|
|
942
|
-
rest = _objectWithoutProperties(_ref, _excluded$2);
|
|
943
|
-
|
|
944
|
-
var _useTranslation = useTranslation(ns, _objectSpread2(_objectSpread2({}, rest), {}, {
|
|
945
|
-
keyPrefix: options.keyPrefix
|
|
946
|
-
})),
|
|
947
|
-
_useTranslation2 = _slicedToArray(_useTranslation, 3),
|
|
948
|
-
t = _useTranslation2[0],
|
|
949
|
-
i18n = _useTranslation2[1],
|
|
950
|
-
ready = _useTranslation2[2];
|
|
951
|
-
|
|
952
|
-
var passDownProps = _objectSpread2(_objectSpread2({}, rest), {}, {
|
|
953
|
-
t: t,
|
|
954
|
-
i18n: i18n,
|
|
955
|
-
tReady: ready
|
|
956
|
-
});
|
|
957
|
-
|
|
958
|
-
if (options.withRef && forwardedRef) {
|
|
959
|
-
passDownProps.ref = forwardedRef;
|
|
960
|
-
} else if (!options.withRef && forwardedRef) {
|
|
961
|
-
passDownProps.forwardedRef = forwardedRef;
|
|
962
|
-
}
|
|
963
|
-
|
|
964
|
-
return react.createElement(WrappedComponent, passDownProps);
|
|
965
|
-
}
|
|
966
|
-
|
|
967
|
-
I18nextWithTranslation.displayName = "withI18nextTranslation(".concat(getDisplayName(WrappedComponent), ")");
|
|
968
|
-
I18nextWithTranslation.WrappedComponent = WrappedComponent;
|
|
969
|
-
|
|
970
|
-
var forwardRef = function forwardRef(props, ref) {
|
|
971
|
-
return react.createElement(I18nextWithTranslation, Object.assign({}, props, {
|
|
972
|
-
forwardedRef: ref
|
|
973
|
-
}));
|
|
974
|
-
};
|
|
975
|
-
|
|
976
|
-
return options.withRef ? react.forwardRef(forwardRef) : I18nextWithTranslation;
|
|
977
|
-
};
|
|
978
|
-
}
|
|
979
|
-
|
|
980
|
-
var _excluded$3 = ["ns", "children"];
|
|
981
|
-
function Translation(props) {
|
|
982
|
-
var ns = props.ns,
|
|
983
|
-
children = props.children,
|
|
984
|
-
options = _objectWithoutProperties(props, _excluded$3);
|
|
985
|
-
|
|
986
|
-
var _useTranslation = useTranslation(ns, options),
|
|
987
|
-
_useTranslation2 = _slicedToArray(_useTranslation, 3),
|
|
988
|
-
t = _useTranslation2[0],
|
|
989
|
-
i18n = _useTranslation2[1],
|
|
990
|
-
ready = _useTranslation2[2];
|
|
991
|
-
|
|
992
|
-
return children(t, {
|
|
993
|
-
i18n: i18n,
|
|
994
|
-
lng: i18n.language
|
|
995
|
-
}, ready);
|
|
996
|
-
}
|
|
997
|
-
|
|
998
|
-
function I18nextProvider(_ref) {
|
|
999
|
-
var i18n = _ref.i18n,
|
|
1000
|
-
defaultNS = _ref.defaultNS,
|
|
1001
|
-
children = _ref.children;
|
|
1002
|
-
var value = react.useMemo(function () {
|
|
1003
|
-
return {
|
|
1004
|
-
i18n: i18n,
|
|
1005
|
-
defaultNS: defaultNS
|
|
1006
|
-
};
|
|
1007
|
-
}, [i18n, defaultNS]);
|
|
1008
|
-
return react.createElement(I18nContext.Provider, {
|
|
1009
|
-
value: value
|
|
1010
|
-
}, children);
|
|
1011
|
-
}
|
|
1012
|
-
|
|
1013
|
-
function useSSR(initialI18nStore, initialLanguage) {
|
|
1014
|
-
var props = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
1015
|
-
var i18nFromProps = props.i18n;
|
|
1016
|
-
|
|
1017
|
-
var _ref = react.useContext(I18nContext) || {},
|
|
1018
|
-
i18nFromContext = _ref.i18n;
|
|
1019
|
-
|
|
1020
|
-
var i18n = i18nFromProps || i18nFromContext || getI18n();
|
|
1021
|
-
if (i18n.options && i18n.options.isClone) return;
|
|
1022
|
-
|
|
1023
|
-
if (initialI18nStore && !i18n.initializedStoreOnce) {
|
|
1024
|
-
i18n.services.resourceStore.data = initialI18nStore;
|
|
1025
|
-
i18n.options.ns = Object.values(initialI18nStore).reduce(function (mem, lngResources) {
|
|
1026
|
-
Object.keys(lngResources).forEach(function (ns) {
|
|
1027
|
-
if (mem.indexOf(ns) < 0) mem.push(ns);
|
|
1028
|
-
});
|
|
1029
|
-
return mem;
|
|
1030
|
-
}, i18n.options.ns);
|
|
1031
|
-
i18n.initializedStoreOnce = true;
|
|
1032
|
-
i18n.isInitialized = true;
|
|
1033
|
-
}
|
|
1034
|
-
|
|
1035
|
-
if (initialLanguage && !i18n.initializedLanguageOnce) {
|
|
1036
|
-
i18n.changeLanguage(initialLanguage);
|
|
1037
|
-
i18n.initializedLanguageOnce = true;
|
|
1038
|
-
}
|
|
1039
|
-
}
|
|
1040
|
-
|
|
1041
|
-
var _excluded$4 = ["initialI18nStore", "initialLanguage"];
|
|
1042
|
-
function withSSR() {
|
|
1043
|
-
return function Extend(WrappedComponent) {
|
|
1044
|
-
function I18nextWithSSR(_ref) {
|
|
1045
|
-
var initialI18nStore = _ref.initialI18nStore,
|
|
1046
|
-
initialLanguage = _ref.initialLanguage,
|
|
1047
|
-
rest = _objectWithoutProperties(_ref, _excluded$4);
|
|
1048
|
-
|
|
1049
|
-
useSSR(initialI18nStore, initialLanguage);
|
|
1050
|
-
return react.createElement(WrappedComponent, _objectSpread2({}, rest));
|
|
1051
|
-
}
|
|
1052
|
-
|
|
1053
|
-
I18nextWithSSR.getInitialProps = composeInitialProps(WrappedComponent);
|
|
1054
|
-
I18nextWithSSR.displayName = "withI18nextSSR(".concat(getDisplayName(WrappedComponent), ")");
|
|
1055
|
-
I18nextWithSSR.WrappedComponent = WrappedComponent;
|
|
1056
|
-
return I18nextWithSSR;
|
|
1057
|
-
};
|
|
1058
|
-
}
|
|
1059
|
-
|
|
1060
|
-
var date = function date() {
|
|
1061
|
-
return '';
|
|
1062
|
-
};
|
|
1063
|
-
var time = function time() {
|
|
1064
|
-
return '';
|
|
1065
|
-
};
|
|
1066
|
-
var number = function number() {
|
|
1067
|
-
return '';
|
|
1068
|
-
};
|
|
1069
|
-
var select = function select() {
|
|
1070
|
-
return '';
|
|
1071
|
-
};
|
|
1072
|
-
var plural = function plural() {
|
|
1073
|
-
return '';
|
|
1074
|
-
};
|
|
1075
|
-
var selectOrdinal = function selectOrdinal() {
|
|
1076
|
-
return '';
|
|
1077
|
-
};
|
|
1078
|
-
|
|
1079
|
-
exports.I18nContext = I18nContext;
|
|
1080
|
-
exports.I18nextProvider = I18nextProvider;
|
|
1081
|
-
exports.Trans = Trans$1;
|
|
1082
|
-
exports.TransWithoutContext = Trans;
|
|
1083
|
-
exports.Translation = Translation;
|
|
1084
|
-
exports.composeInitialProps = composeInitialProps;
|
|
1085
|
-
exports.date = date;
|
|
1086
|
-
exports.getDefaults = getDefaults;
|
|
1087
|
-
exports.getI18n = getI18n;
|
|
1088
|
-
exports.getInitialProps = getInitialProps;
|
|
1089
|
-
exports.initReactI18next = initReactI18next;
|
|
1090
|
-
exports.number = number;
|
|
1091
|
-
exports.plural = plural;
|
|
1092
|
-
exports.select = select;
|
|
1093
|
-
exports.selectOrdinal = selectOrdinal;
|
|
1094
|
-
exports.setDefaults = setDefaults;
|
|
1095
|
-
exports.setI18n = setI18n;
|
|
1096
|
-
exports.time = time;
|
|
1097
|
-
exports.useSSR = useSSR;
|
|
1098
|
-
exports.useTranslation = useTranslation;
|
|
1099
|
-
exports.withSSR = withSSR;
|
|
1100
|
-
exports.withTranslation = withTranslation;
|
|
1101
|
-
|
|
1102
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
1103
|
-
|
|
1104
|
-
});
|
|
1
|
+
define(['exports', 'react'], (function (exports, react) { 'use strict';
|
|
2
|
+
|
|
3
|
+
function getDefaultExportFromCjs (x) {
|
|
4
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
var voidElements = {
|
|
8
|
+
"area": true,
|
|
9
|
+
"base": true,
|
|
10
|
+
"br": true,
|
|
11
|
+
"col": true,
|
|
12
|
+
"embed": true,
|
|
13
|
+
"hr": true,
|
|
14
|
+
"img": true,
|
|
15
|
+
"input": true,
|
|
16
|
+
"link": true,
|
|
17
|
+
"meta": true,
|
|
18
|
+
"param": true,
|
|
19
|
+
"source": true,
|
|
20
|
+
"track": true,
|
|
21
|
+
"wbr": true
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
var e = /*@__PURE__*/getDefaultExportFromCjs(voidElements);
|
|
25
|
+
|
|
26
|
+
var t = /\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;
|
|
27
|
+
function n(n) {
|
|
28
|
+
var r = {
|
|
29
|
+
type: "tag",
|
|
30
|
+
name: "",
|
|
31
|
+
voidElement: !1,
|
|
32
|
+
attrs: {},
|
|
33
|
+
children: []
|
|
34
|
+
},
|
|
35
|
+
i = n.match(/<\/?([^\s]+?)[/\s>]/);
|
|
36
|
+
if (i && (r.name = i[1], (e[i[1]] || "/" === n.charAt(n.length - 2)) && (r.voidElement = !0), r.name.startsWith("!--"))) {
|
|
37
|
+
var s = n.indexOf("--\x3e");
|
|
38
|
+
return {
|
|
39
|
+
type: "comment",
|
|
40
|
+
comment: -1 !== s ? n.slice(4, s) : ""
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
for (var a = new RegExp(t), c = null; null !== (c = a.exec(n));) if (c[0].trim()) if (c[1]) {
|
|
44
|
+
var o = c[1].trim(),
|
|
45
|
+
l = [o, ""];
|
|
46
|
+
o.indexOf("=") > -1 && (l = o.split("=")), r.attrs[l[0]] = l[1], a.lastIndex--;
|
|
47
|
+
} else c[2] && (r.attrs[c[2]] = c[3].trim().substring(1, c[3].length - 1));
|
|
48
|
+
return r;
|
|
49
|
+
}
|
|
50
|
+
var r = /<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,
|
|
51
|
+
i = /^\s*$/,
|
|
52
|
+
s = Object.create(null);
|
|
53
|
+
function a(e, t) {
|
|
54
|
+
switch (t.type) {
|
|
55
|
+
case "text":
|
|
56
|
+
return e + t.content;
|
|
57
|
+
case "tag":
|
|
58
|
+
return e += "<" + t.name + (t.attrs ? function (e) {
|
|
59
|
+
var t = [];
|
|
60
|
+
for (var n in e) t.push(n + '="' + e[n] + '"');
|
|
61
|
+
return t.length ? " " + t.join(" ") : "";
|
|
62
|
+
}(t.attrs) : "") + (t.voidElement ? "/>" : ">"), t.voidElement ? e : e + t.children.reduce(a, "") + "</" + t.name + ">";
|
|
63
|
+
case "comment":
|
|
64
|
+
return e + "\x3c!--" + t.comment + "--\x3e";
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
var c = {
|
|
68
|
+
parse: function (e, t) {
|
|
69
|
+
t || (t = {}), t.components || (t.components = s);
|
|
70
|
+
var a,
|
|
71
|
+
c = [],
|
|
72
|
+
o = [],
|
|
73
|
+
l = -1,
|
|
74
|
+
m = !1;
|
|
75
|
+
if (0 !== e.indexOf("<")) {
|
|
76
|
+
var u = e.indexOf("<");
|
|
77
|
+
c.push({
|
|
78
|
+
type: "text",
|
|
79
|
+
content: -1 === u ? e : e.substring(0, u)
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
return e.replace(r, function (r, s) {
|
|
83
|
+
if (m) {
|
|
84
|
+
if (r !== "</" + a.name + ">") return;
|
|
85
|
+
m = !1;
|
|
86
|
+
}
|
|
87
|
+
var u,
|
|
88
|
+
f = "/" !== r.charAt(1),
|
|
89
|
+
h = r.startsWith("\x3c!--"),
|
|
90
|
+
p = s + r.length,
|
|
91
|
+
d = e.charAt(p);
|
|
92
|
+
if (h) {
|
|
93
|
+
var v = n(r);
|
|
94
|
+
return l < 0 ? (c.push(v), c) : ((u = o[l]).children.push(v), c);
|
|
95
|
+
}
|
|
96
|
+
if (f && (l++, "tag" === (a = n(r)).type && t.components[a.name] && (a.type = "component", m = !0), a.voidElement || m || !d || "<" === d || a.children.push({
|
|
97
|
+
type: "text",
|
|
98
|
+
content: e.slice(p, e.indexOf("<", p))
|
|
99
|
+
}), 0 === l && c.push(a), (u = o[l - 1]) && u.children.push(a), o[l] = a), (!f || a.voidElement) && (l > -1 && (a.voidElement || a.name === r.slice(2, -1)) && (l--, a = -1 === l ? c : o[l]), !m && "<" !== d && d)) {
|
|
100
|
+
u = -1 === l ? c : o[l].children;
|
|
101
|
+
var x = e.indexOf("<", p),
|
|
102
|
+
g = e.slice(p, -1 === x ? void 0 : x);
|
|
103
|
+
i.test(g) && (g = " "), (x > -1 && l + u.length >= 0 || " " !== g) && u.push({
|
|
104
|
+
type: "text",
|
|
105
|
+
content: g
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}), c;
|
|
109
|
+
},
|
|
110
|
+
stringify: function (e) {
|
|
111
|
+
return e.reduce(function (e, t) {
|
|
112
|
+
return e + a("", t);
|
|
113
|
+
}, "");
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
function warn() {
|
|
118
|
+
if (console && console.warn) {
|
|
119
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
120
|
+
args[_key] = arguments[_key];
|
|
121
|
+
}
|
|
122
|
+
if (typeof args[0] === 'string') args[0] = `react-i18next:: ${args[0]}`;
|
|
123
|
+
console.warn(...args);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
const alreadyWarned = {};
|
|
127
|
+
function warnOnce() {
|
|
128
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
129
|
+
args[_key2] = arguments[_key2];
|
|
130
|
+
}
|
|
131
|
+
if (typeof args[0] === 'string' && alreadyWarned[args[0]]) return;
|
|
132
|
+
if (typeof args[0] === 'string') alreadyWarned[args[0]] = new Date();
|
|
133
|
+
warn(...args);
|
|
134
|
+
}
|
|
135
|
+
const loadedClb = (i18n, cb) => () => {
|
|
136
|
+
if (i18n.isInitialized) {
|
|
137
|
+
cb();
|
|
138
|
+
} else {
|
|
139
|
+
const initialized = () => {
|
|
140
|
+
setTimeout(() => {
|
|
141
|
+
i18n.off('initialized', initialized);
|
|
142
|
+
}, 0);
|
|
143
|
+
cb();
|
|
144
|
+
};
|
|
145
|
+
i18n.on('initialized', initialized);
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
function loadNamespaces(i18n, ns, cb) {
|
|
149
|
+
i18n.loadNamespaces(ns, loadedClb(i18n, cb));
|
|
150
|
+
}
|
|
151
|
+
function loadLanguages(i18n, lng, ns, cb) {
|
|
152
|
+
if (typeof ns === 'string') ns = [ns];
|
|
153
|
+
ns.forEach(n => {
|
|
154
|
+
if (i18n.options.ns.indexOf(n) < 0) i18n.options.ns.push(n);
|
|
155
|
+
});
|
|
156
|
+
i18n.loadLanguages(lng, loadedClb(i18n, cb));
|
|
157
|
+
}
|
|
158
|
+
function oldI18nextHasLoadedNamespace(ns, i18n) {
|
|
159
|
+
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
160
|
+
const lng = i18n.languages[0];
|
|
161
|
+
const fallbackLng = i18n.options ? i18n.options.fallbackLng : false;
|
|
162
|
+
const lastLng = i18n.languages[i18n.languages.length - 1];
|
|
163
|
+
if (lng.toLowerCase() === 'cimode') return true;
|
|
164
|
+
const loadNotPending = (l, n) => {
|
|
165
|
+
const loadState = i18n.services.backendConnector.state[`${l}|${n}`];
|
|
166
|
+
return loadState === -1 || loadState === 2;
|
|
167
|
+
};
|
|
168
|
+
if (options.bindI18n && options.bindI18n.indexOf('languageChanging') > -1 && i18n.services.backendConnector.backend && i18n.isLanguageChangingTo && !loadNotPending(i18n.isLanguageChangingTo, ns)) return false;
|
|
169
|
+
if (i18n.hasResourceBundle(lng, ns)) return true;
|
|
170
|
+
if (!i18n.services.backendConnector.backend || i18n.options.resources && !i18n.options.partialBundledLanguages) return true;
|
|
171
|
+
if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true;
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
function hasLoadedNamespace(ns, i18n) {
|
|
175
|
+
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
176
|
+
if (!i18n.languages || !i18n.languages.length) {
|
|
177
|
+
warnOnce('i18n.languages were undefined or empty', i18n.languages);
|
|
178
|
+
return true;
|
|
179
|
+
}
|
|
180
|
+
const isNewerI18next = i18n.options.ignoreJSONStructure !== undefined;
|
|
181
|
+
if (!isNewerI18next) {
|
|
182
|
+
return oldI18nextHasLoadedNamespace(ns, i18n, options);
|
|
183
|
+
}
|
|
184
|
+
return i18n.hasLoadedNamespace(ns, {
|
|
185
|
+
lng: options.lng,
|
|
186
|
+
precheck: (i18nInstance, loadNotPending) => {
|
|
187
|
+
if (options.bindI18n && options.bindI18n.indexOf('languageChanging') > -1 && i18nInstance.services.backendConnector.backend && i18nInstance.isLanguageChangingTo && !loadNotPending(i18nInstance.isLanguageChangingTo, ns)) return false;
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
function getDisplayName(Component) {
|
|
192
|
+
return Component.displayName || Component.name || (typeof Component === 'string' && Component.length > 0 ? Component : 'Unknown');
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const matchHtmlEntity = /&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g;
|
|
196
|
+
const htmlEntities = {
|
|
197
|
+
'&': '&',
|
|
198
|
+
'&': '&',
|
|
199
|
+
'<': '<',
|
|
200
|
+
'<': '<',
|
|
201
|
+
'>': '>',
|
|
202
|
+
'>': '>',
|
|
203
|
+
''': "'",
|
|
204
|
+
''': "'",
|
|
205
|
+
'"': '"',
|
|
206
|
+
'"': '"',
|
|
207
|
+
' ': ' ',
|
|
208
|
+
' ': ' ',
|
|
209
|
+
'©': '©',
|
|
210
|
+
'©': '©',
|
|
211
|
+
'®': '®',
|
|
212
|
+
'®': '®',
|
|
213
|
+
'…': '…',
|
|
214
|
+
'…': '…',
|
|
215
|
+
'/': '/',
|
|
216
|
+
'/': '/'
|
|
217
|
+
};
|
|
218
|
+
const unescapeHtmlEntity = m => htmlEntities[m];
|
|
219
|
+
const unescape = text => text.replace(matchHtmlEntity, unescapeHtmlEntity);
|
|
220
|
+
|
|
221
|
+
let defaultOptions = {
|
|
222
|
+
bindI18n: 'languageChanged',
|
|
223
|
+
bindI18nStore: '',
|
|
224
|
+
transEmptyNodeValue: '',
|
|
225
|
+
transSupportBasicHtmlNodes: true,
|
|
226
|
+
transWrapTextNodes: '',
|
|
227
|
+
transKeepBasicHtmlNodesFor: ['br', 'strong', 'i', 'p'],
|
|
228
|
+
useSuspense: true,
|
|
229
|
+
unescape
|
|
230
|
+
};
|
|
231
|
+
function setDefaults() {
|
|
232
|
+
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
233
|
+
defaultOptions = {
|
|
234
|
+
...defaultOptions,
|
|
235
|
+
...options
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
function getDefaults() {
|
|
239
|
+
return defaultOptions;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
let i18nInstance;
|
|
243
|
+
function setI18n(instance) {
|
|
244
|
+
i18nInstance = instance;
|
|
245
|
+
}
|
|
246
|
+
function getI18n() {
|
|
247
|
+
return i18nInstance;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function hasChildren(node, checkLength) {
|
|
251
|
+
if (!node) return false;
|
|
252
|
+
const base = node.props ? node.props.children : node.children;
|
|
253
|
+
if (checkLength) return base.length > 0;
|
|
254
|
+
return !!base;
|
|
255
|
+
}
|
|
256
|
+
function getChildren(node) {
|
|
257
|
+
if (!node) return [];
|
|
258
|
+
return node.props ? node.props.children : node.children;
|
|
259
|
+
}
|
|
260
|
+
function hasValidReactChildren(children) {
|
|
261
|
+
if (Object.prototype.toString.call(children) !== '[object Array]') return false;
|
|
262
|
+
return children.every(child => react.isValidElement(child));
|
|
263
|
+
}
|
|
264
|
+
function getAsArray(data) {
|
|
265
|
+
return Array.isArray(data) ? data : [data];
|
|
266
|
+
}
|
|
267
|
+
function mergeProps(source, target) {
|
|
268
|
+
const newTarget = {
|
|
269
|
+
...target
|
|
270
|
+
};
|
|
271
|
+
newTarget.props = Object.assign(source.props, target.props);
|
|
272
|
+
return newTarget;
|
|
273
|
+
}
|
|
274
|
+
function nodesToString(children, i18nOptions) {
|
|
275
|
+
if (!children) return '';
|
|
276
|
+
let stringNode = '';
|
|
277
|
+
const childrenArray = getAsArray(children);
|
|
278
|
+
const keepArray = i18nOptions.transSupportBasicHtmlNodes && i18nOptions.transKeepBasicHtmlNodesFor ? i18nOptions.transKeepBasicHtmlNodesFor : [];
|
|
279
|
+
childrenArray.forEach((child, childIndex) => {
|
|
280
|
+
if (typeof child === 'string') {
|
|
281
|
+
stringNode += `${child}`;
|
|
282
|
+
} else if (react.isValidElement(child)) {
|
|
283
|
+
const childPropsCount = Object.keys(child.props).length;
|
|
284
|
+
const shouldKeepChild = keepArray.indexOf(child.type) > -1;
|
|
285
|
+
const childChildren = child.props.children;
|
|
286
|
+
if (!childChildren && shouldKeepChild && childPropsCount === 0) {
|
|
287
|
+
stringNode += `<${child.type}/>`;
|
|
288
|
+
} else if (!childChildren && (!shouldKeepChild || childPropsCount !== 0)) {
|
|
289
|
+
stringNode += `<${childIndex}></${childIndex}>`;
|
|
290
|
+
} else if (child.props.i18nIsDynamicList) {
|
|
291
|
+
stringNode += `<${childIndex}></${childIndex}>`;
|
|
292
|
+
} else if (shouldKeepChild && childPropsCount === 1 && typeof childChildren === 'string') {
|
|
293
|
+
stringNode += `<${child.type}>${childChildren}</${child.type}>`;
|
|
294
|
+
} else {
|
|
295
|
+
const content = nodesToString(childChildren, i18nOptions);
|
|
296
|
+
stringNode += `<${childIndex}>${content}</${childIndex}>`;
|
|
297
|
+
}
|
|
298
|
+
} else if (child === null) {
|
|
299
|
+
warn(`Trans: the passed in value is invalid - seems you passed in a null child.`);
|
|
300
|
+
} else if (typeof child === 'object') {
|
|
301
|
+
const {
|
|
302
|
+
format,
|
|
303
|
+
...clone
|
|
304
|
+
} = child;
|
|
305
|
+
const keys = Object.keys(clone);
|
|
306
|
+
if (keys.length === 1) {
|
|
307
|
+
const value = format ? `${keys[0]}, ${format}` : keys[0];
|
|
308
|
+
stringNode += `{{${value}}}`;
|
|
309
|
+
} else {
|
|
310
|
+
warn(`react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.`, child);
|
|
311
|
+
}
|
|
312
|
+
} else {
|
|
313
|
+
warn(`Trans: the passed in value is invalid - seems you passed in a variable like {number} - please pass in variables for interpolation as full objects like {{number}}.`, child);
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
return stringNode;
|
|
317
|
+
}
|
|
318
|
+
function renderNodes(children, targetString, i18n, i18nOptions, combinedTOpts, shouldUnescape) {
|
|
319
|
+
if (targetString === '') return [];
|
|
320
|
+
const keepArray = i18nOptions.transKeepBasicHtmlNodesFor || [];
|
|
321
|
+
const emptyChildrenButNeedsHandling = targetString && new RegExp(keepArray.join('|')).test(targetString);
|
|
322
|
+
if (!children && !emptyChildrenButNeedsHandling) return [targetString];
|
|
323
|
+
const data = {};
|
|
324
|
+
function getData(childs) {
|
|
325
|
+
const childrenArray = getAsArray(childs);
|
|
326
|
+
childrenArray.forEach(child => {
|
|
327
|
+
if (typeof child === 'string') return;
|
|
328
|
+
if (hasChildren(child)) getData(getChildren(child));else if (typeof child === 'object' && !react.isValidElement(child)) Object.assign(data, child);
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
getData(children);
|
|
332
|
+
const ast = c.parse(`<0>${targetString}</0>`);
|
|
333
|
+
const opts = {
|
|
334
|
+
...data,
|
|
335
|
+
...combinedTOpts
|
|
336
|
+
};
|
|
337
|
+
function renderInner(child, node, rootReactNode) {
|
|
338
|
+
const childs = getChildren(child);
|
|
339
|
+
const mappedChildren = mapAST(childs, node.children, rootReactNode);
|
|
340
|
+
return hasValidReactChildren(childs) && mappedChildren.length === 0 ? childs : mappedChildren;
|
|
341
|
+
}
|
|
342
|
+
function pushTranslatedJSX(child, inner, mem, i, isVoid) {
|
|
343
|
+
if (child.dummy) child.children = inner;
|
|
344
|
+
mem.push(react.cloneElement(child, {
|
|
345
|
+
...child.props,
|
|
346
|
+
key: i
|
|
347
|
+
}, isVoid ? undefined : inner));
|
|
348
|
+
}
|
|
349
|
+
function mapAST(reactNode, astNode, rootReactNode) {
|
|
350
|
+
const reactNodes = getAsArray(reactNode);
|
|
351
|
+
const astNodes = getAsArray(astNode);
|
|
352
|
+
return astNodes.reduce((mem, node, i) => {
|
|
353
|
+
const translationContent = node.children && node.children[0] && node.children[0].content && i18n.services.interpolator.interpolate(node.children[0].content, opts, i18n.language);
|
|
354
|
+
if (node.type === 'tag') {
|
|
355
|
+
let tmp = reactNodes[parseInt(node.name, 10)];
|
|
356
|
+
if (!tmp && rootReactNode.length === 1 && rootReactNode[0][node.name]) tmp = rootReactNode[0][node.name];
|
|
357
|
+
if (!tmp) tmp = {};
|
|
358
|
+
const child = Object.keys(node.attrs).length !== 0 ? mergeProps({
|
|
359
|
+
props: node.attrs
|
|
360
|
+
}, tmp) : tmp;
|
|
361
|
+
const isElement = react.isValidElement(child);
|
|
362
|
+
const isValidTranslationWithChildren = isElement && hasChildren(node, true) && !node.voidElement;
|
|
363
|
+
const isEmptyTransWithHTML = emptyChildrenButNeedsHandling && typeof child === 'object' && child.dummy && !isElement;
|
|
364
|
+
const isKnownComponent = typeof children === 'object' && children !== null && Object.hasOwnProperty.call(children, node.name);
|
|
365
|
+
if (typeof child === 'string') {
|
|
366
|
+
const value = i18n.services.interpolator.interpolate(child, opts, i18n.language);
|
|
367
|
+
mem.push(value);
|
|
368
|
+
} else if (hasChildren(child) || isValidTranslationWithChildren) {
|
|
369
|
+
const inner = renderInner(child, node, rootReactNode);
|
|
370
|
+
pushTranslatedJSX(child, inner, mem, i);
|
|
371
|
+
} else if (isEmptyTransWithHTML) {
|
|
372
|
+
const inner = mapAST(reactNodes, node.children, rootReactNode);
|
|
373
|
+
mem.push(react.cloneElement(child, {
|
|
374
|
+
...child.props,
|
|
375
|
+
key: i
|
|
376
|
+
}, inner));
|
|
377
|
+
} else if (Number.isNaN(parseFloat(node.name))) {
|
|
378
|
+
if (isKnownComponent) {
|
|
379
|
+
const inner = renderInner(child, node, rootReactNode);
|
|
380
|
+
pushTranslatedJSX(child, inner, mem, i, node.voidElement);
|
|
381
|
+
} else if (i18nOptions.transSupportBasicHtmlNodes && keepArray.indexOf(node.name) > -1) {
|
|
382
|
+
if (node.voidElement) {
|
|
383
|
+
mem.push(react.createElement(node.name, {
|
|
384
|
+
key: `${node.name}-${i}`
|
|
385
|
+
}));
|
|
386
|
+
} else {
|
|
387
|
+
const inner = mapAST(reactNodes, node.children, rootReactNode);
|
|
388
|
+
mem.push(react.createElement(node.name, {
|
|
389
|
+
key: `${node.name}-${i}`
|
|
390
|
+
}, inner));
|
|
391
|
+
}
|
|
392
|
+
} else if (node.voidElement) {
|
|
393
|
+
mem.push(`<${node.name} />`);
|
|
394
|
+
} else {
|
|
395
|
+
const inner = mapAST(reactNodes, node.children, rootReactNode);
|
|
396
|
+
mem.push(`<${node.name}>${inner}</${node.name}>`);
|
|
397
|
+
}
|
|
398
|
+
} else if (typeof child === 'object' && !isElement) {
|
|
399
|
+
const content = node.children[0] ? translationContent : null;
|
|
400
|
+
if (content) mem.push(content);
|
|
401
|
+
} else if (node.children.length === 1 && translationContent) {
|
|
402
|
+
mem.push(react.cloneElement(child, {
|
|
403
|
+
...child.props,
|
|
404
|
+
key: i
|
|
405
|
+
}, translationContent));
|
|
406
|
+
} else {
|
|
407
|
+
mem.push(react.cloneElement(child, {
|
|
408
|
+
...child.props,
|
|
409
|
+
key: i
|
|
410
|
+
}));
|
|
411
|
+
}
|
|
412
|
+
} else if (node.type === 'text') {
|
|
413
|
+
const wrapTextNodes = i18nOptions.transWrapTextNodes;
|
|
414
|
+
const content = shouldUnescape ? i18nOptions.unescape(i18n.services.interpolator.interpolate(node.content, opts, i18n.language)) : i18n.services.interpolator.interpolate(node.content, opts, i18n.language);
|
|
415
|
+
if (wrapTextNodes) {
|
|
416
|
+
mem.push(react.createElement(wrapTextNodes, {
|
|
417
|
+
key: `${node.name}-${i}`
|
|
418
|
+
}, content));
|
|
419
|
+
} else {
|
|
420
|
+
mem.push(content);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
return mem;
|
|
424
|
+
}, []);
|
|
425
|
+
}
|
|
426
|
+
const result = mapAST([{
|
|
427
|
+
dummy: true,
|
|
428
|
+
children: children || []
|
|
429
|
+
}], ast, getAsArray(children || []));
|
|
430
|
+
return getChildren(result[0]);
|
|
431
|
+
}
|
|
432
|
+
function Trans$1(_ref) {
|
|
433
|
+
let {
|
|
434
|
+
children,
|
|
435
|
+
count,
|
|
436
|
+
parent,
|
|
437
|
+
i18nKey,
|
|
438
|
+
context,
|
|
439
|
+
tOptions = {},
|
|
440
|
+
values,
|
|
441
|
+
defaults,
|
|
442
|
+
components,
|
|
443
|
+
ns,
|
|
444
|
+
i18n: i18nFromProps,
|
|
445
|
+
t: tFromProps,
|
|
446
|
+
shouldUnescape,
|
|
447
|
+
...additionalProps
|
|
448
|
+
} = _ref;
|
|
449
|
+
const i18n = i18nFromProps || getI18n();
|
|
450
|
+
if (!i18n) {
|
|
451
|
+
warnOnce('You will need to pass in an i18next instance by using i18nextReactModule');
|
|
452
|
+
return children;
|
|
453
|
+
}
|
|
454
|
+
const t = tFromProps || i18n.t.bind(i18n) || (k => k);
|
|
455
|
+
if (context) tOptions.context = context;
|
|
456
|
+
const reactI18nextOptions = {
|
|
457
|
+
...getDefaults(),
|
|
458
|
+
...(i18n.options && i18n.options.react)
|
|
459
|
+
};
|
|
460
|
+
let namespaces = ns || t.ns || i18n.options && i18n.options.defaultNS;
|
|
461
|
+
namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation'];
|
|
462
|
+
const defaultValue = defaults || nodesToString(children, reactI18nextOptions) || reactI18nextOptions.transEmptyNodeValue || i18nKey;
|
|
463
|
+
const {
|
|
464
|
+
hashTransKey
|
|
465
|
+
} = reactI18nextOptions;
|
|
466
|
+
const key = i18nKey || (hashTransKey ? hashTransKey(defaultValue) : defaultValue);
|
|
467
|
+
const interpolationOverride = values ? tOptions.interpolation : {
|
|
468
|
+
interpolation: {
|
|
469
|
+
...tOptions.interpolation,
|
|
470
|
+
prefix: '#$?',
|
|
471
|
+
suffix: '?$#'
|
|
472
|
+
}
|
|
473
|
+
};
|
|
474
|
+
const combinedTOpts = {
|
|
475
|
+
...tOptions,
|
|
476
|
+
count,
|
|
477
|
+
...values,
|
|
478
|
+
...interpolationOverride,
|
|
479
|
+
defaultValue,
|
|
480
|
+
ns: namespaces
|
|
481
|
+
};
|
|
482
|
+
const translation = key ? t(key, combinedTOpts) : defaultValue;
|
|
483
|
+
const content = renderNodes(components || children, translation, i18n, reactI18nextOptions, combinedTOpts, shouldUnescape);
|
|
484
|
+
const useAsParent = parent !== undefined ? parent : reactI18nextOptions.defaultTransParent;
|
|
485
|
+
return useAsParent ? react.createElement(useAsParent, additionalProps, content) : content;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
const initReactI18next = {
|
|
489
|
+
type: '3rdParty',
|
|
490
|
+
init(instance) {
|
|
491
|
+
setDefaults(instance.options.react);
|
|
492
|
+
setI18n(instance);
|
|
493
|
+
}
|
|
494
|
+
};
|
|
495
|
+
|
|
496
|
+
const I18nContext = react.createContext();
|
|
497
|
+
class ReportNamespaces {
|
|
498
|
+
constructor() {
|
|
499
|
+
this.usedNamespaces = {};
|
|
500
|
+
}
|
|
501
|
+
addUsedNamespaces(namespaces) {
|
|
502
|
+
namespaces.forEach(ns => {
|
|
503
|
+
if (!this.usedNamespaces[ns]) this.usedNamespaces[ns] = true;
|
|
504
|
+
});
|
|
505
|
+
}
|
|
506
|
+
getUsedNamespaces() {
|
|
507
|
+
return Object.keys(this.usedNamespaces);
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
function composeInitialProps(ForComponent) {
|
|
511
|
+
return ctx => new Promise(resolve => {
|
|
512
|
+
const i18nInitialProps = getInitialProps();
|
|
513
|
+
if (ForComponent.getInitialProps) {
|
|
514
|
+
ForComponent.getInitialProps(ctx).then(componentsInitialProps => {
|
|
515
|
+
resolve({
|
|
516
|
+
...componentsInitialProps,
|
|
517
|
+
...i18nInitialProps
|
|
518
|
+
});
|
|
519
|
+
});
|
|
520
|
+
} else {
|
|
521
|
+
resolve(i18nInitialProps);
|
|
522
|
+
}
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
function getInitialProps() {
|
|
526
|
+
const i18n = getI18n();
|
|
527
|
+
const namespaces = i18n.reportNamespaces ? i18n.reportNamespaces.getUsedNamespaces() : [];
|
|
528
|
+
const ret = {};
|
|
529
|
+
const initialI18nStore = {};
|
|
530
|
+
i18n.languages.forEach(l => {
|
|
531
|
+
initialI18nStore[l] = {};
|
|
532
|
+
namespaces.forEach(ns => {
|
|
533
|
+
initialI18nStore[l][ns] = i18n.getResourceBundle(l, ns) || {};
|
|
534
|
+
});
|
|
535
|
+
});
|
|
536
|
+
ret.initialI18nStore = initialI18nStore;
|
|
537
|
+
ret.initialLanguage = i18n.language;
|
|
538
|
+
return ret;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
function Trans(_ref) {
|
|
542
|
+
let {
|
|
543
|
+
children,
|
|
544
|
+
count,
|
|
545
|
+
parent,
|
|
546
|
+
i18nKey,
|
|
547
|
+
context,
|
|
548
|
+
tOptions = {},
|
|
549
|
+
values,
|
|
550
|
+
defaults,
|
|
551
|
+
components,
|
|
552
|
+
ns,
|
|
553
|
+
i18n: i18nFromProps,
|
|
554
|
+
t: tFromProps,
|
|
555
|
+
shouldUnescape,
|
|
556
|
+
...additionalProps
|
|
557
|
+
} = _ref;
|
|
558
|
+
const {
|
|
559
|
+
i18n: i18nFromContext,
|
|
560
|
+
defaultNS: defaultNSFromContext
|
|
561
|
+
} = react.useContext(I18nContext) || {};
|
|
562
|
+
const i18n = i18nFromProps || i18nFromContext || getI18n();
|
|
563
|
+
const t = tFromProps || i18n && i18n.t.bind(i18n);
|
|
564
|
+
return Trans$1({
|
|
565
|
+
children,
|
|
566
|
+
count,
|
|
567
|
+
parent,
|
|
568
|
+
i18nKey,
|
|
569
|
+
context,
|
|
570
|
+
tOptions,
|
|
571
|
+
values,
|
|
572
|
+
defaults,
|
|
573
|
+
components,
|
|
574
|
+
ns: ns || t && t.ns || defaultNSFromContext || i18n && i18n.options && i18n.options.defaultNS,
|
|
575
|
+
i18n,
|
|
576
|
+
t: tFromProps,
|
|
577
|
+
shouldUnescape,
|
|
578
|
+
...additionalProps
|
|
579
|
+
});
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
const usePrevious = (value, ignore) => {
|
|
583
|
+
const ref = react.useRef();
|
|
584
|
+
react.useEffect(() => {
|
|
585
|
+
ref.current = ignore ? ref.current : value;
|
|
586
|
+
}, [value, ignore]);
|
|
587
|
+
return ref.current;
|
|
588
|
+
};
|
|
589
|
+
function useTranslation(ns) {
|
|
590
|
+
let props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
591
|
+
const {
|
|
592
|
+
i18n: i18nFromProps
|
|
593
|
+
} = props;
|
|
594
|
+
const {
|
|
595
|
+
i18n: i18nFromContext,
|
|
596
|
+
defaultNS: defaultNSFromContext
|
|
597
|
+
} = react.useContext(I18nContext) || {};
|
|
598
|
+
const i18n = i18nFromProps || i18nFromContext || getI18n();
|
|
599
|
+
if (i18n && !i18n.reportNamespaces) i18n.reportNamespaces = new ReportNamespaces();
|
|
600
|
+
if (!i18n) {
|
|
601
|
+
warnOnce('You will need to pass in an i18next instance by using initReactI18next');
|
|
602
|
+
const notReadyT = (k, optsOrDefaultValue) => {
|
|
603
|
+
if (typeof optsOrDefaultValue === 'string') return optsOrDefaultValue;
|
|
604
|
+
if (optsOrDefaultValue && typeof optsOrDefaultValue === 'object' && typeof optsOrDefaultValue.defaultValue === 'string') return optsOrDefaultValue.defaultValue;
|
|
605
|
+
return Array.isArray(k) ? k[k.length - 1] : k;
|
|
606
|
+
};
|
|
607
|
+
const retNotReady = [notReadyT, {}, false];
|
|
608
|
+
retNotReady.t = notReadyT;
|
|
609
|
+
retNotReady.i18n = {};
|
|
610
|
+
retNotReady.ready = false;
|
|
611
|
+
return retNotReady;
|
|
612
|
+
}
|
|
613
|
+
if (i18n.options.react && i18n.options.react.wait !== undefined) warnOnce('It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.');
|
|
614
|
+
const i18nOptions = {
|
|
615
|
+
...getDefaults(),
|
|
616
|
+
...i18n.options.react,
|
|
617
|
+
...props
|
|
618
|
+
};
|
|
619
|
+
const {
|
|
620
|
+
useSuspense,
|
|
621
|
+
keyPrefix
|
|
622
|
+
} = i18nOptions;
|
|
623
|
+
let namespaces = ns || defaultNSFromContext || i18n.options && i18n.options.defaultNS;
|
|
624
|
+
namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation'];
|
|
625
|
+
if (i18n.reportNamespaces.addUsedNamespaces) i18n.reportNamespaces.addUsedNamespaces(namespaces);
|
|
626
|
+
const ready = (i18n.isInitialized || i18n.initializedStoreOnce) && namespaces.every(n => hasLoadedNamespace(n, i18n, i18nOptions));
|
|
627
|
+
function getT() {
|
|
628
|
+
return i18n.getFixedT(props.lng || null, i18nOptions.nsMode === 'fallback' ? namespaces : namespaces[0], keyPrefix);
|
|
629
|
+
}
|
|
630
|
+
const [t, setT] = react.useState(getT);
|
|
631
|
+
let joinedNS = namespaces.join();
|
|
632
|
+
if (props.lng) joinedNS = `${props.lng}${joinedNS}`;
|
|
633
|
+
const previousJoinedNS = usePrevious(joinedNS);
|
|
634
|
+
const isMounted = react.useRef(true);
|
|
635
|
+
react.useEffect(() => {
|
|
636
|
+
const {
|
|
637
|
+
bindI18n,
|
|
638
|
+
bindI18nStore
|
|
639
|
+
} = i18nOptions;
|
|
640
|
+
isMounted.current = true;
|
|
641
|
+
if (!ready && !useSuspense) {
|
|
642
|
+
if (props.lng) {
|
|
643
|
+
loadLanguages(i18n, props.lng, namespaces, () => {
|
|
644
|
+
if (isMounted.current) setT(getT);
|
|
645
|
+
});
|
|
646
|
+
} else {
|
|
647
|
+
loadNamespaces(i18n, namespaces, () => {
|
|
648
|
+
if (isMounted.current) setT(getT);
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
if (ready && previousJoinedNS && previousJoinedNS !== joinedNS && isMounted.current) {
|
|
653
|
+
setT(getT);
|
|
654
|
+
}
|
|
655
|
+
function boundReset() {
|
|
656
|
+
if (isMounted.current) setT(getT);
|
|
657
|
+
}
|
|
658
|
+
if (bindI18n && i18n) i18n.on(bindI18n, boundReset);
|
|
659
|
+
if (bindI18nStore && i18n) i18n.store.on(bindI18nStore, boundReset);
|
|
660
|
+
return () => {
|
|
661
|
+
isMounted.current = false;
|
|
662
|
+
if (bindI18n && i18n) bindI18n.split(' ').forEach(e => i18n.off(e, boundReset));
|
|
663
|
+
if (bindI18nStore && i18n) bindI18nStore.split(' ').forEach(e => i18n.store.off(e, boundReset));
|
|
664
|
+
};
|
|
665
|
+
}, [i18n, joinedNS]);
|
|
666
|
+
const isInitial = react.useRef(true);
|
|
667
|
+
react.useEffect(() => {
|
|
668
|
+
if (isMounted.current && !isInitial.current) {
|
|
669
|
+
setT(getT);
|
|
670
|
+
}
|
|
671
|
+
isInitial.current = false;
|
|
672
|
+
}, [i18n, keyPrefix]);
|
|
673
|
+
const ret = [t, i18n, ready];
|
|
674
|
+
ret.t = t;
|
|
675
|
+
ret.i18n = i18n;
|
|
676
|
+
ret.ready = ready;
|
|
677
|
+
if (ready) return ret;
|
|
678
|
+
if (!ready && !useSuspense) return ret;
|
|
679
|
+
throw new Promise(resolve => {
|
|
680
|
+
if (props.lng) {
|
|
681
|
+
loadLanguages(i18n, props.lng, namespaces, () => resolve());
|
|
682
|
+
} else {
|
|
683
|
+
loadNamespaces(i18n, namespaces, () => resolve());
|
|
684
|
+
}
|
|
685
|
+
});
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
function withTranslation(ns) {
|
|
689
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
690
|
+
return function Extend(WrappedComponent) {
|
|
691
|
+
function I18nextWithTranslation(_ref) {
|
|
692
|
+
let {
|
|
693
|
+
forwardedRef,
|
|
694
|
+
...rest
|
|
695
|
+
} = _ref;
|
|
696
|
+
const [t, i18n, ready] = useTranslation(ns, {
|
|
697
|
+
...rest,
|
|
698
|
+
keyPrefix: options.keyPrefix
|
|
699
|
+
});
|
|
700
|
+
const passDownProps = {
|
|
701
|
+
...rest,
|
|
702
|
+
t,
|
|
703
|
+
i18n,
|
|
704
|
+
tReady: ready
|
|
705
|
+
};
|
|
706
|
+
if (options.withRef && forwardedRef) {
|
|
707
|
+
passDownProps.ref = forwardedRef;
|
|
708
|
+
} else if (!options.withRef && forwardedRef) {
|
|
709
|
+
passDownProps.forwardedRef = forwardedRef;
|
|
710
|
+
}
|
|
711
|
+
return react.createElement(WrappedComponent, passDownProps);
|
|
712
|
+
}
|
|
713
|
+
I18nextWithTranslation.displayName = `withI18nextTranslation(${getDisplayName(WrappedComponent)})`;
|
|
714
|
+
I18nextWithTranslation.WrappedComponent = WrappedComponent;
|
|
715
|
+
const forwardRef = (props, ref) => react.createElement(I18nextWithTranslation, Object.assign({}, props, {
|
|
716
|
+
forwardedRef: ref
|
|
717
|
+
}));
|
|
718
|
+
return options.withRef ? react.forwardRef(forwardRef) : I18nextWithTranslation;
|
|
719
|
+
};
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
function Translation(props) {
|
|
723
|
+
const {
|
|
724
|
+
ns,
|
|
725
|
+
children,
|
|
726
|
+
...options
|
|
727
|
+
} = props;
|
|
728
|
+
const [t, i18n, ready] = useTranslation(ns, options);
|
|
729
|
+
return children(t, {
|
|
730
|
+
i18n,
|
|
731
|
+
lng: i18n.language
|
|
732
|
+
}, ready);
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
function I18nextProvider(_ref) {
|
|
736
|
+
let {
|
|
737
|
+
i18n,
|
|
738
|
+
defaultNS,
|
|
739
|
+
children
|
|
740
|
+
} = _ref;
|
|
741
|
+
const value = react.useMemo(() => ({
|
|
742
|
+
i18n,
|
|
743
|
+
defaultNS
|
|
744
|
+
}), [i18n, defaultNS]);
|
|
745
|
+
return react.createElement(I18nContext.Provider, {
|
|
746
|
+
value
|
|
747
|
+
}, children);
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
function useSSR(initialI18nStore, initialLanguage) {
|
|
751
|
+
let props = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
752
|
+
const {
|
|
753
|
+
i18n: i18nFromProps
|
|
754
|
+
} = props;
|
|
755
|
+
const {
|
|
756
|
+
i18n: i18nFromContext
|
|
757
|
+
} = react.useContext(I18nContext) || {};
|
|
758
|
+
const i18n = i18nFromProps || i18nFromContext || getI18n();
|
|
759
|
+
if (i18n.options && i18n.options.isClone) return;
|
|
760
|
+
if (initialI18nStore && !i18n.initializedStoreOnce) {
|
|
761
|
+
i18n.services.resourceStore.data = initialI18nStore;
|
|
762
|
+
i18n.options.ns = Object.values(initialI18nStore).reduce((mem, lngResources) => {
|
|
763
|
+
Object.keys(lngResources).forEach(ns => {
|
|
764
|
+
if (mem.indexOf(ns) < 0) mem.push(ns);
|
|
765
|
+
});
|
|
766
|
+
return mem;
|
|
767
|
+
}, i18n.options.ns);
|
|
768
|
+
i18n.initializedStoreOnce = true;
|
|
769
|
+
i18n.isInitialized = true;
|
|
770
|
+
}
|
|
771
|
+
if (initialLanguage && !i18n.initializedLanguageOnce) {
|
|
772
|
+
i18n.changeLanguage(initialLanguage);
|
|
773
|
+
i18n.initializedLanguageOnce = true;
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
function withSSR() {
|
|
778
|
+
return function Extend(WrappedComponent) {
|
|
779
|
+
function I18nextWithSSR(_ref) {
|
|
780
|
+
let {
|
|
781
|
+
initialI18nStore,
|
|
782
|
+
initialLanguage,
|
|
783
|
+
...rest
|
|
784
|
+
} = _ref;
|
|
785
|
+
useSSR(initialI18nStore, initialLanguage);
|
|
786
|
+
return react.createElement(WrappedComponent, {
|
|
787
|
+
...rest
|
|
788
|
+
});
|
|
789
|
+
}
|
|
790
|
+
I18nextWithSSR.getInitialProps = composeInitialProps(WrappedComponent);
|
|
791
|
+
I18nextWithSSR.displayName = `withI18nextSSR(${getDisplayName(WrappedComponent)})`;
|
|
792
|
+
I18nextWithSSR.WrappedComponent = WrappedComponent;
|
|
793
|
+
return I18nextWithSSR;
|
|
794
|
+
};
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
const date = () => '';
|
|
798
|
+
const time = () => '';
|
|
799
|
+
const number = () => '';
|
|
800
|
+
const select = () => '';
|
|
801
|
+
const plural = () => '';
|
|
802
|
+
const selectOrdinal = () => '';
|
|
803
|
+
|
|
804
|
+
exports.I18nContext = I18nContext;
|
|
805
|
+
exports.I18nextProvider = I18nextProvider;
|
|
806
|
+
exports.Trans = Trans;
|
|
807
|
+
exports.TransWithoutContext = Trans$1;
|
|
808
|
+
exports.Translation = Translation;
|
|
809
|
+
exports.composeInitialProps = composeInitialProps;
|
|
810
|
+
exports.date = date;
|
|
811
|
+
exports.getDefaults = getDefaults;
|
|
812
|
+
exports.getI18n = getI18n;
|
|
813
|
+
exports.getInitialProps = getInitialProps;
|
|
814
|
+
exports.initReactI18next = initReactI18next;
|
|
815
|
+
exports.number = number;
|
|
816
|
+
exports.plural = plural;
|
|
817
|
+
exports.select = select;
|
|
818
|
+
exports.selectOrdinal = selectOrdinal;
|
|
819
|
+
exports.setDefaults = setDefaults;
|
|
820
|
+
exports.setI18n = setI18n;
|
|
821
|
+
exports.time = time;
|
|
822
|
+
exports.useSSR = useSSR;
|
|
823
|
+
exports.useTranslation = useTranslation;
|
|
824
|
+
exports.withSSR = withSSR;
|
|
825
|
+
exports.withTranslation = withTranslation;
|
|
826
|
+
|
|
827
|
+
}));
|