Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
CultureInfoConverter.cs
Go to the documentation of this file.
6
8
10{
11 private sealed class CultureComparer : IComparer
12 {
14
19
20 public int Compare(object item1, object item2)
21 {
22 if (item1 == null)
23 {
24 if (item2 == null)
25 {
26 return 0;
27 }
28 return -1;
29 }
30 if (item2 == null)
31 {
32 return 1;
33 }
34 string cultureName = _converter.GetCultureName((CultureInfo)item1);
37 return compareInfo.Compare(cultureName, cultureName2, CompareOptions.StringSort);
38 }
39 }
40
41 private static class CultureInfoMapper
42 {
44
46 {
47 return new Dictionary<string, string>(274)
48 {
49 { "Afrikaans", "af" },
50 { "Afrikaans (South Africa)", "af-ZA" },
51 { "Albanian", "sq" },
52 { "Albanian (Albania)", "sq-AL" },
53 { "Alsatian (France)", "gsw-FR" },
54 { "Amharic (Ethiopia)", "am-ET" },
55 { "Arabic", "ar" },
56 { "Arabic (Algeria)", "ar-DZ" },
57 { "Arabic (Bahrain)", "ar-BH" },
58 { "Arabic (Egypt)", "ar-EG" },
59 { "Arabic (Iraq)", "ar-IQ" },
60 { "Arabic (Jordan)", "ar-JO" },
61 { "Arabic (Kuwait)", "ar-KW" },
62 { "Arabic (Lebanon)", "ar-LB" },
63 { "Arabic (Libya)", "ar-LY" },
64 { "Arabic (Morocco)", "ar-MA" },
65 { "Arabic (Oman)", "ar-OM" },
66 { "Arabic (Qatar)", "ar-QA" },
67 { "Arabic (Saudi Arabia)", "ar-SA" },
68 { "Arabic (Syria)", "ar-SY" },
69 { "Arabic (Tunisia)", "ar-TN" },
70 { "Arabic (U.A.E.)", "ar-AE" },
71 { "Arabic (Yemen)", "ar-YE" },
72 { "Armenian", "hy" },
73 { "Armenian (Armenia)", "hy-AM" },
74 { "Assamese (India)", "as-IN" },
75 { "Azeri", "az" },
76 { "Azeri (Cyrillic, Azerbaijan)", "az-Cyrl-AZ" },
77 { "Azeri (Latin, Azerbaijan)", "az-Latn-AZ" },
78 { "Bashkir (Russia)", "ba-RU" },
79 { "Basque", "eu" },
80 { "Basque (Basque)", "eu-ES" },
81 { "Belarusian", "be" },
82 { "Belarusian (Belarus)", "be-BY" },
83 { "Bengali (Bangladesh)", "bn-BD" },
84 { "Bengali (India)", "bn-IN" },
85 { "Bosnian (Cyrillic, Bosnia and Herzegovina)", "bs-Cyrl-BA" },
86 { "Bosnian (Latin, Bosnia and Herzegovina)", "bs-Latn-BA" },
87 { "Breton (France)", "br-FR" },
88 { "Bulgarian", "bg" },
89 { "Bulgarian (Bulgaria)", "bg-BG" },
90 { "Catalan", "ca" },
91 { "Catalan (Catalan)", "ca-ES" },
92 { "Chinese (Hong Kong S.A.R.)", "zh-HK" },
93 { "Chinese (Macao S.A.R.)", "zh-MO" },
94 { "Chinese (People's Republic of China)", "zh-CN" },
95 { "Chinese (Simplified)", "zh-CHS" },
96 { "Chinese (Singapore)", "zh-SG" },
97 { "Chinese (Taiwan)", "zh-TW" },
98 { "Chinese (Traditional)", "zh-CHT" },
99 { "Corsican (France)", "co-FR" },
100 { "Croatian", "hr" },
101 { "Croatian (Croatia)", "hr-HR" },
102 { "Croatian (Latin, Bosnia and Herzegovina)", "hr-BA" },
103 { "Czech", "cs" },
104 { "Czech (Czech Republic)", "cs-CZ" },
105 { "Danish", "da" },
106 { "Danish (Denmark)", "da-DK" },
107 { "Dari (Afghanistan)", "prs-AF" },
108 { "Divehi", "dv" },
109 { "Divehi (Maldives)", "dv-MV" },
110 { "Dutch", "nl" },
111 { "Dutch (Belgium)", "nl-BE" },
112 { "Dutch (Netherlands)", "nl-NL" },
113 { "English", "en" },
114 { "English (Australia)", "en-AU" },
115 { "English (Belize)", "en-BZ" },
116 { "English (Canada)", "en-CA" },
117 { "English (Caribbean)", "en-029" },
118 { "English (India)", "en-IN" },
119 { "English (Ireland)", "en-IE" },
120 { "English (Jamaica)", "en-JM" },
121 { "English (Malaysia)", "en-MY" },
122 { "English (New Zealand)", "en-NZ" },
123 { "English (Republic of the Philippines)", "en-PH" },
124 { "English (Singapore)", "en-SG" },
125 { "English (South Africa)", "en-ZA" },
126 { "English (Trinidad and Tobago)", "en-TT" },
127 { "English (United Kingdom)", "en-GB" },
128 { "English (United States)", "en-US" },
129 { "English (Zimbabwe)", "en-ZW" },
130 { "Estonian", "et" },
131 { "Estonian (Estonia)", "et-EE" },
132 { "Faroese", "fo" },
133 { "Faroese (Faroe Islands)", "fo-FO" },
134 { "Filipino (Philippines)", "fil-PH" },
135 { "Finnish", "fi" },
136 { "Finnish (Finland)", "fi-FI" },
137 { "French", "fr" },
138 { "French (Belgium)", "fr-BE" },
139 { "French (Canada)", "fr-CA" },
140 { "French (France)", "fr-FR" },
141 { "French (Luxembourg)", "fr-LU" },
142 { "French (Principality of Monaco)", "fr-MC" },
143 { "French (Switzerland)", "fr-CH" },
144 { "Frisian (Netherlands)", "fy-NL" },
145 { "Galician", "gl" },
146 { "Galician (Galician)", "gl-ES" },
147 { "Georgian", "ka" },
148 { "Georgian (Georgia)", "ka-GE" },
149 { "German", "de" },
150 { "German (Austria)", "de-AT" },
151 { "German (Germany)", "de-DE" },
152 { "German (Liechtenstein)", "de-LI" },
153 { "German (Luxembourg)", "de-LU" },
154 { "German (Switzerland)", "de-CH" },
155 { "Greek", "el" },
156 { "Greek (Greece)", "el-GR" },
157 { "Greenlandic (Greenland)", "kl-GL" },
158 { "Gujarati", "gu" },
159 { "Gujarati (India)", "gu-IN" },
160 { "Hausa (Latin, Nigeria)", "ha-Latn-NG" },
161 { "Hebrew", "he" },
162 { "Hebrew (Israel)", "he-IL" },
163 { "Hindi", "hi" },
164 { "Hindi (India)", "hi-IN" },
165 { "Hungarian", "hu" },
166 { "Hungarian (Hungary)", "hu-HU" },
167 { "Icelandic", "is" },
168 { "Icelandic (Iceland)", "is-IS" },
169 { "Igbo (Nigeria)", "ig-NG" },
170 { "Indonesian", "id" },
171 { "Indonesian (Indonesia)", "id-ID" },
172 { "Inuktitut (Latin, Canada)", "iu-Latn-CA" },
173 { "Inuktitut (Syllabics, Canada)", "iu-Cans-CA" },
174 { "Invariant Language (Invariant Country)", "" },
175 { "Irish (Ireland)", "ga-IE" },
176 { "isiXhosa (South Africa)", "xh-ZA" },
177 { "isiZulu (South Africa)", "zu-ZA" },
178 { "Italian", "it" },
179 { "Italian (Italy)", "it-IT" },
180 { "Italian (Switzerland)", "it-CH" },
181 { "Japanese", "ja" },
182 { "Japanese (Japan)", "ja-JP" },
183 { "K'iche (Guatemala)", "qut-GT" },
184 { "Kannada", "kn" },
185 { "Kannada (India)", "kn-IN" },
186 { "Kazakh", "kk" },
187 { "Kazakh (Kazakhstan)", "kk-KZ" },
188 { "Khmer (Cambodia)", "km-KH" },
189 { "Kinyarwanda (Rwanda)", "rw-RW" },
190 { "Kiswahili", "sw" },
191 { "Kiswahili (Kenya)", "sw-KE" },
192 { "Konkani", "kok" },
193 { "Konkani (India)", "kok-IN" },
194 { "Korean", "ko" },
195 { "Korean (Korea)", "ko-KR" },
196 { "Kyrgyz", "ky" },
197 { "Kyrgyz (Kyrgyzstan)", "ky-KG" },
198 { "Lao (Lao P.D.R.)", "lo-LA" },
199 { "Latvian", "lv" },
200 { "Latvian (Latvia)", "lv-LV" },
201 { "Lithuanian", "lt" },
202 { "Lithuanian (Lithuania)", "lt-LT" },
203 { "Lower Sorbian (Germany)", "dsb-DE" },
204 { "Luxembourgish (Luxembourg)", "lb-LU" },
205 { "Macedonian", "mk" },
206 { "Macedonian (North Macedonia)", "mk-MK" },
207 { "Malay", "ms" },
208 { "Malay (Brunei Darussalam)", "ms-BN" },
209 { "Malay (Malaysia)", "ms-MY" },
210 { "Malayalam (India)", "ml-IN" },
211 { "Maltese (Malta)", "mt-MT" },
212 { "Maori (New Zealand)", "mi-NZ" },
213 { "Mapudungun (Chile)", "arn-CL" },
214 { "Marathi", "mr" },
215 { "Marathi (India)", "mr-IN" },
216 { "Mohawk (Mohawk)", "moh-CA" },
217 { "Mongolian", "mn" },
218 { "Mongolian (Cyrillic, Mongolia)", "mn-MN" },
219 { "Mongolian (Traditional Mongolian, PRC)", "mn-Mong-CN" },
220 { "Nepali (Nepal)", "ne-NP" },
221 { "Norwegian", "no" },
222 { "Norwegian, Bokmål (Norway)", "nb-NO" },
223 { "Norwegian, Nynorsk (Norway)", "nn-NO" },
224 { "Occitan (France)", "oc-FR" },
225 { "Oriya (India)", "or-IN" },
226 { "Pashto (Afghanistan)", "ps-AF" },
227 { "Persian", "fa" },
228 { "Persian (Iran)", "fa-IR" },
229 { "Polish", "pl" },
230 { "Polish (Poland)", "pl-PL" },
231 { "Portuguese", "pt" },
232 { "Portuguese (Brazil)", "pt-BR" },
233 { "Portuguese (Portugal)", "pt-PT" },
234 { "Punjabi", "pa" },
235 { "Punjabi (India)", "pa-IN" },
236 { "Quechua (Bolivia)", "quz-BO" },
237 { "Quechua (Ecuador)", "quz-EC" },
238 { "Quechua (Peru)", "quz-PE" },
239 { "Romanian", "ro" },
240 { "Romanian (Romania)", "ro-RO" },
241 { "Romansh (Switzerland)", "rm-CH" },
242 { "Russian", "ru" },
243 { "Russian (Russia)", "ru-RU" },
244 { "Sami, Inari (Finland)", "smn-FI" },
245 { "Sami, Lule (Norway)", "smj-NO" },
246 { "Sami, Lule (Sweden)", "smj-SE" },
247 { "Sami, Northern (Finland)", "se-FI" },
248 { "Sami, Northern (Norway)", "se-NO" },
249 { "Sami, Northern (Sweden)", "se-SE" },
250 { "Sami, Skolt (Finland)", "sms-FI" },
251 { "Sami, Southern (Norway)", "sma-NO" },
252 { "Sami, Southern (Sweden)", "sma-SE" },
253 { "Sanskrit", "sa" },
254 { "Sanskrit (India)", "sa-IN" },
255 { "Serbian", "sr" },
256 { "Serbian (Cyrillic, Bosnia and Herzegovina)", "sr-Cyrl-BA" },
257 { "Serbian (Cyrillic, Serbia)", "sr-Cyrl-CS" },
258 { "Serbian (Latin, Bosnia and Herzegovina)", "sr-Latn-BA" },
259 { "Serbian (Latin, Serbia)", "sr-Latn-CS" },
260 { "Sesotho sa Leboa (South Africa)", "nso-ZA" },
261 { "Setswana (South Africa)", "tn-ZA" },
262 { "Sinhala (Sri Lanka)", "si-LK" },
263 { "Slovak", "sk" },
264 { "Slovak (Slovakia)", "sk-SK" },
265 { "Slovenian", "sl" },
266 { "Slovenian (Slovenia)", "sl-SI" },
267 { "Spanish", "es" },
268 { "Spanish (Argentina)", "es-AR" },
269 { "Spanish (Bolivia)", "es-BO" },
270 { "Spanish (Chile)", "es-CL" },
271 { "Spanish (Colombia)", "es-CO" },
272 { "Spanish (Costa Rica)", "es-CR" },
273 { "Spanish (Dominican Republic)", "es-DO" },
274 { "Spanish (Ecuador)", "es-EC" },
275 { "Spanish (El Salvador)", "es-SV" },
276 { "Spanish (Guatemala)", "es-GT" },
277 { "Spanish (Honduras)", "es-HN" },
278 { "Spanish (Mexico)", "es-MX" },
279 { "Spanish (Nicaragua)", "es-NI" },
280 { "Spanish (Panama)", "es-PA" },
281 { "Spanish (Paraguay)", "es-PY" },
282 { "Spanish (Peru)", "es-PE" },
283 { "Spanish (Puerto Rico)", "es-PR" },
284 { "Spanish (Spain)", "es-ES" },
285 { "Spanish (United States)", "es-US" },
286 { "Spanish (Uruguay)", "es-UY" },
287 { "Spanish (Venezuela)", "es-VE" },
288 { "Swedish", "sv" },
289 { "Swedish (Finland)", "sv-FI" },
290 { "Swedish (Sweden)", "sv-SE" },
291 { "Syriac", "syr" },
292 { "Syriac (Syria)", "syr-SY" },
293 { "Tajik (Cyrillic, Tajikistan)", "tg-Cyrl-TJ" },
294 { "Tamazight (Latin, Algeria)", "tzm-Latn-DZ" },
295 { "Tamil", "ta" },
296 { "Tamil (India)", "ta-IN" },
297 { "Tatar", "tt" },
298 { "Tatar (Russia)", "tt-RU" },
299 { "Telugu", "te" },
300 { "Telugu (India)", "te-IN" },
301 { "Thai", "th" },
302 { "Thai (Thailand)", "th-TH" },
303 { "Tibetan (PRC)", "bo-CN" },
304 { "Turkish", "tr" },
305 { "Turkish (Turkey)", "tr-TR" },
306 { "Turkmen (Turkmenistan)", "tk-TM" },
307 { "Uighur (PRC)", "ug-CN" },
308 { "Ukrainian", "uk" },
309 { "Ukrainian (Ukraine)", "uk-UA" },
310 { "Upper Sorbian (Germany)", "hsb-DE" },
311 { "Urdu", "ur" },
312 { "Urdu (Islamic Republic of Pakistan)", "ur-PK" },
313 { "Uzbek", "uz" },
314 { "Uzbek (Cyrillic, Uzbekistan)", "uz-Cyrl-UZ" },
315 { "Uzbek (Latin, Uzbekistan)", "uz-Latn-UZ" },
316 { "Vietnamese", "vi" },
317 { "Vietnamese (Vietnam)", "vi-VN" },
318 { "Welsh (United Kingdom)", "cy-GB" },
319 { "Wolof (Senegal)", "wo-SN" },
320 { "Yakut (Russia)", "sah-RU" },
321 { "Yi (PRC)", "ii-CN" },
322 { "Yoruba (Nigeria)", "yo-NG" }
323 };
324 }
325
326 public static string GetCultureInfoName(string cultureInfoDisplayName)
327 {
329 {
331 }
332 return value;
333 }
334 }
335
337
339
340 protected virtual string GetCultureName(CultureInfo culture)
341 {
342 if (culture == null)
343 {
344 throw new ArgumentNullException("culture");
345 }
346 return culture.Name;
347 }
348
349 public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType)
350 {
351 if (!(sourceType == typeof(string)))
352 {
353 return base.CanConvertFrom(context, sourceType);
354 }
355 return true;
356 }
357
359 {
361 {
362 return base.CanConvertTo(context, destinationType);
363 }
364 return true;
365 }
366
367 public override object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value)
368 {
369 string text = value as string;
370 if (text != null)
371 {
372 if (GetCultureName(CultureInfo.InvariantCulture).Equals(string.Empty))
373 {
375 }
376 string b = DefaultCultureString;
377 if (culture != null && culture.Equals(CultureInfo.InvariantCulture))
378 {
379 b = "(Default)";
380 }
382 if (string.IsNullOrEmpty(text) || string.Equals(text, b, StringComparison.Ordinal))
383 {
385 }
386 if (cultureInfo == null)
387 {
388 foreach (CultureInfo standardValue in GetStandardValues(context))
389 {
390 if (standardValue != null && string.Equals(GetCultureName(standardValue), text, StringComparison.Ordinal))
391 {
393 break;
394 }
395 }
396 }
397 if (cultureInfo == null)
398 {
399 try
400 {
402 }
403 catch
404 {
405 }
406 }
407 if (cultureInfo == null)
408 {
409 foreach (CultureInfo value2 in _values)
410 {
411 if (value2 != null && GetCultureName(value2).StartsWith(text, StringComparison.CurrentCulture))
412 {
414 break;
415 }
416 }
417 }
418 if (cultureInfo == null)
419 {
421 }
422 return cultureInfo;
423 }
424 return base.ConvertFrom(context, culture, value);
425 }
426
427 public override object? ConvertTo(ITypeDescriptorContext? context, CultureInfo? culture, object? value, Type destinationType)
428 {
429 if (destinationType == typeof(string))
430 {
431 string result = DefaultCultureString;
432 if (culture != null && culture.Equals(CultureInfo.InvariantCulture))
433 {
434 result = "(Default)";
435 }
436 if (value == null || value == CultureInfo.InvariantCulture)
437 {
438 return result;
439 }
441 {
442 return GetCultureName(culture2);
443 }
444 }
446 {
447 return new InstanceDescriptor(typeof(CultureInfo).GetConstructor(new Type[1] { typeof(string) }), new object[1] { cultureInfo.Name });
448 }
449 return base.ConvertTo(context, culture, value, destinationType);
450 }
451
452 [MemberNotNull("_values")]
454 {
455 if (_values == null)
456 {
457 CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.NeutralCultures | CultureTypes.SpecificCultures);
460 if (num != -1)
461 {
462 cultures[num] = null;
463 array = new CultureInfo[cultures.Length];
464 }
465 else
466 {
467 array = new CultureInfo[cultures.Length + 1];
468 }
469 Array.Copy(cultures, array, cultures.Length);
470 Array.Sort(array, new CultureComparer(this));
471 if (array[0] == null)
472 {
474 }
476 }
477 return _values;
478 }
479
481 {
482 return false;
483 }
484
486 {
487 return true;
488 }
489}
static void Sort(Array array)
Definition Array.cs:2329
int IList. IndexOf(object value)
Definition Array.cs:1228
static unsafe void Copy(Array sourceArray, Array destinationArray, int length)
Definition Array.cs:624
static readonly Dictionary< string, string > s_cultureInfoNameMap
static string GetCultureInfoName(string cultureInfoDisplayName)
override bool GetStandardValuesExclusive(ITypeDescriptorContext? context)
virtual string GetCultureName(CultureInfo culture)
override bool GetStandardValuesSupported(ITypeDescriptorContext? context)
override bool CanConvertTo(ITypeDescriptorContext? context, Type? destinationType)
override? object ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value)
override? object ConvertTo(ITypeDescriptorContext? context, CultureInfo? culture, object? value, Type destinationType)
override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType)
override StandardValuesCollection GetStandardValues(ITypeDescriptorContext? context)
static CultureInfo[] GetCultures(CultureTypes types)
static CultureInfo CurrentCulture
static CultureInfo InvariantCulture
static string CultureInfoConverterInvalidCulture
Definition SR.cs:78
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string CultureInfoConverterDefaultCultureString
Definition SR.cs:76
Definition SR.cs:7