2 // System.Globalization.CultureInfo.cs
5 // Miguel de Icaza (miguel@ximian.com)
6 // Dick Porter (dick@ximian.com)
7 // Marek Safar (marek.safar@gmail.com)
9 // (C) 2001, 2002, 2003 Ximian, Inc. (http://www.ximian.com)
10 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
11 // Copyright (C) 2012 Xamarin Inc (http://www.xamarin.com)
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System.Collections.Generic;
34 using System.Threading;
35 using System.Runtime.CompilerServices;
36 using System.Runtime.InteropServices;
37 using System.Diagnostics.Contracts;
39 namespace System.Globalization
41 [System.Runtime.InteropServices.ComVisible (true)]
43 [StructLayout (LayoutKind.Sequential)]
44 public class CultureInfo : ICloneable, IFormatProvider
46 static volatile CultureInfo invariant_culture_info = new CultureInfo (InvariantCultureId, false, true);
47 static object shared_table_lock = new object ();
48 static CultureInfo default_current_culture;
50 #pragma warning disable 169, 649
60 int default_calendar_type;
61 bool m_useUserOverride;
63 internal volatile NumberFormatInfo numInfo;
64 internal volatile DateTimeFormatInfo dateTimeInfo;
65 volatile TextInfo textInfo;
66 internal string m_name;
69 private string englishname;
71 private string nativename;
73 private string iso3lang;
75 private string iso2lang;
77 private string win3lang;
79 private string territory;
81 string[] native_calendar_names;
83 volatile CompareInfo compareInfo;
85 private unsafe readonly void *textinfo_data;
87 [StructLayout (LayoutKind.Sequential)]
93 public bool right_to_left;
97 int m_dataItem; // MS.NET serializes this.
98 #pragma warning restore 169, 649
103 CultureInfo parent_culture;
105 // Deserialized instances will set this to false
110 // Used by Thread.set_CurrentCulture
111 internal byte[] cached_serialized_form;
113 [NonSerialized]internal CultureData m_cultureData;
114 [NonSerialized]internal bool m_isInherited;
116 internal const int InvariantCultureId = 0x7F;
117 const int CalendarTypeBits = 8;
119 const string MSG_READONLY = "This instance is read only";
121 public static CultureInfo InvariantCulture {
123 return invariant_culture_info;
127 public static CultureInfo CurrentCulture {
129 return Thread.CurrentThread.CurrentCulture;
133 public static CultureInfo CurrentUICulture {
135 return Thread.CurrentThread.CurrentUICulture;
139 internal static CultureInfo ConstructCurrentCulture ()
141 if (default_current_culture != null)
142 return default_current_culture;
144 var locale_name = get_current_locale_name ();
145 CultureInfo ci = null;
147 if (locale_name != null) {
149 ci = CreateSpecificCulture (locale_name);
155 ci = InvariantCulture;
157 ci.m_isReadOnly = true;
158 ci.m_useUserOverride = true;
161 default_current_culture = ci;
165 internal static CultureInfo ConstructCurrentUICulture ()
167 return ConstructCurrentCulture ();
170 // it is used for RegionInfo.
171 internal string Territory {
172 get { return territory; }
176 // FIXME: It is implemented, but would be hell slow.
178 public CultureTypes CultureTypes {
180 CultureTypes ret = (CultureTypes) 0;
181 foreach (CultureTypes v in Enum.GetValues (typeof (CultureTypes)))
182 if (Array.IndexOf (GetCultures (v), this) >= 0)
189 public CultureInfo GetConsoleFallbackUICulture ()
191 // as documented in MSDN ...
193 case "ar": case "ar-BH": case "ar-EG": case "ar-IQ":
194 case "ar-JO": case "ar-KW": case "ar-LB": case "ar-LY":
195 case "ar-QA": case "ar-SA": case "ar-SY": case "ar-AE":
197 case "dv": case "dv-MV":
198 case "fa": case "fa-IR":
199 case "gu": case "gu-IN":
200 case "he": case "he-IL":
201 case "hi": case "hi-IN":
202 case "kn": case "kn-IN":
203 case "kok": case "kok-IN":
204 case "mr": case "mr-IN":
205 case "pa": case "pa-IN":
206 case "sa": case "sa-IN":
207 case "syr": case "syr-SY":
208 case "ta": case "ta-IN":
209 case "te": case "te-IN":
210 case "th": case "th-TH":
211 case "ur": case "ur-PK":
212 case "vi": case "vi-VN":
213 return GetCultureInfo ("en");
214 case "ar-DZ": case "ar-MA": case "ar-TN":
215 return GetCultureInfo ("fr");
217 return (CultureTypes & CultureTypes.WindowsOnlyCultures) != 0 ? CultureInfo.InvariantCulture : this;
221 public string IetfLanguageTag {
222 // There could be more consistent way to implement
223 // it, but right now it works just fine with this...
236 // For specific cultures it basically returns LCID.
237 // For neutral cultures it is mapped to the default(?) specific
238 // culture, where the LCID of the specific culture seems to be
239 // n + 1024 by default. zh-CHS is the only exception which is
240 // mapped to 2052, not 1028 (zh-CHT is mapped to 1028 instead).
241 // There are very few exceptions, here I simply list them here.
242 // It is Windows-specific property anyways, so no worthy of
243 // trying to do some complex things with locale-builder.
245 public virtual int KeyboardLayoutId {
248 case 4: // zh-CHS (neutral)
250 case 1034: // es-ES Spanish 2
252 case 31748: // zh-CHT (neutral)
254 case 31770: // sr (neutral)
257 return LCID < 1024 ? LCID + 1024 : LCID;
263 public virtual int LCID {
269 public virtual string Name {
275 public virtual string NativeName {
277 if (!constructed) Construct ();
282 internal string NativeCalendarName {
284 if (!constructed) Construct ();
285 return native_calendar_names[(default_calendar_type >> CalendarTypeBits) - 1];
289 public virtual Calendar Calendar {
291 if (calendar == null) {
292 if (!constructed) Construct ();
293 calendar = CreateCalendar (default_calendar_type);
300 [MonoLimitation ("Optional calendars are not supported only default calendar is returned")]
301 public virtual Calendar[] OptionalCalendars {
303 return new[] { Calendar };
307 public virtual CultureInfo Parent
310 if (parent_culture == null) {
313 if (parent_lcid == cultureID) {
315 // Parent lcid is same but culture info is not for legacy zh culture
317 if (parent_lcid == 0x7C04 && EnglishName [EnglishName.Length - 1] == 'y')
318 return parent_culture = new CultureInfo ("zh-Hant");
319 else if (parent_lcid == 0x0004 && EnglishName [EnglishName.Length -1] == 'y')
320 return parent_culture = new CultureInfo ("zh-Hans");
324 if (parent_lcid == InvariantCultureId)
325 parent_culture = InvariantCulture;
326 else if (cultureID == InvariantCultureId)
327 parent_culture = this;
328 else if (cultureID == 0x0404) {
329 // zh-tw has parent id 0x7C04 which is in this case zh-cht and not zh-hant
330 parent_culture = new CultureInfo ("zh-CHT");
332 parent_culture = new CultureInfo (parent_lcid);
334 return parent_culture;
338 public virtual TextInfo TextInfo
341 if (textInfo == null) {
342 if (!constructed) Construct ();
344 if(textInfo == null) {
345 textInfo = CreateTextInfo (m_isReadOnly);
354 public virtual string ThreeLetterISOLanguageName {
356 if (!constructed) Construct ();
361 public virtual string ThreeLetterWindowsLanguageName
364 if (!constructed) Construct ();
369 public virtual string TwoLetterISOLanguageName {
371 if (!constructed) Construct ();
376 public bool UseUserOverride
379 return m_useUserOverride;
383 public void ClearCachedData()
385 lock (shared_table_lock) {
386 shared_by_number = null;
387 shared_by_name = null;
391 // ClearCachedData method does not refresh the information in
392 // the Thread.CurrentCulture property for existing threads
394 default_current_culture = null;
396 RegionInfo.ClearCachedData ();
397 TimeZone.ClearCachedData ();
398 TimeZoneInfo.ClearCachedData ();
401 public virtual object Clone()
403 if (!constructed) Construct ();
404 CultureInfo ci=(CultureInfo)MemberwiseClone ();
405 ci.m_isReadOnly=false;
406 ci.cached_serialized_form=null;
407 if (!IsNeutralCulture) {
408 ci.NumberFormat = (NumberFormatInfo)NumberFormat.Clone ();
409 ci.DateTimeFormat = (DateTimeFormatInfo)DateTimeFormat.Clone ();
414 public override bool Equals (object value)
416 CultureInfo b = value as CultureInfo;
417 return b != null && b.cultureID == cultureID && b.m_name == m_name;
420 public static CultureInfo[] GetCultures(CultureTypes types)
422 bool neutral=((types & CultureTypes.NeutralCultures)!=0);
423 bool specific=((types & CultureTypes.SpecificCultures)!=0);
424 bool installed=((types & CultureTypes.InstalledWin32Cultures)!=0); // TODO
426 CultureInfo [] infos = internal_get_cultures (neutral, specific, installed);
427 // The runtime returns a NULL in the first position of the array when
428 // 'neutral' is true. We fill it in with a clone of InvariantCulture
429 // since it must not be read-only
431 if (neutral && infos.Length > 0 && infos [0] == null) {
432 infos [i++] = (CultureInfo) InvariantCulture.Clone ();
435 for (; i < infos.Length; ++i) {
437 var ti = ci.GetTextInfoData ();
438 infos [i].m_cultureData = CultureData.GetCultureData (ci.m_name, false, ci.datetime_index, ci.CalendarType, ci.number_index, ci.iso2lang,
439 ti.ansi, ti.oem, ti.mac, ti.ebcdic, ti.right_to_left, ((char)ti.list_sep).ToString ());
445 unsafe Data GetTextInfoData ()
447 return *(Data*) textinfo_data;
450 public override int GetHashCode ()
452 return cultureID.GetHashCode ();
455 public static CultureInfo ReadOnly(CultureInfo ci)
458 throw new ArgumentNullException("ci");
461 if(ci.m_isReadOnly) {
464 CultureInfo new_ci=(CultureInfo)ci.Clone ();
465 new_ci.m_isReadOnly=true;
466 if (new_ci.numInfo != null)
467 new_ci.numInfo = NumberFormatInfo.ReadOnly (new_ci.numInfo);
468 if (new_ci.dateTimeInfo != null)
469 new_ci.dateTimeInfo = DateTimeFormatInfo.ReadOnly (new_ci.dateTimeInfo);
470 if (new_ci.textInfo != null)
471 new_ci.textInfo = TextInfo.ReadOnly (new_ci.textInfo);
476 public override string ToString()
481 public virtual CompareInfo CompareInfo
484 if(compareInfo==null) {
489 if(compareInfo==null) {
490 compareInfo=new CompareInfo (this);
499 public virtual bool IsNeutralCulture {
501 if (cultureID == InvariantCultureId)
504 if (!constructed) Construct ();
505 return territory == null;
509 internal void CheckNeutral ()
513 public virtual NumberFormatInfo NumberFormat {
515 if (numInfo == null) {
516 NumberFormatInfo temp = new NumberFormatInfo(this.m_cultureData);
517 temp.isReadOnly = m_isReadOnly;
525 if (!constructed) Construct ();
526 if (m_isReadOnly) throw new InvalidOperationException(MSG_READONLY);
529 throw new ArgumentNullException ("NumberFormat");
535 public virtual DateTimeFormatInfo DateTimeFormat {
537 if (dateTimeInfo != null)
540 if (!constructed) Construct ();
543 var temp = new DateTimeFormatInfo (m_cultureData, Calendar);
544 temp.m_isReadOnly = m_isReadOnly;
545 System.Threading.Thread.MemoryBarrier();
551 if (!constructed) Construct ();
552 if (m_isReadOnly) throw new InvalidOperationException(MSG_READONLY);
555 throw new ArgumentNullException ("DateTimeFormat");
557 dateTimeInfo = value;
561 public virtual string DisplayName {
563 // Mono is not localized and will always return english name regardless of OS locale
568 public virtual string EnglishName {
570 if (!constructed) Construct ();
575 public static CultureInfo InstalledUICulture {
577 return ConstructCurrentCulture ();
581 public bool IsReadOnly {
589 // IFormatProvider implementation
591 public virtual object GetFormat( Type formatType )
593 object format = null;
595 if ( formatType == typeof(NumberFormatInfo) )
596 format = NumberFormat;
597 else if ( formatType == typeof(DateTimeFormatInfo) )
598 format = DateTimeFormat;
605 construct_internal_locale_from_lcid (cultureID);
609 [MethodImplAttribute (MethodImplOptions.InternalCall)]
610 private extern bool construct_internal_locale_from_lcid (int lcid);
612 [MethodImplAttribute (MethodImplOptions.InternalCall)]
613 private extern bool construct_internal_locale_from_name (string name);
615 [MethodImplAttribute (MethodImplOptions.InternalCall)]
616 private extern static string get_current_locale_name ();
618 [MethodImplAttribute (MethodImplOptions.InternalCall)]
619 private extern static CultureInfo [] internal_get_cultures (bool neutral, bool specific, bool installed);
621 private void ConstructInvariant (bool read_only)
623 cultureID = InvariantCultureId;
625 /* NumberFormatInfo defaults to the invariant data */
626 numInfo=NumberFormatInfo.InvariantInfo;
629 numInfo = (NumberFormatInfo) numInfo.Clone ();
632 textInfo = TextInfo.Invariant;
636 nativename="Invariant Language (Invariant Country)";
640 default_calendar_type = 1 << CalendarTypeBits | (int) GregorianCalendarTypes.Localized;
643 private unsafe TextInfo CreateTextInfo (bool readOnly)
645 TextInfo tempTextInfo = new TextInfo (this.m_cultureData);
646 tempTextInfo.SetReadOnlyState (readOnly);
650 public CultureInfo (int culture) : this (culture, true) {}
652 public CultureInfo (int culture, bool useUserOverride) :
653 this (culture, useUserOverride, false) {}
655 private CultureInfo (int culture, bool useUserOverride, bool read_only)
658 throw new ArgumentOutOfRangeException ("culture", "Positive "
659 + "number required.");
662 m_isReadOnly = read_only;
663 m_useUserOverride = useUserOverride;
665 if (culture == InvariantCultureId) {
666 /* Short circuit the invariant culture */
667 m_cultureData = CultureData.Invariant;
668 ConstructInvariant (read_only);
672 if (!construct_internal_locale_from_lcid (culture)) {
674 // Be careful not to cause recursive CultureInfo initialization
676 var msg = string.Format (InvariantCulture, "Culture ID {0} (0x{1}) is not a supported culture.", culture.ToString (InvariantCulture), culture.ToString ("X4", InvariantCulture));
677 throw new CultureNotFoundException ("culture", msg);
680 var ti = GetTextInfoData ();
681 m_cultureData = CultureData.GetCultureData (m_name, m_useUserOverride, datetime_index, CalendarType, number_index, iso2lang,
682 ti.ansi, ti.oem, ti.mac, ti.ebcdic, ti.right_to_left, ((char)ti.list_sep).ToString ());
685 public CultureInfo (string name) : this (name, true) {}
687 public CultureInfo (string name, bool useUserOverride) :
688 this (name, useUserOverride, false) {}
690 private CultureInfo (string name, bool useUserOverride, bool read_only)
693 throw new ArgumentNullException ("name");
696 m_isReadOnly = read_only;
697 m_useUserOverride = useUserOverride;
698 m_isInherited = GetType() != typeof(System.Globalization.CultureInfo);
700 if (name.Length == 0) {
701 /* Short circuit the invariant culture */
702 m_cultureData = CultureData.Invariant;
703 ConstructInvariant (read_only);
707 if (!construct_internal_locale_from_name (name.ToLowerInvariant ())) {
708 throw CreateNotFoundException (name);
711 var ti = GetTextInfoData ();
712 m_cultureData = CultureData.GetCultureData (m_name, useUserOverride, datetime_index, CalendarType, number_index, iso2lang,
713 ti.ansi, ti.oem, ti.mac, ti.ebcdic, ti.right_to_left, ((char)ti.list_sep).ToString ());
716 // This is used when creating by specific name and creating by
717 // current locale so we can initialize the object without
718 // doing any member initialization
719 private CultureInfo () { constructed = true; }
720 static Dictionary<int, CultureInfo> shared_by_number;
721 static Dictionary<string, CultureInfo> shared_by_name;
723 static void insert_into_shared_tables (CultureInfo c)
725 if (shared_by_number == null){
726 shared_by_number = new Dictionary<int, CultureInfo> ();
727 shared_by_name = new Dictionary<string, CultureInfo> ();
729 shared_by_number [c.cultureID] = c;
730 shared_by_name [c.m_name] = c;
733 public static CultureInfo GetCultureInfo (int culture)
736 throw new ArgumentOutOfRangeException ("culture", "Positive number required.");
740 lock (shared_table_lock){
741 if (shared_by_number != null) {
742 if (shared_by_number.TryGetValue (culture, out c))
746 c = new CultureInfo (culture, false, true);
747 insert_into_shared_tables (c);
752 public static CultureInfo GetCultureInfo (string name)
755 throw new ArgumentNullException ("name");
758 lock (shared_table_lock){
759 if (shared_by_name != null){
760 if (shared_by_name.TryGetValue (name, out c))
763 c = new CultureInfo (name, false, true);
764 insert_into_shared_tables (c);
769 [MonoTODO ("Currently it ignores the altName parameter")]
770 public static CultureInfo GetCultureInfo (string name, string altName) {
772 throw new ArgumentNullException ("null");
774 throw new ArgumentNullException ("null");
776 return GetCultureInfo (name);
779 public static CultureInfo GetCultureInfoByIetfLanguageTag (string name)
781 // There could be more consistent way to implement
782 // it, but right now it works just fine with this...
785 return GetCultureInfo ("zh-CHS");
787 return GetCultureInfo ("zh-CHT");
789 return GetCultureInfo (name);
793 // used in runtime (icall.c) to construct CultureInfo for
794 // AssemblyName of assemblies
795 internal static CultureInfo CreateCulture (string name, bool reference)
798 bool use_user_override;
800 bool invariant = name.Length == 0;
802 use_user_override = invariant ? false : true;
806 use_user_override = invariant ? false : true;
809 return new CultureInfo (name, use_user_override, read_only);
812 public static CultureInfo CreateSpecificCulture (string name)
815 throw new ArgumentNullException ("name");
817 if (name.Length == 0)
818 return InvariantCulture;
821 name = name.ToLowerInvariant ();
822 CultureInfo ci = new CultureInfo ();
824 if (!ci.construct_internal_locale_from_name (name)) {
825 int idx = name.Length - 1;
827 while ((idx = name.LastIndexOf ('-', idx - 1)) > 0) {
828 if (ci.construct_internal_locale_from_name (name.Substring (0, idx)))
834 throw CreateNotFoundException (src_name);
837 if (ci.IsNeutralCulture)
838 ci = CreateSpecificCultureFromNeutral (ci.Name);
840 var ti = ci.GetTextInfoData ();
842 ci.m_cultureData = CultureData.GetCultureData (ci.m_name, false, ci.datetime_index, ci.CalendarType, ci.number_index, ci.iso2lang,
843 ti.ansi, ti.oem, ti.mac, ti.ebcdic, ti.right_to_left, ((char)ti.list_sep).ToString ());
848 // Creates specific culture from neutral culture. Used by CreateSpecificCulture
849 // only but using separate method we can delay switch underlying Dictionary
852 static CultureInfo CreateSpecificCultureFromNeutral (string name)
857 // For neutral cultures find predefined default specific culture
859 // Use managed switch because we need this for only some cultures
860 // and the method is not used frequently
862 // TODO: We could optimize for cultures with single specific culture
864 switch (name.ToLowerInvariant ()) {
865 case "af": id = 1078; break;
866 case "am": id = 1118; break;
867 case "ar": id = 1025; break;
868 case "arn": id = 1146; break;
869 case "as": id = 1101; break;
870 case "az": id = 1068; break;
871 case "az-cyrl": id = 2092; break;
872 case "az-latn": id = 1068; break;
873 case "ba": id = 1133; break;
874 case "be": id = 1059; break;
875 case "bg": id = 1026; break;
876 case "bn": id = 1093; break;
877 case "bo": id = 1105; break;
878 case "br": id = 1150; break;
879 case "bs": id = 5146; break;
880 case "bs-cyrl": id = 8218; break;
881 case "bs-latn": id = 5146; break;
882 case "ca": id = 1027; break;
883 case "co": id = 1155; break;
884 case "cs": id = 1029; break;
885 case "cy": id = 1106; break;
886 case "da": id = 1030; break;
887 case "de": id = 1031; break;
888 case "dsb": id = 2094; break;
889 case "dv": id = 1125; break;
890 case "el": id = 1032; break;
891 case "en": id = 1033; break;
892 case "es": id = 3082; break;
893 case "et": id = 1061; break;
894 case "eu": id = 1069; break;
895 case "fa": id = 1065; break;
896 case "fi": id = 1035; break;
897 case "fil": id = 1124; break;
898 case "fo": id = 1080; break;
899 case "fr": id = 1036; break;
900 case "fy": id = 1122; break;
901 case "ga": id = 2108; break;
902 case "gd": id = 1169; break;
903 case "gl": id = 1110; break;
904 case "gsw": id = 1156; break;
905 case "gu": id = 1095; break;
906 case "ha": id = 1128; break;
907 case "ha-latn": id = 1128; break;
908 case "he": id = 1037; break;
909 case "hi": id = 1081; break;
910 case "hr": id = 1050; break;
911 case "hsb": id = 1070; break;
912 case "hu": id = 1038; break;
913 case "hy": id = 1067; break;
914 case "id": id = 1057; break;
915 case "ig": id = 1136; break;
916 case "ii": id = 1144; break;
917 case "is": id = 1039; break;
918 case "it": id = 1040; break;
919 case "iu": id = 2141; break;
920 case "iu-cans": id = 1117; break;
921 case "iu-latn": id = 2141; break;
922 case "ja": id = 1041; break;
923 case "ka": id = 1079; break;
924 case "kk": id = 1087; break;
925 case "kl": id = 1135; break;
926 case "km": id = 1107; break;
927 case "kn": id = 1099; break;
928 case "ko": id = 1042; break;
929 case "kok": id = 1111; break;
930 case "ky": id = 1088; break;
931 case "lb": id = 1134; break;
932 case "lo": id = 1108; break;
933 case "lt": id = 1063; break;
934 case "lv": id = 1062; break;
935 case "mi": id = 1153; break;
936 case "mk": id = 1071; break;
937 case "ml": id = 1100; break;
938 case "mn": id = 1104; break;
939 case "mn-cyrl": id = 1104; break;
940 case "mn-mong": id = 2128; break;
941 case "moh": id = 1148; break;
942 case "mr": id = 1102; break;
943 case "ms": id = 1086; break;
944 case "mt": id = 1082; break;
945 case "nb": id = 1044; break;
946 case "ne": id = 1121; break;
947 case "nl": id = 1043; break;
948 case "nn": id = 2068; break;
949 case "no": id = 1044; break;
950 case "nso": id = 1132; break;
951 case "oc": id = 1154; break;
952 case "or": id = 1096; break;
953 case "pa": id = 1094; break;
954 case "pl": id = 1045; break;
955 case "prs": id = 1164; break;
956 case "ps": id = 1123; break;
957 case "pt": id = 1046; break;
958 case "qut": id = 1158; break;
959 case "quz": id = 1131; break;
960 case "rm": id = 1047; break;
961 case "ro": id = 1048; break;
962 case "ru": id = 1049; break;
963 case "rw": id = 1159; break;
964 case "sa": id = 1103; break;
965 case "sah": id = 1157; break;
966 case "se": id = 1083; break;
967 case "si": id = 1115; break;
968 case "sk": id = 1051; break;
969 case "sl": id = 1060; break;
970 case "sma": id = 7227; break;
971 case "smj": id = 5179; break;
972 case "smn": id = 9275; break;
973 case "sms": id = 8251; break;
974 case "sq": id = 1052; break;
975 case "sr": id = 9242; break;
976 case "sr-cyrl": id = 10266; break;
977 case "sr-latn": id = 9242; break;
978 case "sv": id = 1053; break;
979 case "sw": id = 1089; break;
980 case "syr": id = 1114; break;
981 case "ta": id = 1097; break;
982 case "te": id = 1098; break;
983 case "tg": id = 1064; break;
984 case "tg-cyrl": id = 1064; break;
985 case "th": id = 1054; break;
986 case "tk": id = 1090; break;
987 case "tn": id = 1074; break;
988 case "tr": id = 1055; break;
989 case "tt": id = 1092; break;
990 case "tzm": id = 2143; break;
991 case "tzm-latn": id = 2143; break;
992 case "ug": id = 1152; break;
993 case "uk": id = 1058; break;
994 case "ur": id = 1056; break;
995 case "uz": id = 1091; break;
996 case "uz-cyrl": id = 2115; break;
997 case "uz-latn": id = 1091; break;
998 case "vi": id = 1066; break;
999 case "wo": id = 1160; break;
1000 case "xh": id = 1076; break;
1001 case "yo": id = 1130; break;
1002 case "zh": id = 2052; break;
1009 case "zu": id = 1077; break;
1011 throw new NotImplementedException ("Mapping for neutral culture " + name);
1014 return new CultureInfo (id);
1017 internal int CalendarType {
1019 switch (default_calendar_type >> CalendarTypeBits) {
1021 return Calendar.CAL_GREGORIAN;
1023 return Calendar.CAL_THAI;
1025 return Calendar.CAL_UMALQURA;
1027 return Calendar.CAL_HIJRI;
1029 throw new NotImplementedException ("CalendarType");
1034 static Calendar CreateCalendar (int calendarType)
1037 switch (calendarType >> CalendarTypeBits) {
1039 GregorianCalendarTypes greg_type;
1040 greg_type = (GregorianCalendarTypes) (calendarType & 0xFF);
1041 return new GregorianCalendar (greg_type);
1043 name = "System.Globalization.ThaiBuddhistCalendar";
1046 name = "System.Globalization.UmAlQuraCalendar";
1049 name = "System.Globalization.HijriCalendar";
1052 throw new NotImplementedException ("Unknown calendar type: " + calendarType);
1055 Type type = Type.GetType (name, false);
1057 return new GregorianCalendar (GregorianCalendarTypes.Localized); // return invariant calendar if not found
1058 return (Calendar) Activator.CreateInstance (type);
1061 static Exception CreateNotFoundException (string name)
1063 return new CultureNotFoundException ("name", "Culture name " + name + " is not supported.");
1066 public static CultureInfo DefaultThreadCurrentCulture {
1068 return Thread.default_culture;
1071 Thread.default_culture = value;
1075 public static CultureInfo DefaultThreadCurrentUICulture {
1077 return Thread.default_ui_culture;
1080 Thread.default_ui_culture = value;
1084 internal string SortName {
1090 #region reference sources
1092 internal static readonly bool IsTaiwanSku;
1095 // CheckDomainSafetyObject throw if the object is customized object which cannot be attached to
1096 // other object (like CultureInfo or DateTimeFormatInfo).
1099 internal static void CheckDomainSafetyObject(Object obj, Object container)
1101 if (obj.GetType().Assembly != typeof(System.Globalization.CultureInfo).Assembly) {
1103 throw new InvalidOperationException(
1105 CultureInfo.CurrentCulture,
1106 Environment.GetResourceString("InvalidOperation_SubclassedObject"),
1108 container.GetType()));
1110 Contract.EndContractBlock();
1113 // For resource lookup, we consider a culture the invariant culture by name equality.
1114 // We perform this check frequently during resource lookup, so adding a property for
1115 // improved readability.
1116 internal bool HasInvariantCultureName
1118 get { return Name == CultureInfo.InvariantCulture.Name; }
1121 internal static bool VerifyCultureName(String cultureName, bool throwException)
1123 // This function is used by ResourceManager.GetResourceFileName().
1124 // ResourceManager searches for resource using CultureInfo.Name,
1125 // so we should check against CultureInfo.Name.
1127 for (int i=0; i<cultureName.Length; i++) {
1128 char c = cultureName[i];
1131 if (Char.IsLetterOrDigit(c) || c=='-' || c=='_') {
1134 if (throwException) {
1135 throw new ArgumentException(Environment.GetResourceString("Argument_InvalidResourceCultureName", cultureName));