-
Notifications
You must be signed in to change notification settings - Fork 66.8k
Expand file tree
/
Copy pathcorrect-translation-content.ts
More file actions
1638 lines (1387 loc) · 67.2 KB
/
correct-translation-content.ts
File metadata and controls
1638 lines (1387 loc) · 67.2 KB
1
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
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
import { describe, expect, test } from 'vitest'
import { performance } from 'perf_hooks'
import { correctTranslatedContentStrings } from '@/languages/lib/correct-translation-content'
function fix(content: string, code: string, englishContent = '') {
return correctTranslatedContentStrings(content, englishContent, {
code,
relativePath: 'test.md',
skipOrphanStripping: true,
})
}
describe('correctTranslatedContentStrings', () => {
// ─── SPANISH (es) ───────────────────────────────────────────────────
describe('Spanish (es)', () => {
test('fixes colon-prefix tags', () => {
expect(fix('{%: ifversion ghec %}', 'es')).toBe('{% ifversion ghec %}')
})
test('fixes translated data tag variants', () => {
expect(fix('{% vulnerables variables.product.github %}', 'es')).toBe(
'{% data variables.product.github %}',
)
expect(fix('{% datos variables.product.github %}', 'es')).toBe(
'{% data variables.product.github %}',
)
expect(fix('{% de datos variables.product.github %}', 'es')).toBe(
'{% data variables.product.github %}',
)
expect(fix('{% datos reusables.foo.bar %}', 'es')).toBe('{% data reusables.foo.bar %}')
expect(fix('{% data reutilizables.foo.bar %}', 'es')).toBe('{% data reusables.foo.bar %}')
})
test('fixes translated comment keyword', () => {
expect(fix('{% comentario %}', 'es')).toBe('{% comment %}')
expect(fix('{%- comentario %}', 'es')).toBe('{%- comment %}')
})
test('fixes translated if keyword', () => {
expect(fix('{% si ghec %}', 'es')).toBe('{% if ghec %}')
})
test('fixes translated raw keyword variants', () => {
expect(fix('{% sin procesar %}', 'es')).toBe('{% raw %}')
expect(fix('{% %} sin procesar', 'es')).toBe('{% raw %}')
expect(fix('{% sin formato }', 'es')).toBe('{% raw %}')
expect(fix('{%sin formato}', 'es')).toBe('{% raw %}')
expect(fix('{% %sin formato }', 'es')).toBe('{% raw %}')
})
test('fixes translated glossary template', () => {
expect(fix('{% para glosario en glosarios %}', 'es')).toBe('{% for glossary in glossaries %}')
expect(fix('{{ glosario.term }}', 'es')).toBe('{{ glossary.term }}')
expect(fix('{{ glosario.description }}', 'es')).toBe('{{ glossary.description }}')
})
test('fixes o and y/o → or in ifversion tags', () => {
expect(fix('{% ifversion fpt o ghec %}', 'es')).toBe('{% ifversion fpt or ghec %}')
expect(fix('{% ifversion fpt y/o ghec %}', 'es')).toBe('{% ifversion fpt or ghec %}')
expect(fix('{%- ifversion fpt o ghec %}', 'es')).toBe('{%- ifversion fpt or ghec %}')
expect(fix('{% elsif fpt o ghec %}', 'es')).toBe('{% elsif fpt or ghec %}')
})
test('fixes no → not in ifversion tags', () => {
expect(fix('{% ifversion no ghes %}', 'es')).toBe('{% ifversion not ghes %}')
expect(fix('{%- ifversion no ghes %}', 'es')).toBe('{%- ifversion not ghes %}')
})
test('fixes translated for-loop keywords', () => {
expect(fix('{%- para entrada en list %}', 'es')).toBe('{%- for entry in list %}')
expect(fix('{%- para la entrada en list %}', 'es')).toBe('{%- for entry in list %}')
})
test('translates cuando → when in case statements', () => {
expect(fix('{%- cuando "supported" %}', 'es')).toBe('{%- when "supported" %}')
})
test('fixes translated note block tags', () => {
expect(fix('{% nota %}', 'es')).toBe('{% note %}')
expect(fix('{%- nota %}', 'es')).toBe('{%- note %}')
expect(fix('{%- nota -%}', 'es')).toBe('{%- note -%}')
})
test('fixes otra → else', () => {
expect(fix('{% otra %}', 'es')).toBe('{% else %}')
expect(fix('{%- otra %}', 'es')).toBe('{%- else %}')
})
test('fixes encabezados de fila → rowheaders', () => {
expect(fix('{% encabezados de fila %}', 'es')).toBe('{% rowheaders %}')
expect(fix('{%- encabezados de fila %}', 'es')).toBe('{%- rowheaders %}')
})
test('fixes icono → octicon', () => {
expect(fix('{% icono "copilot" aria-hidden="true" aria-label="Copilot" %}', 'es')).toBe(
'{% octicon "copilot" aria-hidden="true" aria-label="Copilot" %}',
)
expect(fix('{%- icono "check" %}', 'es')).toBe('{%- octicon "check" %}')
})
test('fixes octicon "bombilla" → octicon "light-bulb"', () => {
expect(fix('{% octicon "bombilla" aria-label="The light-bulb icon" %}', 'es')).toBe(
'{% octicon "light-bulb" aria-label="The light-bulb icon" %}',
)
expect(fix('{%- octicon "bombilla" aria-label="The light-bulb icon" %}', 'es')).toBe(
'{%- octicon "light-bulb" aria-label="The light-bulb icon" %}',
)
})
test('fixes capturar → capture', () => {
expect(fix('{% capturar service_name %}runner{% endcapture %}', 'es')).toBe(
'{% capture service_name %}runner{% endcapture %}',
)
})
test('fixes para el modelo en → for model in', () => {
expect(fix('{% para el modelo en tables.copilot.model-comparison %}', 'es')).toBe(
'{% for model in tables.copilot.model-comparison %}',
)
})
test('fixes multiple or-translations in single ifversion', () => {
expect(fix('{% ifversion fpt o ghec o ghes %}', 'es')).toBe(
'{% ifversion fpt or ghec or ghes %}',
)
})
test('fixes datos reutilizables → data reusables', () => {
expect(fix('{% datos reutilizables.profile.access_org %}', 'es')).toBe(
'{% data reusables.profile.access_org %}',
)
})
test('fixes siVersion → ifversion', () => {
expect(fix('{% siVersion productos-ghas %}', 'es')).toBe('{% ifversion productos-ghas %}')
expect(fix('{%- siVersion productos-ghas %}', 'es')).toBe('{%- ifversion productos-ghas %}')
})
})
// ─── JAPANESE (ja) ──────────────────────────────────────────────────
describe('Japanese (ja)', () => {
test('fixes translated data tags', () => {
expect(fix('{% データ variables.product.github %}', 'ja')).toBe(
'{% data variables.product.github %}',
)
expect(fix('{% データvariables.product.github %}', 'ja')).toBe(
'{% data variables.product.github %}',
)
expect(fix('{% データ reusables.foo %}', 'ja')).toBe('{% data reusables.foo %}')
expect(fix('{% データ変数.product.github %}', 'ja')).toBe(
'{% data variables.product.github %}',
)
expect(fix('{% データ再利用可能な.foo %}', 'ja')).toBe('{% data reusables.foo %}')
expect(fix('{% データ再利用可能.foo %}', 'ja')).toBe('{% data reusables.foo %}')
expect(fix('{% データ再利用.foo %}', 'ja')).toBe('{% data reusables.foo %}')
})
test('fixes double-brace data corruption', () => {
expect(fix('{% {{データ}} variables.product.github %}', 'ja')).toBe(
'{% data variables.product.github %}',
)
})
test('fixes note keyword', () => {
expect(fix('{% メモ %}', 'ja')).toBe('{% note %}')
expect(fix('{%- メモ %}', 'ja')).toBe('{%- note %}')
})
test('fixes Japanese or (または) in ifversion tags', () => {
expect(fix('{% ifversion fpt または ghec %}', 'ja')).toBe('{% ifversion fpt or ghec %}')
expect(fix('{%- ifversion fpt または ghec %}', 'ja')).toBe('{%- ifversion fpt or ghec %}')
})
test('fixes trailing quote on YAML value', () => {
expect(fix(' asked_too_many_times: some value" ', 'ja')).toBe(
' asked_too_many_times: some value',
)
})
test('fixes translated endcase', () => {
expect(fix('{%- エンドケース -%}', 'ja')).toBe('{%- endcase -%}')
expect(fix('{% エンドケース %}', 'ja')).toBe('{% endcase %}')
})
test('fixes translated else', () => {
expect(fix('{%- それ以外の場合 %}', 'ja')).toBe('{%- else %}')
expect(fix('{% それ以外の場合 %}', 'ja')).toBe('{% else %}')
})
test('fixes translated comment/endcomment', () => {
expect(fix('{%- コメント %}', 'ja')).toBe('{%- comment %}')
expect(fix('{% コメント %}', 'ja')).toBe('{% comment %}')
expect(fix('{%- 終了コメント %}', 'ja')).toBe('{%- endcomment %}')
expect(fix('{% 終了コメント %}', 'ja')).toBe('{% endcomment %}')
})
test('adds missing when keyword for English strings', () => {
expect(fix('{%- "supported" %}', 'ja')).toBe('{%- when "supported" %}')
expect(fix('{% "not_supported" %}', 'ja')).toBe('{% when "not_supported" %}')
expect(fix('{%- "preview" %}', 'ja')).toBe('{%- when "preview" %}')
})
test('adds missing when keyword for Japanese strings', () => {
expect(fix('{%- "サポートされている" %}', 'ja')).toBe('{%- when "supported" %}')
expect(fix('{%- "サポートされていません" %}', 'ja')).toBe('{%- when "not_supported" %}')
expect(fix('{%- "プレビュー" %}', 'ja')).toBe('{%- when "preview" %}')
})
test('preserves trim syntax when adding when keyword', () => {
expect(fix('{% "supported" %}', 'ja')).toBe('{% when "supported" %}')
expect(fix('{%- "supported" %}', 'ja')).toBe('{%- when "supported" %}')
})
test('fixes empty trim tag before C', () => {
expect(fix('{%- %}C', 'ja')).toBe('{%- when "closing-down" %}C')
})
test('fixes translated for-loops with の', () => {
expect(fix('{%- tables.copilot.ides の version -%}', 'ja')).toBe(
'{%- for version in tables.copilot.ides -%}',
)
expect(fix('{% groupVersions の ver %}', 'ja')).toBe('{% for ver in groupVersions %}')
})
test('fixes for-loop variant with の outside tag', () => {
expect(fix('{%- tables.copilot.ides %} のversionの場合', 'ja')).toBe(
'{%- for version in tables.copilot.ides %}',
)
})
test('fixes translated variable names', () => {
expect(fix('{{ バージョン }}', 'ja')).toBe('{{ version }}')
expect(fix('{{ 言語 }}', 'ja')).toBe('{{ language }}')
})
test('fixes translated assign keyword', () => {
expect(fix('{%- 言語を割り当てる = "ja" %}', 'ja')).toBe('{%- assign language = "ja" %}')
})
test('fixes rearranged assign with を割り当てる', () => {
expect(fix('{%- featureData = entry.features %} を割り当てる', 'ja')).toBe(
'{%- assign featureData = entry.features %}',
)
})
test('strips stray の割り当て and の場合', () => {
expect(fix('{%- assign x = y -%} の割り当て', 'ja')).toBe('{%- assign x = y -%}')
})
test('adds missing if keyword', () => {
expect(fix('{%- featureData.overview %}', 'ja')).toBe('{%- if featureData.overview %}')
expect(fix('{% entry.hasNote %}', 'ja')).toBe('{% if entry.hasNote %}')
})
test('adds missing assign keyword', () => {
expect(fix('{%- featureKey = "copilot" %}', 'ja')).toBe(
'{%- assign featureKey = "copilot" %}',
)
expect(fix('{%- supportLevel = entry.support -%}', 'ja')).toBe(
'{%- assign supportLevel = entry.support -%}',
)
})
test('fixes garbled endif with percent placed after keyword', () => {
// `{ endif% %}` — percent appears after "endif" instead of after the opening brace
expect(fix('some content\n{ endif% %}\nmore', 'ja')).toBe('some content\n{% endif %}\nmore')
})
test('fixes truncated それ以外の → else', () => {
expect(fix('{% それ以外の %}', 'ja')).toBe('{% else %}')
expect(fix('{%- それ以外の %}', 'ja')).toBe('{%- else %}')
})
test('fixes further-truncated それ以外 → else', () => {
expect(fix('{% それ以外 %}', 'ja')).toBe('{% else %}')
expect(fix('{%- それ以外 %}', 'ja')).toBe('{%- else %}')
})
test('fixes それ以外の場合 ifversion X → elsif X', () => {
expect(fix('{% それ以外の場合 ifversion codeql-rust-public-preview %}', 'ja')).toBe(
'{% elsif codeql-rust-public-preview %}',
)
// no space before closing tag
expect(fix('{% それ以外の場合 ifversion codeql-rust-public-preview%}', 'ja')).toBe(
'{% elsif codeql-rust-public-preview %}',
)
})
test('fixes 行ヘッダー → rowheaders', () => {
expect(fix('{% 行ヘッダー %}', 'ja')).toBe('{% rowheaders %}')
expect(fix('{%- 行ヘッダー %}', 'ja')).toBe('{%- rowheaders %}')
})
test('fixes ウィンドウズ → windows', () => {
expect(fix('{% ウィンドウズ %}', 'ja')).toBe('{% windows %}')
expect(fix('{%- ウィンドウズ %}', 'ja')).toBe('{%- windows %}')
})
test('fixes ウィンドウ (without ズ) → windows', () => {
expect(fix('{% ウィンドウ %}', 'ja')).toBe('{% windows %}')
expect(fix('{%- ウィンドウ %}', 'ja')).toBe('{%- windows %}')
})
})
// ─── PORTUGUESE (pt) ───────────────────────────────────────────────
describe('Portuguese (pt)', () => {
test('fixes translated data tags', () => {
expect(fix('{% dados variables.product.github %}', 'pt')).toBe(
'{% data variables.product.github %}',
)
expect(fix('{% de dados variables.product.github %}', 'pt')).toBe(
'{% data variables.product.github %}',
)
expect(fix('{% dados reusables.foo %}', 'pt')).toBe('{% data reusables.foo %}')
expect(fix('{{% dados variables.product.github %}', 'pt')).toBe(
'{% data variables.product.github %}',
)
expect(fix('{{% datas variables.product.github %}', 'pt')).toBe(
'{% data variables.product.github %}',
)
})
test('fixes en-dash in trim modifier', () => {
// `{%–` — en-dash (U+2013) used instead of hyphen in `{%-` trim modifier
expect(fix('{%– ifversion projects-v1 %}', 'pt')).toBe('{%- ifversion projects-v1 %}')
expect(fix('{%– endif %}', 'pt')).toBe('{%- endif %}')
})
test('fixes datavariables / dadosvariables (no space)', () => {
// `{% datavariables` — no space between "data" and "variables" (post-translation)
expect(fix('{% datavariables.product.github %}', 'pt')).toBe(
'{% data variables.product.github %}',
)
expect(fix('{%- datavariables.product.github %}', 'pt')).toBe(
'{%- data variables.product.github %}',
)
// `{% dadosvariables` — Portuguese "dados" fused with "variables"
expect(fix('{% dadosvariables.product.github %}', 'pt')).toBe(
'{% data variables.product.github %}',
)
})
test('fixes translated else variants', () => {
expect(fix('{% senão %}', 'pt')).toBe('{% else %}')
expect(fix('{%- senão %}', 'pt')).toBe('{%- else %}')
expect(fix('{% mais %}', 'pt')).toBe('{% else %}')
expect(fix('{%- mais %}', 'pt')).toBe('{%- else %}')
})
test('fixes translated if keyword', () => {
expect(fix('{% se ghec %}', 'pt')).toBe('{% if ghec %}')
})
test('fixes translated assign keyword', () => {
expect(fix('{% atribuir x = y %}', 'pt')).toBe('{% assign x = y %}')
})
test('fixes translated raw keyword', () => {
expect(fix('{% %} bruto', 'pt')).toBe('{% raw %}')
})
test('fixes %de dados patterns', () => {
expect(fix('{% %de dados reusables.foo %}', 'pt')).toBe('{% data reusables.foo %}')
expect(fix('{% %de dados variables.product.github %}', 'pt')).toBe(
'{% data variables.product.github %}',
)
})
test('fixes móvel keyword', () => {
expect(fix('{% %móvel }', 'pt')).toBe('{% mobile %}')
})
test('fixes ou → or in ifversion tags', () => {
expect(fix('{% ifversion fpt ou ghec %}', 'pt')).toBe('{% ifversion fpt or ghec %}')
expect(fix('{%- elsif fpt ou ghec %}', 'pt')).toBe('{%- elsif fpt or ghec %}')
})
test('fixes ou → or in if tags', () => {
expect(fix('{% if condition ou other %}', 'pt')).toBe('{% if condition or other %}')
})
test('fixes fully translated reutilizáveis reusables path', () => {
// `reutilizáveis` is Portuguese for "reusables"
expect(fix('{% dados reutilizáveis.repositórios.reaction_list %}', 'pt')).toBe(
'{% data reusables.repositories.reaction_list %}',
)
expect(fix('{% dados reutilizáveis.foo.bar %}', 'pt')).toBe('{% data reusables.foo.bar %}')
})
test('fixes translated repositórios path segment', () => {
// `repositórios` is Portuguese for "repositories"
expect(fix('{% data reusables.repositórios.reaction_list %}', 'pt')).toBe(
'{% data reusables.repositories.reaction_list %}',
)
})
test('fixes variáveis de dados → data variables', () => {
expect(fix('{% variáveis de dados.release-phases.public_preview %}', 'pt')).toBe(
'{% data variables.release-phases.public_preview %}',
)
expect(fix('{% variáveis de dados product.github %}', 'pt')).toBe(
'{% data variables product.github %}',
)
})
test('fixes dados variáveis → data variables', () => {
expect(fix('{% dados variáveis.produto.prodname_pro %}', 'pt')).toBe(
'{% data variables.produto.prodname_pro %}',
)
})
test('fixes janelas → windows', () => {
expect(fix('{% janelas %}', 'pt')).toBe('{% windows %}')
expect(fix('{%- janelas %}', 'pt')).toBe('{%- windows %}')
})
test('fixes observação → note', () => {
expect(fix('{% observação %}', 'pt')).toBe('{% note %}')
expect(fix('{%- observação %}', 'pt')).toBe('{%- note %}')
})
test('fixes comentário → comment', () => {
expect(fix('{% comentário %}', 'pt')).toBe('{% comment %}')
expect(fix('{%- comentário %}', 'pt')).toBe('{%- comment %}')
})
test('fixes nota de fim → endnote', () => {
expect(fix('{% nota de fim %}', 'pt')).toBe('{% endnote %}')
expect(fix('{%- nota de fim %}', 'pt')).toBe('{%- endnote %}')
})
test('fixes Dados variables → data variables', () => {
expect(fix('{% Dados variables.product.github %}', 'pt')).toBe(
'{% data variables.product.github %}',
)
})
test('fixes fully translated audit_log reusable path', () => {
expect(
fix(
'{% dados agrupados por categoria.complemento.audit_log.reference-grouped-by-category %}',
'pt',
),
).toBe('{% data reusables.audit_log.reference-grouped-by-category %}')
})
})
// ─── CHINESE (zh) ──────────────────────────────────────────────────
describe('Chinese (zh)', () => {
test('fixes translated data tags', () => {
expect(fix('{% 数据variables.product.github %}', 'zh')).toBe(
'{% data variables.product.github %}',
)
expect(fix('{% 数据 variables.product.github %}', 'zh')).toBe(
'{% data variables.product.github %}',
)
expect(fix('{% 数据可重用s.foo %}', 'zh')).toBe('{% data reusables.foo %}')
// No space between `{%` and 数据
expect(fix('{%数据variables.product.github%}', 'zh')).toBe(
'{% data variables.product.github%}',
)
expect(fix('{%数据 variables.product.github%}', 'zh')).toBe(
'{% data variables.product.github%}',
)
})
test('fixes translated else and raw', () => {
expect(fix('{% 其他 %}', 'zh')).toBe('{% else %}')
expect(fix('{%- 其他 %}', 'zh')).toBe('{%- else %}')
expect(fix('{% 原始 %}', 'zh')).toBe('{% raw %}')
expect(fix('{%- 原始 %}', 'zh')).toBe('{%- raw %}')
})
test('fixes Chinese if keyword', () => {
expect(fix('{ 如果 ghec %}', 'zh')).toBe('{% if ghec %}')
})
test('fixes stray Chinese then merged with HTML', () => {
expect(fix(',则为 {%<div>', 'zh')).toBe('<div>')
})
test('fixes 或 → or in ifversion tags', () => {
expect(fix('{% ifversion fpt 或 ghec %}', 'zh')).toBe('{% ifversion fpt or ghec %}')
expect(fix('{%- elsif fpt 或 ghec %}', 'zh')).toBe('{%- elsif fpt or ghec %}')
})
test('fixes 否则 → else', () => {
expect(fix('{% 否则 %}', 'zh')).toBe('{% else %}')
expect(fix('{%- 否则 %}', 'zh')).toBe('{%- else %}')
})
test('fixes 行标题 → rowheaders', () => {
expect(fix('{% 行标题 %}', 'zh')).toBe('{% rowheaders %}')
expect(fix('{%- 行标题 %}', 'zh')).toBe('{%- rowheaders %}')
})
test('fixes 数据变量 → data variables', () => {
expect(fix('{% 数据变量.product.github %}', 'zh')).toBe('{% data variables.product.github %}')
})
})
// ─── RUSSIAN (ru) ──────────────────────────────────────────────────
describe('Russian (ru)', () => {
test('fixes AUTOTITLE with guillemets', () => {
expect(fix('[«AUTOTITLE»](/path)', 'ru')).toBe('[AUTOTITLE](/path)')
})
test('fixes АВТОЗАГОЛОВОК (translated AUTOTITLE)', () => {
expect(fix('[АВТОЗАГОЛОВОК](/path/to/article)', 'ru')).toBe('[AUTOTITLE](/path/to/article)')
})
test('fixes translated data tag variants', () => {
expect(fix('{% данных variables.product.github %}', 'ru')).toBe(
'{% data variables.product.github %}',
)
expect(fix('{% данных, variables.product.github %}', 'ru')).toBe(
'{% data variables.product.github %}',
)
expect(fix('{% данными variables.product.github %}', 'ru')).toBe(
'{% data variables.product.github %}',
)
expect(fix('{% данных организации variables.product.github %}', 'ru')).toBe(
'{% data variables.product.github %}',
)
expect(fix('{% данным variables.product.github %}', 'ru')).toBe(
'{% data variables.product.github %}',
)
expect(fix('{% данные variables.product.github %}', 'ru')).toBe(
'{% data variables.product.github %}',
)
expect(fix('{% данных reusables.foo %}', 'ru')).toBe('{% data reusables.foo %}')
expect(fix('{% данные reusables.foo %}', 'ru')).toBe('{% data reusables.foo %}')
})
test('fixes broadened данных. pattern', () => {
expect(fix('{% данных.product.github %}', 'ru')).toBe('{% data variables.product.github %}')
})
test('fixes переменных данных pattern', () => {
expect(fix('{% переменных данных.product.github %}', 'ru')).toBe(
'{% data variables.product.github %}',
)
expect(fix('{% data переменных.product.github %}', 'ru')).toBe(
'{% data variables.product.github %}',
)
})
test('fixes dot-prefix paths', () => {
expect(fix('{% .dependency-review.foo %}', 'ru')).toBe(
'{% data variables.dependency-review.foo %}',
)
expect(fix('{% .code-scanning.foo %}', 'ru')).toBe('{% data variables.code-scanning.foo %}')
expect(fix('{%.dependency-review.foo %}', 'ru')).toBe(
'{% data variables.dependency-review.foo %}',
)
expect(fix('{%.copilot.foo %}', 'ru')).toBe('{% data variables.copilot.foo %}')
})
test('fixes stray punctuation in data tags', () => {
expect(fix('{% данных" variables.product.github %}', 'ru')).toBe(
'{% data variables.product.github %}',
)
expect(fix('{%" variables.product.github %}', 'ru')).toBe(
'{% data variables.product.github %}',
)
expect(fix('{%, variables.product.github %}', 'ru')).toBe(
'{% data variables.product.github %}',
)
})
test('fixes translated raw/endraw', () => {
expect(fix('{% необработанного %}', 'ru')).toBe('{% raw %}')
expect(fix('{%- необработанного %}', 'ru')).toBe('{%- raw %}')
expect(fix('{% необработанные %}', 'ru')).toBe('{% raw %}')
expect(fix('{%- необработанные %}', 'ru')).toBe('{%- raw %}')
expect(fix('{% необработанный %}', 'ru')).toBe('{% raw %}')
expect(fix('{%- необработанный %}', 'ru')).toBe('{%- raw %}')
expect(fix('{% сырой %}', 'ru')).toBe('{% raw %}')
expect(fix('{%- сырой %}', 'ru')).toBe('{%- raw %}')
expect(fix('{% нарисовать %}', 'ru')).toBe('{% endraw %}')
expect(fix('{%- нарисовать %}', 'ru')).toBe('{%- endraw %}')
expect(fix('{% запроса %}', 'ru')).toBe('{% endraw %}')
expect(fix('{%- запроса %}', 'ru')).toBe('{%- endraw %}')
})
test('fixes translated or (или) in ifversion tags', () => {
expect(fix('{%- ifversion fpt или ghec %}', 'ru')).toBe('{%- ifversion fpt or ghec %}')
expect(fix('{% ifversion fpt или ghec %}', 'ru')).toBe('{% ifversion fpt or ghec %}')
expect(fix('{% ifversion ghec или fpt %}', 'ru')).toBe('{% ifversion ghec or fpt %}')
expect(fix('{% elsif ghec или ghes %}', 'ru')).toBe('{% elsif ghec or ghes %}')
expect(fix('{% ghes или ghec %}', 'ru')).toBe('{% ifversion ghes or ghec %}')
})
test('fixes translated not (не)', () => {
expect(fix('{% ifversion не ghes %}', 'ru')).toBe('{% ifversion not ghes %}')
})
test('fixes translated else variants', () => {
expect(fix('{% еще %}', 'ru')).toBe('{% else %}')
expect(fix('{%- еще %}', 'ru')).toBe('{%- else %}')
expect(fix('{% ещё %}', 'ru')).toBe('{% else %}')
expect(fix('{%- ещё %}', 'ru')).toBe('{%- else %}')
})
test('fixes конец as context-aware end tag', () => {
expect(fix('{% raw %}some content{% конец %}', 'ru')).toBe(
'{% raw %}some content{% endraw %}',
)
expect(fix('{% конец %}', 'ru')).toBe('{% endif %}')
expect(fix('{%- конец %}', 'ru')).toBe('{%- endif %}')
})
test('fixes конец для → endfor', () => {
expect(fix('{%- конец для %}', 'ru')).toBe('{%- endfor %}')
})
test('fixes заголовки строк → rowheaders', () => {
expect(fix('{% заголовки строк %}', 'ru')).toBe('{% rowheaders %}')
expect(fix('{%- заголовки строк %}', 'ru')).toBe('{%- rowheaders %}')
})
test('fixes translated feature flag names', () => {
expect(fix('обязательный-2fa-dotcom-участник', 'ru')).toBe(
'mandatory-2fa-dotcom-contributors',
)
expect(fix('обязательный-2fa-участник-2023', 'ru')).toBe('mandatory-2fa-contributors-2023')
})
test('fixes other translated keywords', () => {
expect(fix('{% конечным %}', 'ru')).toBe('{% endif %}')
expect(fix('{%- конечным %}', 'ru')).toBe('{%- endif %}')
expect(fix('{% примечание %}', 'ru')).toBe('{% note %}')
expect(fix('{%- примечание %}', 'ru')).toBe('{%- note %}')
expect(fix('{% конечных головщиков %}', 'ru')).toBe('{% endrowheaders %}')
expect(fix('{% эндкёрл %}', 'ru')).toBe('{% endcurl %}')
expect(fix('{%- эндкёрл %}', 'ru')).toBe('{%- endcurl %}')
expect(fix('{% Эльсиф %}', 'ru')).toBe('{% else %}')
expect(fix('{%- Эльсиф %}', 'ru')).toBe('{%- else %}')
})
test('fixes translated reusable paths', () => {
expect(fix('{% повторно используемых данных.foo %}', 'ru')).toBe('{% data reusables.foo %}')
expect(fix('{% данных для повторного использования.foo %}', 'ru')).toBe(
'{% data reusables.foo %}',
)
})
test('fixes double quotes in Russian YAML (via generic)', () => {
expect(fix('href=""https://example.com"', 'ru')).toBe('href="https://example.com"')
})
test('fixes empty HTML tags (via generic)', () => {
expect(fix('some <b></b> text', 'ru')).toBe('some text')
expect(fix('some <u></u> text', 'ru')).toBe('some text')
})
test('fixes Russian glossary template', () => {
expect(fix('{% для глоссария в глоссариях %}', 'ru')).toBe('{% for glossary in glossaries %}')
expect(fix('{{ глоссарий.term }}', 'ru')).toBe('{{ glossary.term }}')
expect(fix('{{ глоссарий.description }}', 'ru')).toBe('{{ glossary.description }}')
})
test('fixes rearranged data tag patterns', () => {
expect(fix('variables.product.github %данных {% }', 'ru')).toBe(
'{% data variables.product.github %}',
)
})
test('fixes translated octicon names', () => {
expect(
fix('{% octicon "организация" aria-hidden="true" aria-label="organization" %}', 'ru'),
).toBe('{% octicon "organization" aria-hidden="true" aria-label="organization" %}')
})
test('fixes иначе → else', () => {
expect(fix('{% иначе %}', 'ru')).toBe('{% else %}')
expect(fix('{%- иначе %}', 'ru')).toBe('{%- else %}')
})
test('fixes capitalized Mac → mac platform tag (via generic)', () => {
expect(fix('{% Mac %}', 'ru')).toBe('{% mac %}')
expect(fix('{%- Mac %}', 'ru')).toBe('{%- mac %}')
})
test('fixes Endwindows → endwindows (via generic)', () => {
expect(fix('{% Endwindows %}', 'ru')).toBe('{% endwindows %}')
expect(fix('{%- Endwindows %}', 'ru')).toBe('{%- endwindows %}')
})
test('fixes capitalized Elsif → elsif (via generic)', () => {
expect(fix('{% Elsif ghec %}', 'ru')).toBe('{% elsif ghec %}')
})
test('fixes capitalized Linux → linux platform tag', () => {
expect(fix('{% Linux %}', 'ru')).toBe('{% linux %}')
expect(fix('{%- Linux %}', 'ru')).toBe('{%- linux %}')
})
test('fixes джетмозги → jetbrains', () => {
expect(fix('{% джетмозги %}', 'ru')).toBe('{% jetbrains %}')
expect(fix('{%- джетмозги %}', 'ru')).toBe('{%- jetbrains %}')
})
})
// ─── FRENCH (fr) ───────────────────────────────────────────────────
describe('French (fr)', () => {
test('fixes translated data tags', () => {
expect(fix('{% données variables.product.github %}', 'fr')).toBe(
'{% data variables.product.github %}',
)
expect(fix('{% données réutilisables.foo %}', 'fr')).toBe('{% data reusables.foo %}')
expect(fix('{% variables de données.product.github %}', 'fr')).toBe(
'{% data variables.product.github %}',
)
expect(fix('{% données reusables.foo %}', 'fr')).toBe('{% data reusables.foo %}')
// `{% de données variables.` — preposition "de" prepended
expect(fix('{% de données variables.product.github %}', 'fr')).toBe(
'{% data variables.product.github %}',
)
// `{% de data variables.` — partially-corrected form
expect(fix('{% de data variables.product.github %}', 'fr')).toBe(
'{% data variables.product.github %}',
)
})
test('fixes translated else', () => {
expect(fix('{% autre %}', 'fr')).toBe('{% else %}')
expect(fix('{%- autre %}', 'fr')).toBe('{%- else %}')
})
test('fixes translated raw/endraw', () => {
expect(fix('{% brut %}', 'fr')).toBe('{% raw %}')
expect(fix('{%- brut %}', 'fr')).toBe('{%- raw %}')
expect(fix('{% %brut }', 'fr')).toBe('{% raw %}')
expect(fix('{% redessiner %}', 'fr')).toBe('{% endraw %}')
expect(fix('{%- redessiner %}', 'fr')).toBe('{%- endraw %}')
})
test('fixes ou → or in ifversion tags', () => {
expect(fix('{% ifversion fpt ou ghec %}', 'fr')).toBe('{% ifversion fpt or ghec %}')
expect(fix('{%- elsif fpt ou ghec %}', 'fr')).toBe('{%- elsif fpt or ghec %}')
})
test('fixes ou → or in if tags', () => {
expect(
fix('{% if query.apiVersion == nil ou "2026-03-10" <= query.apiVersion %}', 'fr'),
).toBe('{% if query.apiVersion == nil or "2026-03-10" <= query.apiVersion %}')
})
test('fixes et → and in ifversion tags', () => {
expect(fix('{% ifversion ghes > 3.14 et ghes < 3.20 %}', 'fr')).toBe(
'{% ifversion ghes > 3.14 and ghes < 3.20 %}',
)
expect(fix('{%- ifversion ghes et fpt %}', 'fr')).toBe('{%- ifversion ghes and fpt %}')
})
test('fixes French guillemets « » → " in if/ifversion tags', () => {
expect(
fix('{% if query.apiVersion == nil ou « 2026-03-10 » <= query.apiVersion %}', 'fr'),
).toBe('{% if query.apiVersion == nil or "2026-03-10" <= query.apiVersion %}')
expect(fix('{% ifversion « ghec » %}', 'fr')).toBe('{% ifversion "ghec" %}')
})
test('fixes translated block tags', () => {
expect(fix('{% remarque %}', 'fr')).toBe('{% note %}')
expect(fix('{%- remarque %}', 'fr')).toBe('{%- note %}')
expect(fix('{%- remarque -%}', 'fr')).toBe('{%- note -%}')
expect(fix('{% avertissement %}', 'fr')).toBe('{% warning %}')
expect(fix('{%- avertissement %}', 'fr')).toBe('{%- warning %}')
expect(fix('{%- avertissement -%}', 'fr')).toBe('{%- warning -%}')
expect(fix('{% conseil %}', 'fr')).toBe('{% tip %}')
expect(fix('{%- conseil %}', 'fr')).toBe('{%- tip %}')
expect(fix('{%- conseil -%}', 'fr')).toBe('{%- tip -%}')
})
test('removes orphaned endif when no matching ifversion/elsif opener exists', () => {
// Caused by translations where only the closing tag survived (e.g. user-api.md reusable)
const fixWithStrip = (s: string) =>
correctTranslatedContentStrings(s, '', { code: 'fr', relativePath: 'test.md' })
expect(fixWithStrip('Some content\n{% endif %}\nMore content')).toBe(
'Some content\n\nMore content',
)
expect(fixWithStrip('Line one\n{%- endif %}\nLine two')).toBe('Line one\n\nLine two')
expect(fixWithStrip('Text {%- endif -%} more')).toBe('Text more')
})
test('preserves endif when matching ifversion opener is present', () => {
const input = '{% ifversion ghec %}content{% endif %}'
expect(fix(input, 'fr')).toBe(input)
})
test('preserves endif when elsif opener is present', () => {
const input = '{% ifversion fpt %}a{% elsif ghec %}b{% endif %}'
expect(fix(input, 'fr')).toBe(input)
})
test('fixes sinon → else', () => {
expect(fix('{% sinon %}', 'fr')).toBe('{% else %}')
expect(fix('{%- sinon %}', 'fr')).toBe('{%- else %}')
})
test('fixes note de fin → endnote', () => {
expect(fix('{% note de fin %}', 'fr')).toBe('{% endnote %}')
expect(fix('{%- note de fin %}', 'fr')).toBe('{%- endnote %}')
})
test('fixes éclipse → eclipse platform tag', () => {
expect(fix('{% éclipse %}', 'fr')).toBe('{% eclipse %}')
expect(fix('{%- éclipse %}', 'fr')).toBe('{%- eclipse %}')
})
test('fixes données_reutilisables → data reusables', () => {
expect(fix('{% données_reutilisables.user-settings.ssh %}', 'fr')).toBe(
'{% data reusables.user-settings.ssh %}',
)
expect(fix('{% données_réutilisables.codespaces.foo %}', 'fr')).toBe(
'{% data reusables.codespaces.foo %}',
)
})
test('fixes composants réutilisables → data reusables', () => {
expect(fix('{% composants réutilisables.répertoires.barre-latérale-sujets %}', 'fr')).toBe(
'{% data reusables.répertoires.barre-latérale-sujets %}',
)
})
test('fixes fully-translated données réutilisables propriétés-personnalisées path', () => {
expect(
fix('{% données réutilisables propriétés-personnalisées valeurs-requises %}', 'fr'),
).toBe('{% data reusables.organizations.custom-properties-required-values %}')
})
})
// ─── KOREAN (ko) ──────────────────────────────────────────────────
describe('Korean (ko)', () => {
test('fixes AUTOTITLE with Korean suffix', () => {
expect(fix('[AUTOTITLE"을 참조하세요]', 'ko')).toBe('[AUTOTITLE]')
})
test('fixes translated data tags', () => {
expect(fix('{% 데이터 variables.product.github %}', 'ko')).toBe(
'{% data variables.product.github %}',
)
expect(fix('{% 데이터 reusables.foo %}', 'ko')).toBe('{% data reusables.foo %}')
expect(fix('{% 데이터 변수.product.github %}', 'ko')).toBe(
'{% data variables.product.github %}',
)
expect(fix('{% 데이터 변숫값.product.github %}', 'ko')).toBe(
'{% data variables.product.github %}',
)
})
test('fixes extra percent before data (via generic)', () => {
expect(fix('{% % data variables.product.github %}', 'ko')).toBe(
'{% data variables.product.github %}',
)
})
test('fixes dada → data (via generic)', () => {
expect(fix('{% dada variables.product.github %}', 'ko')).toBe(
'{% data variables.product.github %}',
)
})
test('fixes translated keywords', () => {
expect(fix('{% 기타 %}', 'ko')).toBe('{% else %}')
expect(fix('{%- 기타 %}', 'ko')).toBe('{%- else %}')
expect(fix('{% 참고 %}', 'ko')).toBe('{% note %}')
expect(fix('{%- 참고 %}', 'ko')).toBe('{%- note %}')
expect(fix('{% 원시 %}', 'ko')).toBe('{% raw %}')
expect(fix('{%- 원시 %}', 'ko')).toBe('{%- raw %}')
})
test('fixes 또는 → or in ifversion tags', () => {
expect(fix('{% ifversion fpt 또는 ghec %}', 'ko')).toBe('{% ifversion fpt or ghec %}')
})
test('fixes Korean glossary template', () => {
expect(fix('{{ 용어집.term }}', 'ko')).toBe('{{ glossary.term }}')
})
test('fixes 그렇지 않으면 → else', () => {
expect(fix('{% 그렇지 않으면 %}', 'ko')).toBe('{% else %}')
expect(fix('{%- 그렇지 않으면 %}', 'ko')).toBe('{%- else %}')
})
test('fixes 옥티콘 → octicon', () => {
expect(fix('{% 옥티콘 "check" aria-label="Supported" %}', 'ko')).toBe(
'{% octicon "check" aria-label="Supported" %}',
)
expect(fix('{%- 옥티콘 "check" aria-label="Supported" %}', 'ko')).toBe(
'{%- octicon "check" aria-label="Supported" %}',
)
})
test('fixes 데이터 재사용 → data reusables', () => {
expect(fix('{% 데이터 재사용.profile.access_org %}', 'ko')).toBe(
'{% data reusables.profile.access_org %}',
)
})
test('fixes datavariable → data variables (via generic)', () => {
expect(fix('{% datavariable.product.github %}', 'ko')).toBe(
'{% data variables.product.github %}',
)
})
test('fixes 행 머리글 → rowheaders', () => {
expect(fix('{% 행 머리글 %}', 'ko')).toBe('{% rowheaders %}')
expect(fix('{%- 행 머리글 %}', 'ko')).toBe('{%- rowheaders %}')
})
test('fixes 윈도우즈 → windows', () => {
expect(fix('{% 윈도우즈 %}', 'ko')).toBe('{% windows %}')
expect(fix('{%- 윈도우즈 %}', 'ko')).toBe('{%- windows %}')
})
test('fixes 엔드맥 → endmac', () => {
expect(fix('{% 엔드맥 %}', 'ko')).toBe('{% endmac %}')
expect(fix('{%- 엔드맥 %}', 'ko')).toBe('{%- endmac %}')
})
test('fixes 주석 끝 → endnote', () => {
expect(fix('{% 주석 끝 %}', 'ko')).toBe('{% endnote %}')
expect(fix('{%- 주석 끝 %}', 'ko')).toBe('{%- endnote %}')
})
test('fixes capitalized Variables → data variables', () => {
expect(fix('{% data Variables.product.github %}', 'ko')).toBe(
'{% data variables.product.github %}',
)
expect(fix('{%- data Variables.product.github %}', 'ko')).toBe(
'{%- data variables.product.github %}',
)
})
})
// ─── GERMAN (de) ──────────────────────────────────────────────────
describe('German (de)', () => {
test('fixes translated data tags', () => {
expect(fix('{% Daten variables.product.github %}', 'de')).toBe(
'{% data variables.product.github %}',
)
expect(fix('{% daten variables.product.github %}', 'de')).toBe(
'{% data variables.product.github %}',
)
expect(fix('{% Daten reusables.foo %}', 'de')).toBe('{% data reusables.foo %}')
expect(fix('{%- Daten reusables.foo %}', 'de')).toBe('{%- data reusables.foo %}')
})
test('fixes hyphenated data tags without space', () => {
expect(fix('{%-Daten variables.product.github %}', 'de')).toBe(
'{%- data variables.product.github %}',
)
expect(fix('{%-Daten-variables.product.github %}', 'de')).toBe(
'{%- data variables.product.github %}',
)
})
test('fixes oder → or in ifversion tags', () => {
expect(fix('{%- ifversion fpt oder ghec %}', 'de')).toBe('{%- ifversion fpt or ghec %}')
expect(fix('{% ifversion fpt oder ghec %}', 'de')).toBe('{% ifversion fpt or ghec %}')
})
test('fixes translated block tags', () => {
expect(fix('{% Hinweis %}', 'de')).toBe('{% note %}')
expect(fix('{%- Hinweis %}', 'de')).toBe('{%- note %}')
expect(fix('{%- Hinweis -%}', 'de')).toBe('{%- note -%}')
expect(fix('{% Warnung %}', 'de')).toBe('{% warning %}')
expect(fix('{%- Warnung %}', 'de')).toBe('{%- warning %}')
expect(fix('{%- Warnung -%}', 'de')).toBe('{%- warning -%}')
expect(fix('{% Tipp %}', 'de')).toBe('{% tip %}')
expect(fix('{%- Tipp %}', 'de')).toBe('{%- tip %}')
expect(fix('{%- Tipp -%}', 'de')).toBe('{%- tip -%}')
})
test('fixes für → for in for-loops', () => {
expect(fix('{%- für version in tables.copilot.ides -%}', 'de')).toBe(
'{%- for version in tables.copilot.ides -%}',
)
expect(fix('{% für entry in list %}', 'de')).toBe('{% for entry in list %}')
})
test('fixes wiederverwendbare reusables path', () => {
// `wiederverwendbare` is German for "reusables"
expect(fix('{% data wiederverwendbare.audit_log.reference %}', 'de')).toBe(
'{% data reusables.audit_log.reference %}',
)
expect(fix('{% Daten wiederverwendbare.audit_log.reference %}', 'de')).toBe(
'{% data reusables.audit_log.reference %}',
)