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;
62 internal volatile NumberFormatInfo numInfo;
63 internal volatile DateTimeFormatInfo dateTimeInfo;
64 volatile TextInfo textInfo;
65 internal string m_name;
68 private string englishname;
70 private string nativename;
72 private string iso3lang;
74 private string iso2lang;
76 private string win3lang;
78 private string territory;
80 string[] native_calendar_names;
82 volatile CompareInfo compareInfo;
84 private unsafe readonly void *textinfo_data;
86 [StructLayout (LayoutKind.Sequential)]
92 public bool right_to_left;
96 int m_dataItem; // MS.NET serializes this.
97 #pragma warning restore 169, 649
102 CultureInfo parent_culture;
104 // Deserialized instances will set this to false
109 // Used by Thread.set_CurrentCulture
110 internal byte[] cached_serialized_form;
112 [NonSerialized]internal CultureData m_cultureData;
113 [NonSerialized]internal bool m_isInherited;
115 internal const int InvariantCultureId = 0x7F;
116 const int CalendarTypeBits = 8;
118 const string MSG_READONLY = "This instance is read only";
120 public static CultureInfo InvariantCulture {
122 return invariant_culture_info;
126 public static CultureInfo CurrentCulture {
128 return Thread.CurrentThread.CurrentCulture;
132 public static CultureInfo CurrentUICulture {
134 return Thread.CurrentThread.CurrentUICulture;
138 internal static CultureInfo ConstructCurrentCulture ()
140 if (default_current_culture != null)
141 return default_current_culture;
143 var locale_name = get_current_locale_name ();
144 CultureInfo ci = null;
146 if (locale_name != null) {
148 ci = CreateSpecificCulture (locale_name);
154 ci = InvariantCulture;
156 ci.m_isReadOnly = true;
157 ci.m_useUserOverride = true;
160 default_current_culture = ci;
164 internal static CultureInfo ConstructCurrentUICulture ()
166 return ConstructCurrentCulture ();
169 // it is used for RegionInfo.
170 internal string Territory {
171 get { return territory; }
175 // FIXME: It is implemented, but would be hell slow.
177 public CultureTypes CultureTypes {
179 CultureTypes ret = (CultureTypes) 0;
180 foreach (CultureTypes v in Enum.GetValues (typeof (CultureTypes)))
181 if (Array.IndexOf (GetCultures (v), this) >= 0)
188 public CultureInfo GetConsoleFallbackUICulture ()
190 // as documented in MSDN ...
192 case "ar": case "ar-BH": case "ar-EG": case "ar-IQ":
193 case "ar-JO": case "ar-KW": case "ar-LB": case "ar-LY":
194 case "ar-QA": case "ar-SA": case "ar-SY": case "ar-AE":
196 case "dv": case "dv-MV":
197 case "fa": case "fa-IR":
198 case "gu": case "gu-IN":
199 case "he": case "he-IL":
200 case "hi": case "hi-IN":
201 case "kn": case "kn-IN":
202 case "kok": case "kok-IN":
203 case "mr": case "mr-IN":
204 case "pa": case "pa-IN":
205 case "sa": case "sa-IN":
206 case "syr": case "syr-SY":
207 case "ta": case "ta-IN":
208 case "te": case "te-IN":
209 case "th": case "th-TH":
210 case "ur": case "ur-PK":
211 case "vi": case "vi-VN":
212 return GetCultureInfo ("en");
213 case "ar-DZ": case "ar-MA": case "ar-TN":
214 return GetCultureInfo ("fr");
216 return (CultureTypes & CultureTypes.WindowsOnlyCultures) != 0 ? CultureInfo.InvariantCulture : this;
220 public string IetfLanguageTag {
221 // There could be more consistent way to implement
222 // it, but right now it works just fine with this...
235 // For specific cultures it basically returns LCID.
236 // For neutral cultures it is mapped to the default(?) specific
237 // culture, where the LCID of the specific culture seems to be
238 // n + 1024 by default. zh-CHS is the only exception which is
239 // mapped to 2052, not 1028 (zh-CHT is mapped to 1028 instead).
240 // There are very few exceptions, here I simply list them here.
241 // It is Windows-specific property anyways, so no worthy of
242 // trying to do some complex things with locale-builder.
244 public virtual int KeyboardLayoutId {
247 case 4: // zh-CHS (neutral)
249 case 1034: // es-ES Spanish 2
251 case 31748: // zh-CHT (neutral)
253 case 31770: // sr (neutral)
256 return LCID < 1024 ? LCID + 1024 : LCID;
262 public virtual int LCID {
268 public virtual string Name {
274 public virtual string NativeName {
276 if (!constructed) Construct ();
281 internal string NativeCalendarName {
283 if (!constructed) Construct ();
284 return native_calendar_names[(default_calendar_type >> CalendarTypeBits) - 1];
288 public virtual Calendar Calendar {
290 if (calendar == null) {
291 if (!constructed) Construct ();
292 calendar = CreateCalendar (default_calendar_type);
299 [MonoLimitation ("Optional calendars are not supported only default calendar is returned")]
300 public virtual Calendar[] OptionalCalendars {
302 return new[] { Calendar };
306 public virtual CultureInfo Parent
309 if (parent_culture == null) {
312 if (parent_lcid == cultureID) {
314 // Parent lcid is same but culture info is not for legacy zh culture
316 if (parent_lcid == 0x7C04 && EnglishName [EnglishName.Length - 1] == 'y')
317 return parent_culture = new CultureInfo ("zh-Hant");
318 else if (parent_lcid == 0x0004 && EnglishName [EnglishName.Length -1] == 'y')
319 return parent_culture = new CultureInfo ("zh-Hans");
323 if (parent_lcid == InvariantCultureId)
324 parent_culture = InvariantCulture;
325 else if (cultureID == InvariantCultureId)
326 parent_culture = this;
327 else if (cultureID == 0x0404) {
328 // zh-tw has parent id 0x7C04 which is in this case zh-cht and not zh-hant
329 parent_culture = new CultureInfo ("zh-CHT");
331 parent_culture = new CultureInfo (parent_lcid);
333 return parent_culture;
337 public virtual TextInfo TextInfo
340 if (textInfo == null) {
341 if (!constructed) Construct ();
343 if(textInfo == null) {
344 textInfo = CreateTextInfo (m_isReadOnly);
353 public virtual string ThreeLetterISOLanguageName {
355 if (!constructed) Construct ();
360 public virtual string ThreeLetterWindowsLanguageName
363 if (!constructed) Construct ();
368 public virtual string TwoLetterISOLanguageName {
370 if (!constructed) Construct ();
375 public bool UseUserOverride
378 return m_useUserOverride;
382 public void ClearCachedData()
384 lock (shared_table_lock) {
385 shared_by_number = null;
386 shared_by_name = null;
390 // ClearCachedData method does not refresh the information in
391 // the Thread.CurrentCulture property for existing threads
393 default_current_culture = null;
395 RegionInfo.ClearCachedData ();
396 TimeZone.ClearCachedData ();
397 TimeZoneInfo.ClearCachedData ();
400 public virtual object Clone()
402 if (!constructed) Construct ();
403 CultureInfo ci=(CultureInfo)MemberwiseClone ();
404 ci.m_isReadOnly=false;
405 ci.cached_serialized_form=null;
406 if (!IsNeutralCulture) {
407 ci.NumberFormat = (NumberFormatInfo)NumberFormat.Clone ();
408 ci.DateTimeFormat = (DateTimeFormatInfo)DateTimeFormat.Clone ();
413 public override bool Equals (object value)
415 CultureInfo b = value as CultureInfo;
416 return b != null && b.cultureID == cultureID && b.m_name == m_name;
419 public static CultureInfo[] GetCultures(CultureTypes types)
421 bool neutral=((types & CultureTypes.NeutralCultures)!=0);
422 bool specific=((types & CultureTypes.SpecificCultures)!=0);
423 bool installed=((types & CultureTypes.InstalledWin32Cultures)!=0); // TODO
425 CultureInfo [] infos = internal_get_cultures (neutral, specific, installed);
426 // The runtime returns a NULL in the first position of the array when
427 // 'neutral' is true. We fill it in with a clone of InvariantCulture
428 // since it must not be read-only
430 if (neutral && infos.Length > 0 && infos [0] == null) {
431 infos [i++] = (CultureInfo) InvariantCulture.Clone ();
434 for (; i < infos.Length; ++i) {
436 var ti = ci.GetTextInfoData ();
437 infos [i].m_cultureData = CultureData.GetCultureData (ci.m_name, false, ci.datetime_index, ci.CalendarType, ci.number_index, ci.iso2lang,
438 ti.ansi, ti.oem, ti.mac, ti.ebcdic, ti.right_to_left, ((char)ti.list_sep).ToString ());
444 unsafe Data GetTextInfoData ()
446 return *(Data*) textinfo_data;
449 public override int GetHashCode ()
451 return cultureID.GetHashCode ();
454 public static CultureInfo ReadOnly(CultureInfo ci)
457 throw new ArgumentNullException("ci");
460 if(ci.m_isReadOnly) {
463 CultureInfo new_ci=(CultureInfo)ci.Clone ();
464 new_ci.m_isReadOnly=true;
465 if (new_ci.numInfo != null)
466 new_ci.numInfo = NumberFormatInfo.ReadOnly (new_ci.numInfo);
467 if (new_ci.dateTimeInfo != null)
468 new_ci.dateTimeInfo = DateTimeFormatInfo.ReadOnly (new_ci.dateTimeInfo);
469 if (new_ci.textInfo != null)
470 new_ci.textInfo = TextInfo.ReadOnly (new_ci.textInfo);
475 public override string ToString()
480 public virtual CompareInfo CompareInfo
483 if(compareInfo==null) {
488 if(compareInfo==null) {
489 compareInfo=new CompareInfo (this);
498 public virtual bool IsNeutralCulture {
500 if (cultureID == InvariantCultureId)
503 if (!constructed) Construct ();
504 return territory == null;
508 internal void CheckNeutral ()
512 public virtual NumberFormatInfo NumberFormat {
514 if (numInfo == null) {
515 NumberFormatInfo temp = new NumberFormatInfo(this.m_cultureData);
516 temp.isReadOnly = m_isReadOnly;
524 if (!constructed) Construct ();
525 if (m_isReadOnly) throw new InvalidOperationException(MSG_READONLY);
528 throw new ArgumentNullException ("NumberFormat");
534 public virtual DateTimeFormatInfo DateTimeFormat {
536 if (dateTimeInfo != null)
539 if (!constructed) Construct ();
542 var temp = new DateTimeFormatInfo (m_cultureData, Calendar);
543 temp.m_isReadOnly = m_isReadOnly;
544 System.Threading.Thread.MemoryBarrier();
550 if (!constructed) Construct ();
551 if (m_isReadOnly) throw new InvalidOperationException(MSG_READONLY);
554 throw new ArgumentNullException ("DateTimeFormat");
556 dateTimeInfo = value;
560 public virtual string DisplayName {
562 // Mono is not localized and will always return english name regardless of OS locale
567 public virtual string EnglishName {
569 if (!constructed) Construct ();
574 public static CultureInfo InstalledUICulture {
576 return ConstructCurrentCulture ();
580 public bool IsReadOnly {
588 // IFormatProvider implementation
590 public virtual object GetFormat( Type formatType )
592 object format = null;
594 if ( formatType == typeof(NumberFormatInfo) )
595 format = NumberFormat;
596 else if ( formatType == typeof(DateTimeFormatInfo) )
597 format = DateTimeFormat;
604 construct_internal_locale_from_lcid (cultureID);
608 [MethodImplAttribute (MethodImplOptions.InternalCall)]
609 private extern bool construct_internal_locale_from_lcid (int lcid);
611 [MethodImplAttribute (MethodImplOptions.InternalCall)]
612 private extern bool construct_internal_locale_from_name (string name);
614 [MethodImplAttribute (MethodImplOptions.InternalCall)]
615 private extern static string get_current_locale_name ();
617 [MethodImplAttribute (MethodImplOptions.InternalCall)]
618 private extern static CultureInfo [] internal_get_cultures (bool neutral, bool specific, bool installed);
620 private void ConstructInvariant (bool read_only)
622 cultureID = InvariantCultureId;
624 /* NumberFormatInfo defaults to the invariant data */
625 numInfo=NumberFormatInfo.InvariantInfo;
628 numInfo = (NumberFormatInfo) numInfo.Clone ();
631 textInfo = TextInfo.Invariant;
635 nativename="Invariant Language (Invariant Country)";
639 default_calendar_type = 1 << CalendarTypeBits | (int) GregorianCalendarTypes.Localized;
642 private unsafe TextInfo CreateTextInfo (bool readOnly)
644 TextInfo tempTextInfo = new TextInfo (this.m_cultureData);
645 tempTextInfo.SetReadOnlyState (readOnly);
649 public CultureInfo (int culture) : this (culture, true) {}
651 public CultureInfo (int culture, bool useUserOverride) :
652 this (culture, useUserOverride, false) {}
654 private CultureInfo (int culture, bool useUserOverride, bool read_only)
657 throw new ArgumentOutOfRangeException ("culture", "Positive "
658 + "number required.");
661 m_isReadOnly = read_only;
662 m_useUserOverride = useUserOverride;
664 if (culture == InvariantCultureId) {
665 /* Short circuit the invariant culture */
666 m_cultureData = CultureData.Invariant;
667 ConstructInvariant (read_only);
671 if (!construct_internal_locale_from_lcid (culture)) {
673 // Be careful not to cause recursive CultureInfo initialization
675 var msg = string.Format (InvariantCulture, "Culture ID {0} (0x{1}) is not a supported culture.", culture.ToString (InvariantCulture), culture.ToString ("X4", InvariantCulture));
676 throw new CultureNotFoundException ("culture", msg);
679 var ti = GetTextInfoData ();
680 m_cultureData = CultureData.GetCultureData (m_name, m_useUserOverride, datetime_index, CalendarType, number_index, iso2lang,
681 ti.ansi, ti.oem, ti.mac, ti.ebcdic, ti.right_to_left, ((char)ti.list_sep).ToString ());
684 public CultureInfo (string name) : this (name, true) {}
686 public CultureInfo (string name, bool useUserOverride) :
687 this (name, useUserOverride, false) {}
689 private CultureInfo (string name, bool useUserOverride, bool read_only)
692 throw new ArgumentNullException ("name");
695 m_isReadOnly = read_only;
696 m_useUserOverride = useUserOverride;
697 m_isInherited = GetType() != typeof(System.Globalization.CultureInfo);
699 if (name.Length == 0) {
700 /* Short circuit the invariant culture */
701 m_cultureData = CultureData.Invariant;
702 ConstructInvariant (read_only);
706 if (!construct_internal_locale_from_name (name.ToLowerInvariant ())) {
707 throw CreateNotFoundException (name);
710 var ti = GetTextInfoData ();
711 m_cultureData = CultureData.GetCultureData (m_name, useUserOverride, datetime_index, CalendarType, number_index, iso2lang,
712 ti.ansi, ti.oem, ti.mac, ti.ebcdic, ti.right_to_left, ((char)ti.list_sep).ToString ());
715 // This is used when creating by specific name and creating by
716 // current locale so we can initialize the object without
717 // doing any member initialization
718 private CultureInfo () { constructed = true; }
719 static Dictionary<int, CultureInfo> shared_by_number;
720 static Dictionary<string, CultureInfo> shared_by_name;
722 static void insert_into_shared_tables (CultureInfo c)
724 if (shared_by_number == null){
725 shared_by_number = new Dictionary<int, CultureInfo> ();
726 shared_by_name = new Dictionary<string, CultureInfo> ();
728 shared_by_number [c.cultureID] = c;
729 shared_by_name [c.m_name] = c;
732 public static CultureInfo GetCultureInfo (int culture)
735 throw new ArgumentOutOfRangeException ("culture", "Positive number required.");
739 lock (shared_table_lock){
740 if (shared_by_number != null) {
741 if (shared_by_number.TryGetValue (culture, out c))
745 c = new CultureInfo (culture, false, true);
746 insert_into_shared_tables (c);
751 public static CultureInfo GetCultureInfo (string name)
754 throw new ArgumentNullException ("name");
757 lock (shared_table_lock){
758 if (shared_by_name != null){
759 if (shared_by_name.TryGetValue (name, out c))
762 c = new CultureInfo (name, false, true);
763 insert_into_shared_tables (c);
768 [MonoTODO ("Currently it ignores the altName parameter")]
769 public static CultureInfo GetCultureInfo (string name, string altName) {
771 throw new ArgumentNullException ("null");
773 throw new ArgumentNullException ("null");
775 return GetCultureInfo (name);
778 public static CultureInfo GetCultureInfoByIetfLanguageTag (string name)
780 // There could be more consistent way to implement
781 // it, but right now it works just fine with this...
784 return GetCultureInfo ("zh-CHS");
786 return GetCultureInfo ("zh-CHT");
788 return GetCultureInfo (name);
792 // used in runtime (icall.c) to construct CultureInfo for
793 // AssemblyName of assemblies
794 internal static CultureInfo CreateCulture (string name, bool reference)
797 bool use_user_override;
799 bool invariant = name.Length == 0;
801 use_user_override = invariant ? false : true;
805 use_user_override = invariant ? false : true;
808 return new CultureInfo (name, use_user_override, read_only);
811 public static CultureInfo CreateSpecificCulture (string name)
814 throw new ArgumentNullException ("name");
816 if (name.Length == 0)
817 return InvariantCulture;
820 name = name.ToLowerInvariant ();
821 CultureInfo ci = new CultureInfo ();
823 if (!ci.construct_internal_locale_from_name (name)) {
824 int idx = name.Length - 1;
826 while ((idx = name.LastIndexOf ('-', idx - 1)) > 0) {
827 if (ci.construct_internal_locale_from_name (name.Substring (0, idx)))
833 throw CreateNotFoundException (src_name);
836 if (ci.IsNeutralCulture)
837 ci = CreateSpecificCultureFromNeutral (ci.Name);
839 var ti = ci.GetTextInfoData ();
841 ci.m_cultureData = CultureData.GetCultureData (ci.m_name, false, ci.datetime_index, ci.CalendarType, ci.number_index, ci.iso2lang,
842 ti.ansi, ti.oem, ti.mac, ti.ebcdic, ti.right_to_left, ((char)ti.list_sep).ToString ());
847 // Creates specific culture from neutral culture. Used by CreateSpecificCulture
848 // only but using separate method we can delay switch underlying Dictionary
851 static CultureInfo CreateSpecificCultureFromNeutral (string name)
856 // For neutral cultures find predefined default specific culture
858 // Use managed switch because we need this for only some cultures
859 // and the method is not used frequently
861 // TODO: We could optimize for cultures with single specific culture
863 switch (name.ToLowerInvariant ()) {
864 case "af": id = 1078; break;
865 case "am": id = 1118; break;
866 case "ar": id = 1025; break;
867 case "arn": id = 1146; break;
868 case "as": id = 1101; break;
869 case "az": id = 1068; break;
870 case "az-cyrl": id = 2092; break;
871 case "az-latn": id = 1068; break;
872 case "ba": id = 1133; break;
873 case "be": id = 1059; break;
874 case "bg": id = 1026; break;
875 case "bn": id = 1093; break;
876 case "bo": id = 1105; break;
877 case "br": id = 1150; break;
878 case "bs": id = 5146; break;
879 case "bs-cyrl": id = 8218; break;
880 case "bs-latn": id = 5146; break;
881 case "ca": id = 1027; break;
882 case "co": id = 1155; break;
883 case "cs": id = 1029; break;
884 case "cy": id = 1106; break;
885 case "da": id = 1030; break;
886 case "de": id = 1031; break;
887 case "dsb": id = 2094; break;
888 case "dv": id = 1125; break;
889 case "el": id = 1032; break;
890 case "en": id = 1033; break;
891 case "es": id = 3082; break;
892 case "et": id = 1061; break;
893 case "eu": id = 1069; break;
894 case "fa": id = 1065; break;
895 case "fi": id = 1035; break;
896 case "fil": id = 1124; break;
897 case "fo": id = 1080; break;
898 case "fr": id = 1036; break;
899 case "fy": id = 1122; break;
900 case "ga": id = 2108; break;
901 case "gd": id = 1169; break;
902 case "gl": id = 1110; break;
903 case "gsw": id = 1156; break;
904 case "gu": id = 1095; break;
905 case "ha": id = 1128; break;
906 case "ha-latn": id = 1128; break;
907 case "he": id = 1037; break;
908 case "hi": id = 1081; break;
909 case "hr": id = 1050; break;
910 case "hsb": id = 1070; break;
911 case "hu": id = 1038; break;
912 case "hy": id = 1067; break;
913 case "id": id = 1057; break;
914 case "ig": id = 1136; break;
915 case "ii": id = 1144; break;
916 case "is": id = 1039; break;
917 case "it": id = 1040; break;
918 case "iu": id = 2141; break;
919 case "iu-cans": id = 1117; break;
920 case "iu-latn": id = 2141; break;
921 case "ja": id = 1041; break;
922 case "ka": id = 1079; break;
923 case "kk": id = 1087; break;
924 case "kl": id = 1135; break;
925 case "km": id = 1107; break;
926 case "kn": id = 1099; break;
927 case "ko": id = 1042; break;
928 case "kok": id = 1111; break;
929 case "ky": id = 1088; break;
930 case "lb": id = 1134; break;
931 case "lo": id = 1108; break;
932 case "lt": id = 1063; break;
933 case "lv": id = 1062; break;
934 case "mi": id = 1153; break;
935 case "mk": id = 1071; break;
936 case "ml": id = 1100; break;
937 case "mn": id = 1104; break;
938 case "mn-cyrl": id = 1104; break;
939 case "mn-mong": id = 2128; break;
940 case "moh": id = 1148; break;
941 case "mr": id = 1102; break;
942 case "ms": id = 1086; break;
943 case "mt": id = 1082; break;
944 case "nb": id = 1044; break;
945 case "ne": id = 1121; break;
946 case "nl": id = 1043; break;
947 case "nn": id = 2068; break;
948 case "no": id = 1044; break;
949 case "nso": id = 1132; break;
950 case "oc": id = 1154; break;
951 case "or": id = 1096; break;
952 case "pa": id = 1094; break;
953 case "pl": id = 1045; break;
954 case "prs": id = 1164; break;
955 case "ps": id = 1123; break;
956 case "pt": id = 1046; break;
957 case "qut": id = 1158; break;
958 case "quz": id = 1131; break;
959 case "rm": id = 1047; break;
960 case "ro": id = 1048; break;
961 case "ru": id = 1049; break;
962 case "rw": id = 1159; break;
963 case "sa": id = 1103; break;
964 case "sah": id = 1157; break;
965 case "se": id = 1083; break;
966 case "si": id = 1115; break;
967 case "sk": id = 1051; break;
968 case "sl": id = 1060; break;
969 case "sma": id = 7227; break;
970 case "smj": id = 5179; break;
971 case "smn": id = 9275; break;
972 case "sms": id = 8251; break;
973 case "sq": id = 1052; break;
974 case "sr": id = 9242; break;
975 case "sr-cyrl": id = 10266; break;
976 case "sr-latn": id = 9242; break;
977 case "sv": id = 1053; break;
978 case "sw": id = 1089; break;
979 case "syr": id = 1114; break;
980 case "ta": id = 1097; break;
981 case "te": id = 1098; break;
982 case "tg": id = 1064; break;
983 case "tg-cyrl": id = 1064; break;
984 case "th": id = 1054; break;
985 case "tk": id = 1090; break;
986 case "tn": id = 1074; break;
987 case "tr": id = 1055; break;
988 case "tt": id = 1092; break;
989 case "tzm": id = 2143; break;
990 case "tzm-latn": id = 2143; break;
991 case "ug": id = 1152; break;
992 case "uk": id = 1058; break;
993 case "ur": id = 1056; break;
994 case "uz": id = 1091; break;
995 case "uz-cyrl": id = 2115; break;
996 case "uz-latn": id = 1091; break;
997 case "vi": id = 1066; break;
998 case "wo": id = 1160; break;
999 case "xh": id = 1076; break;
1000 case "yo": id = 1130; break;
1001 case "zh": id = 2052; break;
1008 case "zu": id = 1077; break;
1010 throw new NotImplementedException ("Mapping for neutral culture " + name);
1013 return new CultureInfo (id);
1016 internal int CalendarType {
1018 switch (default_calendar_type >> CalendarTypeBits) {
1020 return Calendar.CAL_GREGORIAN;
1022 return Calendar.CAL_THAI;
1024 return Calendar.CAL_UMALQURA;
1026 return Calendar.CAL_HIJRI;
1028 throw new NotImplementedException ("CalendarType");
1033 static Calendar CreateCalendar (int calendarType)
1036 switch (calendarType >> CalendarTypeBits) {
1038 GregorianCalendarTypes greg_type;
1039 greg_type = (GregorianCalendarTypes) (calendarType & 0xFF);
1040 return new GregorianCalendar (greg_type);
1042 name = "System.Globalization.ThaiBuddhistCalendar";
1045 name = "System.Globalization.UmAlQuraCalendar";
1048 name = "System.Globalization.HijriCalendar";
1051 throw new NotImplementedException ("Unknown calendar type: " + calendarType);
1054 Type type = Type.GetType (name, false);
1056 return new GregorianCalendar (GregorianCalendarTypes.Localized); // return invariant calendar if not found
1057 return (Calendar) Activator.CreateInstance (type);
1060 static Exception CreateNotFoundException (string name)
1062 return new CultureNotFoundException ("name", "Culture name " + name + " is not supported.");
1065 public static CultureInfo DefaultThreadCurrentCulture {
1067 return Thread.default_culture;
1070 Thread.default_culture = value;
1074 public static CultureInfo DefaultThreadCurrentUICulture {
1076 return Thread.default_ui_culture;
1079 Thread.default_ui_culture = value;
1083 internal string SortName {
1089 #region reference sources
1091 internal static readonly bool IsTaiwanSku;
1094 // CheckDomainSafetyObject throw if the object is customized object which cannot be attached to
1095 // other object (like CultureInfo or DateTimeFormatInfo).
1098 internal static void CheckDomainSafetyObject(Object obj, Object container)
1100 if (obj.GetType().Assembly != typeof(System.Globalization.CultureInfo).Assembly) {
1102 throw new InvalidOperationException(
1104 CultureInfo.CurrentCulture,
1105 Environment.GetResourceString("InvalidOperation_SubclassedObject"),
1107 container.GetType()));
1109 Contract.EndContractBlock();
1112 // For resource lookup, we consider a culture the invariant culture by name equality.
1113 // We perform this check frequently during resource lookup, so adding a property for
1114 // improved readability.
1115 internal bool HasInvariantCultureName
1117 get { return Name == CultureInfo.InvariantCulture.Name; }
1120 internal static bool VerifyCultureName(String cultureName, bool throwException)
1122 // This function is used by ResourceManager.GetResourceFileName().
1123 // ResourceManager searches for resource using CultureInfo.Name,
1124 // so we should check against CultureInfo.Name.
1126 for (int i=0; i<cultureName.Length; i++) {
1127 char c = cultureName[i];
1130 if (Char.IsLetterOrDigit(c) || c=='-' || c=='_') {
1133 if (throwException) {
1134 throw new ArgumentException(Environment.GetResourceString("Argument_InvalidResourceCultureName", cultureName));