T4 template - CultureNames.tt

.NET 在操作 Culture 時,免不了要帶入 CultureInfo 的 Name,多半是用 Hard code 的形式帶入,像是下面這樣:

1
2
3
4
...
var currentThread = Thread.CurrentThread;
currentThread.CurrentCulture = CultureInfo.GetCultureInfo("zh-tw");
...



這邊筆者做了個 T4 Template,期望能解決這樣的問題。

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
<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Globalization" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ output extension=".cs" #>
namespace System.Globalization
{
public static class CultureNames
{
<#
var cultures = CultureInfo.GetCultures(CultureTypes.SpecificCultures);
var length = cultures.Count();
foreach(var culture in cultures)
{
var cultureName = culture.Name;
#>
/// <summary>
/// <#=cultureName#>
/// </summary>
public const string <#=cultureName.Replace("-","_").ToUpper()#> = "<#=cultureName#>";

<#
}
#>
}
}


該 T4 Template 運行後會將所有可用的 Culture Name 彙整成一個靜態類別。

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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
namespace System.Globalization
{
public static class CultureNames
{
/// <summary>
/// ar-SA
/// </summary>
public const string AR_SA = "ar-SA";

/// <summary>
/// bg-BG
/// </summary>
public const string BG_BG = "bg-BG";

/// <summary>
/// ca-ES
/// </summary>
public const string CA_ES = "ca-ES";

/// <summary>
/// zh-TW
/// </summary>
public const string ZH_TW = "zh-TW";

/// <summary>
/// cs-CZ
/// </summary>
public const string CS_CZ = "cs-CZ";

/// <summary>
/// da-DK
/// </summary>
public const string DA_DK = "da-DK";

/// <summary>
/// de-DE
/// </summary>
public const string DE_DE = "de-DE";

/// <summary>
/// el-GR
/// </summary>
public const string EL_GR = "el-GR";

/// <summary>
/// en-US
/// </summary>
public const string EN_US = "en-US";

/// <summary>
/// fi-FI
/// </summary>
public const string FI_FI = "fi-FI";

/// <summary>
/// fr-FR
/// </summary>
public const string FR_FR = "fr-FR";

/// <summary>
/// he-IL
/// </summary>
public const string HE_IL = "he-IL";

/// <summary>
/// hu-HU
/// </summary>
public const string HU_HU = "hu-HU";

/// <summary>
/// is-IS
/// </summary>
public const string IS_IS = "is-IS";

/// <summary>
/// it-IT
/// </summary>
public const string IT_IT = "it-IT";

/// <summary>
/// ja-JP
/// </summary>
public const string JA_JP = "ja-JP";

/// <summary>
/// ko-KR
/// </summary>
public const string KO_KR = "ko-KR";

/// <summary>
/// nl-NL
/// </summary>
public const string NL_NL = "nl-NL";

/// <summary>
/// nb-NO
/// </summary>
public const string NB_NO = "nb-NO";

/// <summary>
/// pl-PL
/// </summary>
public const string PL_PL = "pl-PL";

/// <summary>
/// pt-BR
/// </summary>
public const string PT_BR = "pt-BR";

/// <summary>
/// rm-CH
/// </summary>
public const string RM_CH = "rm-CH";

/// <summary>
/// ro-RO
/// </summary>
public const string RO_RO = "ro-RO";

/// <summary>
/// ru-RU
/// </summary>
public const string RU_RU = "ru-RU";

/// <summary>
/// hr-HR
/// </summary>
public const string HR_HR = "hr-HR";

/// <summary>
/// sk-SK
/// </summary>
public const string SK_SK = "sk-SK";

/// <summary>
/// sq-AL
/// </summary>
public const string SQ_AL = "sq-AL";

/// <summary>
/// sv-SE
/// </summary>
public const string SV_SE = "sv-SE";

/// <summary>
/// th-TH
/// </summary>
public const string TH_TH = "th-TH";

/// <summary>
/// tr-TR
/// </summary>
public const string TR_TR = "tr-TR";

/// <summary>
/// ur-PK
/// </summary>
public const string UR_PK = "ur-PK";

/// <summary>
/// id-ID
/// </summary>
public const string ID_ID = "id-ID";

/// <summary>
/// uk-UA
/// </summary>
public const string UK_UA = "uk-UA";

/// <summary>
/// be-BY
/// </summary>
public const string BE_BY = "be-BY";

/// <summary>
/// sl-SI
/// </summary>
public const string SL_SI = "sl-SI";

/// <summary>
/// et-EE
/// </summary>
public const string ET_EE = "et-EE";

/// <summary>
/// lv-LV
/// </summary>
public const string LV_LV = "lv-LV";

/// <summary>
/// lt-LT
/// </summary>
public const string LT_LT = "lt-LT";

/// <summary>
/// tg-Cyrl-TJ
/// </summary>
public const string TG_CYRL_TJ = "tg-Cyrl-TJ";

/// <summary>
/// fa-IR
/// </summary>
public const string FA_IR = "fa-IR";

/// <summary>
/// vi-VN
/// </summary>
public const string VI_VN = "vi-VN";

/// <summary>
/// hy-AM
/// </summary>
public const string HY_AM = "hy-AM";

/// <summary>
/// az-Latn-AZ
/// </summary>
public const string AZ_LATN_AZ = "az-Latn-AZ";

/// <summary>
/// eu-ES
/// </summary>
public const string EU_ES = "eu-ES";

/// <summary>
/// hsb-DE
/// </summary>
public const string HSB_DE = "hsb-DE";

/// <summary>
/// mk-MK
/// </summary>
public const string MK_MK = "mk-MK";

/// <summary>
/// tn-ZA
/// </summary>
public const string TN_ZA = "tn-ZA";

/// <summary>
/// xh-ZA
/// </summary>
public const string XH_ZA = "xh-ZA";

/// <summary>
/// zu-ZA
/// </summary>
public const string ZU_ZA = "zu-ZA";

/// <summary>
/// af-ZA
/// </summary>
public const string AF_ZA = "af-ZA";

/// <summary>
/// ka-GE
/// </summary>
public const string KA_GE = "ka-GE";

/// <summary>
/// fo-FO
/// </summary>
public const string FO_FO = "fo-FO";

/// <summary>
/// hi-IN
/// </summary>
public const string HI_IN = "hi-IN";

/// <summary>
/// mt-MT
/// </summary>
public const string MT_MT = "mt-MT";

/// <summary>
/// se-NO
/// </summary>
public const string SE_NO = "se-NO";

/// <summary>
/// ms-MY
/// </summary>
public const string MS_MY = "ms-MY";

/// <summary>
/// kk-KZ
/// </summary>
public const string KK_KZ = "kk-KZ";

/// <summary>
/// ky-KG
/// </summary>
public const string KY_KG = "ky-KG";

/// <summary>
/// sw-KE
/// </summary>
public const string SW_KE = "sw-KE";

/// <summary>
/// tk-TM
/// </summary>
public const string TK_TM = "tk-TM";

/// <summary>
/// uz-Latn-UZ
/// </summary>
public const string UZ_LATN_UZ = "uz-Latn-UZ";

/// <summary>
/// tt-RU
/// </summary>
public const string TT_RU = "tt-RU";

/// <summary>
/// bn-IN
/// </summary>
public const string BN_IN = "bn-IN";

/// <summary>
/// pa-IN
/// </summary>
public const string PA_IN = "pa-IN";

/// <summary>
/// gu-IN
/// </summary>
public const string GU_IN = "gu-IN";

/// <summary>
/// or-IN
/// </summary>
public const string OR_IN = "or-IN";

/// <summary>
/// ta-IN
/// </summary>
public const string TA_IN = "ta-IN";

/// <summary>
/// te-IN
/// </summary>
public const string TE_IN = "te-IN";

/// <summary>
/// kn-IN
/// </summary>
public const string KN_IN = "kn-IN";

/// <summary>
/// ml-IN
/// </summary>
public const string ML_IN = "ml-IN";

/// <summary>
/// as-IN
/// </summary>
public const string AS_IN = "as-IN";

/// <summary>
/// mr-IN
/// </summary>
public const string MR_IN = "mr-IN";

/// <summary>
/// sa-IN
/// </summary>
public const string SA_IN = "sa-IN";

/// <summary>
/// mn-MN
/// </summary>
public const string MN_MN = "mn-MN";

/// <summary>
/// bo-CN
/// </summary>
public const string BO_CN = "bo-CN";

/// <summary>
/// cy-GB
/// </summary>
public const string CY_GB = "cy-GB";

/// <summary>
/// km-KH
/// </summary>
public const string KM_KH = "km-KH";

/// <summary>
/// lo-LA
/// </summary>
public const string LO_LA = "lo-LA";

/// <summary>
/// gl-ES
/// </summary>
public const string GL_ES = "gl-ES";

/// <summary>
/// kok-IN
/// </summary>
public const string KOK_IN = "kok-IN";

/// <summary>
/// syr-SY
/// </summary>
public const string SYR_SY = "syr-SY";

/// <summary>
/// si-LK
/// </summary>
public const string SI_LK = "si-LK";

/// <summary>
/// iu-Cans-CA
/// </summary>
public const string IU_CANS_CA = "iu-Cans-CA";

/// <summary>
/// am-ET
/// </summary>
public const string AM_ET = "am-ET";

/// <summary>
/// ne-NP
/// </summary>
public const string NE_NP = "ne-NP";

/// <summary>
/// fy-NL
/// </summary>
public const string FY_NL = "fy-NL";

/// <summary>
/// ps-AF
/// </summary>
public const string PS_AF = "ps-AF";

/// <summary>
/// fil-PH
/// </summary>
public const string FIL_PH = "fil-PH";

/// <summary>
/// dv-MV
/// </summary>
public const string DV_MV = "dv-MV";

/// <summary>
/// ha-Latn-NG
/// </summary>
public const string HA_LATN_NG = "ha-Latn-NG";

/// <summary>
/// yo-NG
/// </summary>
public const string YO_NG = "yo-NG";

/// <summary>
/// quz-BO
/// </summary>
public const string QUZ_BO = "quz-BO";

/// <summary>
/// nso-ZA
/// </summary>
public const string NSO_ZA = "nso-ZA";

/// <summary>
/// ba-RU
/// </summary>
public const string BA_RU = "ba-RU";

/// <summary>
/// lb-LU
/// </summary>
public const string LB_LU = "lb-LU";

/// <summary>
/// kl-GL
/// </summary>
public const string KL_GL = "kl-GL";

/// <summary>
/// ig-NG
/// </summary>
public const string IG_NG = "ig-NG";

/// <summary>
/// ii-CN
/// </summary>
public const string II_CN = "ii-CN";

/// <summary>
/// arn-CL
/// </summary>
public const string ARN_CL = "arn-CL";

/// <summary>
/// moh-CA
/// </summary>
public const string MOH_CA = "moh-CA";

/// <summary>
/// br-FR
/// </summary>
public const string BR_FR = "br-FR";

/// <summary>
/// ug-CN
/// </summary>
public const string UG_CN = "ug-CN";

/// <summary>
/// mi-NZ
/// </summary>
public const string MI_NZ = "mi-NZ";

/// <summary>
/// oc-FR
/// </summary>
public const string OC_FR = "oc-FR";

/// <summary>
/// co-FR
/// </summary>
public const string CO_FR = "co-FR";

/// <summary>
/// gsw-FR
/// </summary>
public const string GSW_FR = "gsw-FR";

/// <summary>
/// sah-RU
/// </summary>
public const string SAH_RU = "sah-RU";

/// <summary>
/// qut-GT
/// </summary>
public const string QUT_GT = "qut-GT";

/// <summary>
/// rw-RW
/// </summary>
public const string RW_RW = "rw-RW";

/// <summary>
/// wo-SN
/// </summary>
public const string WO_SN = "wo-SN";

/// <summary>
/// prs-AF
/// </summary>
public const string PRS_AF = "prs-AF";

/// <summary>
/// gd-GB
/// </summary>
public const string GD_GB = "gd-GB";

/// <summary>
/// ar-IQ
/// </summary>
public const string AR_IQ = "ar-IQ";

/// <summary>
/// zh-CN
/// </summary>
public const string ZH_CN = "zh-CN";

/// <summary>
/// de-CH
/// </summary>
public const string DE_CH = "de-CH";

/// <summary>
/// en-GB
/// </summary>
public const string EN_GB = "en-GB";

/// <summary>
/// es-MX
/// </summary>
public const string ES_MX = "es-MX";

/// <summary>
/// fr-BE
/// </summary>
public const string FR_BE = "fr-BE";

/// <summary>
/// it-CH
/// </summary>
public const string IT_CH = "it-CH";

/// <summary>
/// nl-BE
/// </summary>
public const string NL_BE = "nl-BE";

/// <summary>
/// nn-NO
/// </summary>
public const string NN_NO = "nn-NO";

/// <summary>
/// pt-PT
/// </summary>
public const string PT_PT = "pt-PT";

/// <summary>
/// sr-Latn-CS
/// </summary>
public const string SR_LATN_CS = "sr-Latn-CS";

/// <summary>
/// sv-FI
/// </summary>
public const string SV_FI = "sv-FI";

/// <summary>
/// az-Cyrl-AZ
/// </summary>
public const string AZ_CYRL_AZ = "az-Cyrl-AZ";

/// <summary>
/// dsb-DE
/// </summary>
public const string DSB_DE = "dsb-DE";

/// <summary>
/// se-SE
/// </summary>
public const string SE_SE = "se-SE";

/// <summary>
/// ga-IE
/// </summary>
public const string GA_IE = "ga-IE";

/// <summary>
/// ms-BN
/// </summary>
public const string MS_BN = "ms-BN";

/// <summary>
/// uz-Cyrl-UZ
/// </summary>
public const string UZ_CYRL_UZ = "uz-Cyrl-UZ";

/// <summary>
/// bn-BD
/// </summary>
public const string BN_BD = "bn-BD";

/// <summary>
/// mn-Mong-CN
/// </summary>
public const string MN_MONG_CN = "mn-Mong-CN";

/// <summary>
/// iu-Latn-CA
/// </summary>
public const string IU_LATN_CA = "iu-Latn-CA";

/// <summary>
/// tzm-Latn-DZ
/// </summary>
public const string TZM_LATN_DZ = "tzm-Latn-DZ";

/// <summary>
/// quz-EC
/// </summary>
public const string QUZ_EC = "quz-EC";

/// <summary>
/// ar-EG
/// </summary>
public const string AR_EG = "ar-EG";

/// <summary>
/// zh-HK
/// </summary>
public const string ZH_HK = "zh-HK";

/// <summary>
/// de-AT
/// </summary>
public const string DE_AT = "de-AT";

/// <summary>
/// en-AU
/// </summary>
public const string EN_AU = "en-AU";

/// <summary>
/// es-ES
/// </summary>
public const string ES_ES = "es-ES";

/// <summary>
/// fr-CA
/// </summary>
public const string FR_CA = "fr-CA";

/// <summary>
/// sr-Cyrl-CS
/// </summary>
public const string SR_CYRL_CS = "sr-Cyrl-CS";

/// <summary>
/// se-FI
/// </summary>
public const string SE_FI = "se-FI";

/// <summary>
/// quz-PE
/// </summary>
public const string QUZ_PE = "quz-PE";

/// <summary>
/// ar-LY
/// </summary>
public const string AR_LY = "ar-LY";

/// <summary>
/// zh-SG
/// </summary>
public const string ZH_SG = "zh-SG";

/// <summary>
/// de-LU
/// </summary>
public const string DE_LU = "de-LU";

/// <summary>
/// en-CA
/// </summary>
public const string EN_CA = "en-CA";

/// <summary>
/// es-GT
/// </summary>
public const string ES_GT = "es-GT";

/// <summary>
/// fr-CH
/// </summary>
public const string FR_CH = "fr-CH";

/// <summary>
/// hr-BA
/// </summary>
public const string HR_BA = "hr-BA";

/// <summary>
/// smj-NO
/// </summary>
public const string SMJ_NO = "smj-NO";

/// <summary>
/// ar-DZ
/// </summary>
public const string AR_DZ = "ar-DZ";

/// <summary>
/// zh-MO
/// </summary>
public const string ZH_MO = "zh-MO";

/// <summary>
/// de-LI
/// </summary>
public const string DE_LI = "de-LI";

/// <summary>
/// en-NZ
/// </summary>
public const string EN_NZ = "en-NZ";

/// <summary>
/// es-CR
/// </summary>
public const string ES_CR = "es-CR";

/// <summary>
/// fr-LU
/// </summary>
public const string FR_LU = "fr-LU";

/// <summary>
/// bs-Latn-BA
/// </summary>
public const string BS_LATN_BA = "bs-Latn-BA";

/// <summary>
/// smj-SE
/// </summary>
public const string SMJ_SE = "smj-SE";

/// <summary>
/// ar-MA
/// </summary>
public const string AR_MA = "ar-MA";

/// <summary>
/// en-IE
/// </summary>
public const string EN_IE = "en-IE";

/// <summary>
/// es-PA
/// </summary>
public const string ES_PA = "es-PA";

/// <summary>
/// fr-MC
/// </summary>
public const string FR_MC = "fr-MC";

/// <summary>
/// sr-Latn-BA
/// </summary>
public const string SR_LATN_BA = "sr-Latn-BA";

/// <summary>
/// sma-NO
/// </summary>
public const string SMA_NO = "sma-NO";

/// <summary>
/// ar-TN
/// </summary>
public const string AR_TN = "ar-TN";

/// <summary>
/// en-ZA
/// </summary>
public const string EN_ZA = "en-ZA";

/// <summary>
/// es-DO
/// </summary>
public const string ES_DO = "es-DO";

/// <summary>
/// sr-Cyrl-BA
/// </summary>
public const string SR_CYRL_BA = "sr-Cyrl-BA";

/// <summary>
/// sma-SE
/// </summary>
public const string SMA_SE = "sma-SE";

/// <summary>
/// ar-OM
/// </summary>
public const string AR_OM = "ar-OM";

/// <summary>
/// en-JM
/// </summary>
public const string EN_JM = "en-JM";

/// <summary>
/// es-VE
/// </summary>
public const string ES_VE = "es-VE";

/// <summary>
/// bs-Cyrl-BA
/// </summary>
public const string BS_CYRL_BA = "bs-Cyrl-BA";

/// <summary>
/// sms-FI
/// </summary>
public const string SMS_FI = "sms-FI";

/// <summary>
/// ar-YE
/// </summary>
public const string AR_YE = "ar-YE";

/// <summary>
/// en-029
/// </summary>
public const string EN_029 = "en-029";

/// <summary>
/// es-CO
/// </summary>
public const string ES_CO = "es-CO";

/// <summary>
/// sr-Latn-RS
/// </summary>
public const string SR_LATN_RS = "sr-Latn-RS";

/// <summary>
/// smn-FI
/// </summary>
public const string SMN_FI = "smn-FI";

/// <summary>
/// ar-SY
/// </summary>
public const string AR_SY = "ar-SY";

/// <summary>
/// en-BZ
/// </summary>
public const string EN_BZ = "en-BZ";

/// <summary>
/// es-PE
/// </summary>
public const string ES_PE = "es-PE";

/// <summary>
/// sr-Cyrl-RS
/// </summary>
public const string SR_CYRL_RS = "sr-Cyrl-RS";

/// <summary>
/// ar-JO
/// </summary>
public const string AR_JO = "ar-JO";

/// <summary>
/// en-TT
/// </summary>
public const string EN_TT = "en-TT";

/// <summary>
/// es-AR
/// </summary>
public const string ES_AR = "es-AR";

/// <summary>
/// sr-Latn-ME
/// </summary>
public const string SR_LATN_ME = "sr-Latn-ME";

/// <summary>
/// ar-LB
/// </summary>
public const string AR_LB = "ar-LB";

/// <summary>
/// en-ZW
/// </summary>
public const string EN_ZW = "en-ZW";

/// <summary>
/// es-EC
/// </summary>
public const string ES_EC = "es-EC";

/// <summary>
/// sr-Cyrl-ME
/// </summary>
public const string SR_CYRL_ME = "sr-Cyrl-ME";

/// <summary>
/// ar-KW
/// </summary>
public const string AR_KW = "ar-KW";

/// <summary>
/// en-PH
/// </summary>
public const string EN_PH = "en-PH";

/// <summary>
/// es-CL
/// </summary>
public const string ES_CL = "es-CL";

/// <summary>
/// ar-AE
/// </summary>
public const string AR_AE = "ar-AE";

/// <summary>
/// es-UY
/// </summary>
public const string ES_UY = "es-UY";

/// <summary>
/// ar-BH
/// </summary>
public const string AR_BH = "ar-BH";

/// <summary>
/// es-PY
/// </summary>
public const string ES_PY = "es-PY";

/// <summary>
/// ar-QA
/// </summary>
public const string AR_QA = "ar-QA";

/// <summary>
/// en-IN
/// </summary>
public const string EN_IN = "en-IN";

/// <summary>
/// es-BO
/// </summary>
public const string ES_BO = "es-BO";

/// <summary>
/// en-MY
/// </summary>
public const string EN_MY = "en-MY";

/// <summary>
/// es-SV
/// </summary>
public const string ES_SV = "es-SV";

/// <summary>
/// en-SG
/// </summary>
public const string EN_SG = "en-SG";

/// <summary>
/// es-HN
/// </summary>
public const string ES_HN = "es-HN";

/// <summary>
/// es-NI
/// </summary>
public const string ES_NI = "es-NI";

/// <summary>
/// es-PR
/// </summary>
public const string ES_PR = "es-PR";

/// <summary>
/// es-US
/// </summary>
public const string ES_US = "es-US";

}
}


有了該靜態類別我們就可以將這部份的 Hard code 拿掉了。

1
2
3
4
5
6
...
var currentThread = Thread.CurrentThread;
currentThread.CurrentCulture = CultureInfo.GetCultureInfo(CultureNames.ZH_TW);

Console.WriteLine(currentThread.CurrentCulture.Name);
...