public static void Main() { CultureAndRegionInfoBuilder cib = null; try { // Create a CultureAndRegionInfoBuilder // object named "ro-MD". cib = new CultureAndRegionInfoBuilder( "ro-MD", CultureAndRegionModifiers.None); // Populate the new CultureAndRegionInfoBuilder // object with culture information. CultureInfo ci = new CultureInfo("ro-RO"); cib.LoadDataFromCultureInfo(ci); // Populate the new CultureAndRegionInfoBuilder // object with region information. RegionInfo ri = new RegionInfo("RO"); cib.LoadDataFromRegionInfo(ri); var filePath = "ro-MD.xml"; if (File.Exists(filePath)) { File.Delete(filePath); } // Save as XML cib.Save(filePath); // TODO: modify the XML var xDoc = XDocument.Load(filePath); var ns = "http://schemas.microsoft.com/globalization/2004/08/carib/ldml"; xDoc.Descendants(XName.Get("regionEnglishName", ns)) .FirstOrDefault().Attribute("type").SetValue("Moldova"); xDoc.Descendants(XName.Get("regionNativeName", ns)) .FirstOrDefault().Attribute("type").SetValue("Moldova"); // and so on xDoc.Save(filePath); var roMd = CultureAndRegionInfoBuilder .CreateFromLdml(filePath); // this may throw an exception if the culture info exists try { CultureAndRegionInfoBuilder.Unregister("ro-MD"); } catch (Exception) { //throw; } // Register the custom culture. roMd.Register(); // Display some of the properties of the custom culture. var riMd = new RegionInfo("ro-MD"); } catch (Exception e) { Console.WriteLine(e); } }
static void Main() { var cultureAndRegionInfoBuilder = new CultureAndRegionInfoBuilder("x-en-US-metric", CultureAndRegionModifiers.None); cultureAndRegionInfoBuilder.LoadDataFromCultureInfo(new CultureInfo("en-US")); cultureAndRegionInfoBuilder.LoadDataFromRegionInfo(new RegionInfo("US")); cultureAndRegionInfoBuilder.IsMetric = true; // Внести изменения cultureAndRegionInfoBuilder.Save("x-en-US-metric"); // Создать файл LDML cultureAndRegionInfoBuilder.Register(); // Зарегистрировать в системе var regionInfo = new RegionInfo("x-en-US-metric"); Console.WriteLine(regionInfo.IsMetric); Console.ReadKey(); }
public static void BuildCulture() { if (cultureExist()) { CultureAndRegionInfoBuilder.Unregister("ku-KU"); } Console.WriteLine("Create the CultureAndRegionInfoBuilder..."); var cib = new CultureAndRegionInfoBuilder("ku-KU", CultureAndRegionModifiers.None); cib.CultureEnglishName = "Kurdish (Kurdistan)"; cib.RegionEnglishName = "Kurdistan"; cib.CultureNativeName = "ßæÑÏí"; var cia = new CultureInfo("ar-IQ"); cib.NumberFormat = cia.NumberFormat; cib.GregorianDateTimeFormat = cia.DateTimeFormat; cib.TextInfo = cia.TextInfo; cib.CompareInfo = cia.CompareInfo; cib.KeyboardLayoutId = cia.KeyboardLayoutId; cib.RegionNativeName = "ßæÑÏÓÊÇä"; cib.ThreeLetterISOLanguageName = "kur"; cib.ThreeLetterISORegionName = "kur"; cib.TwoLetterISORegionName = "ku"; cib.ThreeLetterWindowsRegionName = "kur"; cib.ISOCurrencySymbol = "USD"; cib.CurrencyNativeName = "Dinary Kurdi"; cib.CurrencyEnglishName = "Kurdish Dinar"; var cinull = new CultureInfo(""); cib.Parent = cinull; cib.ThreeLetterWindowsLanguageName = "kur"; cib.TwoLetterISOLanguageName = "ku"; cib.IetfLanguageTag = "kurdisk"; cib.Register(); cib.Save(@"C:\temp\kurdish.xml"); //Save created culture to XML document Console.WriteLine("Create and explore the custom culture..."); var ci = new CultureInfo("ku-KU"); Console.WriteLine("Name: . . . . . . . . . . . . . {0}", ci.Name); Console.WriteLine("EnglishName:. . . . . . . . . . {0}", ci.EnglishName); Console.WriteLine("NativeName: . . . . . . . . . . {0}", ci.NativeName); Console.WriteLine("TwoLetterISOLanguageName: . . . {0}", ci.TwoLetterISOLanguageName); Console.WriteLine("ThreeLetterISOLanguageName: . . {0}", ci.ThreeLetterISOLanguageName); Console.WriteLine("ThreeLetterWindowsLanguageName: {0}", ci.ThreeLetterWindowsLanguageName); Console.Read(); }
static void Main() { // Создаем свою культуру. var regionInfo = new RegionInfo("US"); Console.WriteLine("Значение свойства US.IsMetric = {0}", regionInfo.IsMetric); Console.WriteLine(new string('-', 25)); var builder = new CultureAndRegionInfoBuilder("ai-en-US-cbs", CultureAndRegionModifiers.None); builder.LoadDataFromCultureInfo(new CultureInfo("en-US")); builder.LoadDataFromRegionInfo(regionInfo); // Внести изменения. builder.IsMetric = true; try { // Создать файл LDML (в папке ...bin\Debug\ai-en-US-cbs.ldml). builder.Save("ai-en-US-cbs0.ldml"); // Зарегистрировать в системе. builder.Register(); } catch (Exception e) { Console.WriteLine("Ошибка 1: {0}", e.Message); } try { // Удалось ли нам создать новую культуру? regionInfo = new RegionInfo("ai-en-US-cbs"); Console.WriteLine("Значение свойства ai-en-US-cbs.IsMetric = {0}.", regionInfo.IsMetric); } catch (Exception e) { Console.WriteLine("Ошибка 2: {0}", e.Message); } // Delay. Console.ReadKey(); }
static void Main() { CultureAndRegionInfoBuilder cib = null; cib = new CultureAndRegionInfoBuilder( "x-en-US-metric", CultureAndRegionModifiers.None); cib.LoadDataFromCultureInfo(new CultureInfo("en-US")); cib.LoadDataFromRegionInfo(new RegionInfo("US")); // Make the change. cib.IsMetric = true; // Create an LDML file. cib.Save("x-en-US-metric.ldml"); // Register with the system. cib.Register(); }
public static void Main() { string savedCARIB = "mySavedCARIB.xml"; string msg1 = "The name of the original CultureAndRegionInfoBuilder" + " is \"{0}\"."; string msg2 = "Reconstituting the CultureAndRegionInfoBuilder object " + "from \"{0}\"."; string msg3 = "The name of the reconstituted CultureAndRegionInfoBuilder" + " is \"{0}\"."; // Construct a new, privately used culture that extends the en-US culture // provided by the .NET Framework. In this sample, the CultureAndRegion- // Types.Specific parameter creates a minimal CultureAndRegionInfoBuilder // object that you must populate with culture and region information. CultureAndRegionInfoBuilder cib1 = null; CultureAndRegionInfoBuilder cib2 = null; try { cib1 = new CultureAndRegionInfoBuilder( "x-en-US-sample", CultureAndRegionModifiers.None); } catch (ArgumentException ae) { Console.WriteLine(ae); return; } // Populate the new CultureAndRegionInfoBuilder object with culture information. CultureInfo ci = new CultureInfo("en-US"); cib1.LoadDataFromCultureInfo(ci); // Populate the new CultureAndRegionInfoBuilder object with region information. RegionInfo ri = new RegionInfo("US"); cib1.LoadDataFromRegionInfo(ri); // Display a property of the new custom culture. Console.Clear(); Console.WriteLine(msg1, cib1.CultureName); // Save the new CultureAndRegionInfoBuilder object in the specified file in // LDML format. The file is saved in the same directory as the application // that calls the Save method. Console.WriteLine("Saving the custom culture to a file..."); try { cib1.Save(savedCARIB); } catch (IOException exc) { Console.WriteLine("** I/O exception: {0}", exc.Message); return; } // Create a new CultureAndRegionInfoBuilder object from the persisted file. Console.WriteLine(msg2, savedCARIB); try { cib2 = CultureAndRegionInfoBuilder.CreateFromLdml(savedCARIB); } catch (XmlException xe) { Console.WriteLine("** XML validation exception: {0}", xe.Message); return; } // Display a property of the resonstituted custom culture. Console.WriteLine(msg3, cib2.CultureName); // At this point you could call the Register method and make the reconstituted // custom culture available to other applications. The mySavedCARIB.xml file // remains on your computer. }
static void Main(string[] args) { //MailTest(); CultureInfo usercul = System.Threading.Thread.CurrentThread.CurrentCulture; Console.WriteLine("The current culture of this app is :" + usercul.Name); Console.WriteLine("The Dispaly name of this app is :" + usercul.DisplayName); Console.WriteLine("The Native name of this app is :" + usercul.NativeName); Console.WriteLine("The ISO abbreviation of this app is :" + usercul.TwoLetterISOLanguageName); string cur = (100000).ToString("C"); Console.WriteLine(cur); usercul = System.Threading.Thread.CurrentThread.CurrentUICulture; Console.WriteLine("The current culture of this app is :" + usercul.Name); Console.WriteLine("The Dispaly name of this app is :" + usercul.DisplayName); Console.WriteLine("The Native name of this app is :" + usercul.NativeName); Console.WriteLine("The ISO abbreviation of this app is :" + usercul.TwoLetterISOLanguageName); System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("es-VE"); Console.WriteLine("The current culture of this app is :" + System.Threading.Thread.CurrentThread.CurrentCulture); foreach (CultureInfo cul in CultureInfo.GetCultures(CultureTypes.SpecificCultures)) { Console.WriteLine("culture:" + cul.Name); } usercul = System.Threading.Thread.CurrentThread.CurrentCulture; RegionInfo ri = new RegionInfo(usercul.LCID); //OR ri = new RegionInfo(usercul.Name); Console.WriteLine("English name: " + ri.EnglishName); Console.WriteLine("Display name: " + ri.DisplayName); Console.WriteLine("Currency Symbol: " + ri.CurrencySymbol); string[] days = usercul.DateTimeFormat.DayNames; foreach (string day in days) { Console.WriteLine("Day name for Venezuelan Spanish: " + day); } string[] months = usercul.DateTimeFormat.MonthNames; foreach (string mon in months) { Console.WriteLine("Month name in Venz. Spanish:" + mon); } Console.WriteLine("Number decimal Symbol:" + usercul.NumberFormat.NumberDecimalSeparator); CompareInfo ci = System.Threading.Thread.CurrentThread.CurrentUICulture.CompareInfo; Console.WriteLine(ci.Name); Console.WriteLine(ci.LCID); string firstString = "Coté"; string secondString = "coté"; ci = new CultureInfo("fr-FR").CompareInfo; Console.WriteLine(ci.Compare(firstString, secondString)); Console.WriteLine(ci.Compare(firstString, secondString, CompareOptions.IgnoreCase)); CultureAndRegionInfoBuilder build = new CultureAndRegionInfoBuilder("en-MS", CultureAndRegionModifiers.None); CultureInfo USCulture = new CultureInfo("en-US"); RegionInfo USRegion = new RegionInfo("US"); build.LoadDataFromCultureInfo(USCulture); build.LoadDataFromRegionInfo(USRegion); build.NumberFormat.CurrencySymbol = "*"; build.NumberFormat.CurrencyDecimalSeparator = "^"; build.Save(@"c:\msft.culture.xml"); //build.Register(); //System.Threading.Thread.CurrentThread.CurrentCultu }