public static void Main() { Console.WriteLine("Registering ja-JP-Latn..."); try { var builder = new CultureAndRegionInfoBuilder("ja-JP-Latn", CultureAndRegionModifiers.None); builder.LoadDataFromCultureInfo(new CultureInfo("ja-JP")); builder.LoadDataFromRegionInfo(new RegionInfo("JP")); builder.CultureEnglishName = "Japanese (Romaji)"; builder.CultureNativeName = "日本語 (ローマ字)"; builder.Register(); Console.WriteLine("Done!"); } catch (InvalidOperationException) { Console.WriteLine("Already registered."); } catch (UnauthorizedAccessException) { Console.WriteLine("Not authorized! Run the program as administrator."); } Console.WriteLine("Press enter to exit..."); Console.ReadLine(); }
/// <summary> /// Default constructor. /// </summary> public SurfaceWindow1() { if (false) { CultureAndRegionInfoBuilder cib = new CultureAndRegionInfoBuilder("und", CultureAndRegionModifiers.None); CultureInfo ci = new CultureInfo("en-US"); cib.LoadDataFromCultureInfo(ci); RegionInfo ri = new RegionInfo("US"); cib.LoadDataFromRegionInfo(ri); cib.Register(); } InitializeComponent(); // Add handlers for window availability events AddWindowAvailabilityHandlers(); Console.WriteLine(Language); //add buttons for (int i = 0; i < 5; i++) { SurfaceButton sb = new SurfaceButton(); sb.Content = "test" + i + ".xps"; docContainer.Items.Add(sb); sb.AddHandler(SurfaceButton.ClickEvent, new RoutedEventHandler(OnButtonClick)); } }
private void BtnRegisterClick(object sender, EventArgs e) { try { var cultureInfo = cboCultures.SelectedItem as CultureInfo; if (cultureInfo != null) { var cultureAndRegionInfoBbuilder = new CultureAndRegionInfoBuilder(cultureInfo.Name, CultureAndRegionModifiers.Replacement); // load the culture info into the builder cultureAndRegionInfoBbuilder.LoadDataFromCultureInfo(cultureInfo); // load the regional info into the builder var regionInfo = new RegionInfo(cultureInfo.Name); cultureAndRegionInfoBbuilder.LoadDataFromRegionInfo(regionInfo); // set the currency symbols cultureAndRegionInfoBbuilder.ISOCurrencySymbol = txtISOCurrencySymbol.Text; cultureAndRegionInfoBbuilder.NumberFormat.CurrencySymbol = txtSymbol.Text; cultureAndRegionInfoBbuilder.Register(); MessageBox.Show(Resources.FormMain_BtnRegisterClick_Symbols_registered, Resources.FormMain_BtnRegisterClick_Info, MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show(Resources.FormMain_BtnRegisterClick_Error__ + ex.Message); } }
private static CultureInfo CreateCultureInfo() { try { return(new CultureInfo(_cultureName)); } catch (ArgumentException) { CultureAndRegionInfoBuilder cultureAndRegionInfoBuilder = new CultureAndRegionInfoBuilder(_cultureName, CultureAndRegionModifiers.None); cultureAndRegionInfoBuilder.LoadDataFromCultureInfo(CultureInfo.InvariantCulture); cultureAndRegionInfoBuilder.LoadDataFromRegionInfo(new RegionInfo("US")); cultureAndRegionInfoBuilder.ThreeLetterWindowsRegionName = "cmt"; cultureAndRegionInfoBuilder.ThreeLetterISORegionName = "cmt"; cultureAndRegionInfoBuilder.TwoLetterISORegionName = "mc"; cultureAndRegionInfoBuilder.RegionEnglishName = "Candy Mountain"; cultureAndRegionInfoBuilder.RegionNativeName = "Come inside the cave, Charlie"; cultureAndRegionInfoBuilder.NumberFormat.NegativeSign = "++--"; cultureAndRegionInfoBuilder.NumberFormat.PositiveSign = "--++"; cultureAndRegionInfoBuilder.NumberFormat.NumberDecimalSeparator = ";"; cultureAndRegionInfoBuilder.NumberFormat.NumberGroupSeparator = ":"; cultureAndRegionInfoBuilder.NumberFormat.NumberGroupSizes = new int[] { 2, 3, 4, 5 }; cultureAndRegionInfoBuilder.NumberFormat.CurrencyDecimalSeparator = ";"; cultureAndRegionInfoBuilder.NumberFormat.CurrencyGroupSeparator = ":"; cultureAndRegionInfoBuilder.NumberFormat.CurrencyGroupSizes = new int[] { 2, 3, 4, 5 }; cultureAndRegionInfoBuilder.NumberFormat.PercentDecimalSeparator = ";"; cultureAndRegionInfoBuilder.NumberFormat.PercentGroupSeparator = ":"; cultureAndRegionInfoBuilder.NumberFormat.PercentGroupSizes = new int[] { 2, 3, 4, 5 }; cultureAndRegionInfoBuilder.Register(); return(new CultureInfo(_cultureName)); } }
private static CultureInfo CreateCultureInfo() { try { return(new CultureInfo(_cultureName)); } catch (ArgumentException) { CultureAndRegionInfoBuilder cultureAndRegionInfoBuilder = new CultureAndRegionInfoBuilder(_cultureName, CultureAndRegionModifiers.None); cultureAndRegionInfoBuilder.LoadDataFromCultureInfo(CultureInfo.InvariantCulture); cultureAndRegionInfoBuilder.LoadDataFromRegionInfo(new RegionInfo("US")); cultureAndRegionInfoBuilder.ThreeLetterWindowsRegionName = "bwl"; cultureAndRegionInfoBuilder.ThreeLetterISORegionName = "bwl"; cultureAndRegionInfoBuilder.TwoLetterISORegionName = "bl"; cultureAndRegionInfoBuilder.RegionEnglishName = "Backwards Land"; cultureAndRegionInfoBuilder.RegionNativeName = "Wark"; cultureAndRegionInfoBuilder.NumberFormat.NegativeSign = "+"; cultureAndRegionInfoBuilder.NumberFormat.PositiveSign = "-"; cultureAndRegionInfoBuilder.NumberFormat.NumberDecimalSeparator = ";"; cultureAndRegionInfoBuilder.NumberFormat.NumberGroupSeparator = ":"; cultureAndRegionInfoBuilder.NumberFormat.NumberGroupSizes = new int[] { 2, 3, 4, 5 }; cultureAndRegionInfoBuilder.NumberFormat.CurrencyDecimalSeparator = ";"; cultureAndRegionInfoBuilder.NumberFormat.CurrencyGroupSeparator = ":"; cultureAndRegionInfoBuilder.NumberFormat.CurrencyGroupSizes = new int[] { 2, 3, 4, 5 }; cultureAndRegionInfoBuilder.NumberFormat.PercentDecimalSeparator = ";"; cultureAndRegionInfoBuilder.NumberFormat.PercentGroupSeparator = ":"; cultureAndRegionInfoBuilder.NumberFormat.PercentGroupSizes = new int[] { 2, 3, 4, 5 }; cultureAndRegionInfoBuilder.Register(); return(new CultureInfo(_cultureName)); } }
private static void Main(string[] args) { var currentCulture = CultureInfo.CurrentCulture; var x = 1.0 / 3; var y = 2.0 / 3; Console.WriteLine($"culture {currentCulture.IetfLanguageTag} NumberDecimalDigits {currentCulture.NumberFormat.NumberDecimalDigits} 1/3={x.ToString("f")} 2/3={y.ToString("f")}"); CultureAndRegionInfoBuilder builder = new CultureAndRegionInfoBuilder("fr-FR-Mush", CultureAndRegionModifiers.None); CultureInfo parent = new CultureInfo("fr-FR"); builder.LoadDataFromCultureInfo(parent); builder.LoadDataFromRegionInfo(new RegionInfo("FR")); builder.Parent = parent; builder.NumberFormat.NumberDecimalDigits = 4; builder.RegionNativeName = "Francais bouillie"; builder.RegionEnglishName = "French mush"; builder.Register(); /* * NumberFormatInfo nfi = (NumberFormatInfo)currentCulture.NumberFormat.Clone(); * nfi.NumberDecimalDigits = 4; * var customCulture = CultureInfo.CreateSpecificCulture(CultureInfo.CurrentCulture.Name); * customCulture.NumberFormat = nfi; * CultureInfo.CurrentCulture = customCulture; * * */ CultureInfo frMush = new CultureInfo("fr-FR-Mush"); Console.WriteLine($"culture {currentCulture.IetfLanguageTag} NumberDecimalDigits {currentCulture.NumberFormat.NumberDecimalDigits} 1/3={x.ToString("f", frMush)} 2/3={y.ToString("f", frMush)}"); Console.ReadKey(); }
static void Main() { // Create a Styria culture CultureAndRegionInfoBuilder styria = new CultureAndRegionInfoBuilder( "de-AT-ST", CultureAndRegionModifiers.None); CultureInfo parent = new CultureInfo("de-AT"); styria.LoadDataFromCultureInfo(parent); styria.LoadDataFromRegionInfo(new RegionInfo("AT")); styria.Parent = parent; styria.RegionNativeName = "Steiermark"; styria.RegionEnglishName = "Styria"; styria.CultureEnglishName = "Styria (Austria)"; styria.CultureNativeName = "Steirisch"; styria.Register(); //CultureInfo ci = new CultureInfo("de-AT-ST"); //Thread.CurrentThread.CurrentCulture = ci; //Thread.CurrentThread.CurrentUICulture = ci; //ResourceManager rm = new ResourceManager("CreateACulture.Resource1", // Assembly.GetExecutingAssembly()); //Console.WriteLine(rm.GetString("String1")); }
static void Main() { try { // Create a Styria culture var styria = new CultureAndRegionInfoBuilder("de-AT-ST", CultureAndRegionModifiers.None); var cultureParent = new CultureInfo("de-AT"); styria.LoadDataFromCultureInfo(cultureParent); styria.LoadDataFromRegionInfo(new RegionInfo("AT")); styria.Parent = cultureParent; styria.RegionNativeName = "Steiermark"; styria.RegionEnglishName = "Styria"; styria.CultureEnglishName = "Styria (Austria)"; styria.CultureNativeName = "Steirisch"; styria.Register(); } catch (UnauthorizedAccessException ex) { WriteLine(ex.Message); } catch (InvalidOperationException ex) { WriteLine(ex.Message); } ReadLine(); }
/// <summary> /// This static method creates and register a custom culture based on <see cref="Values"/> /// </summary> /// <remarks> /// <para> /// These custom cultures are necessary to make POS platform "language dependency-free" for which either the country and/or the language is not currently supported by the .NET Framework (or Windows). /// </para> /// </remarks> public static void RegisterCustomRegion() { foreach (CustomRegion customRegion in Values) { string customCultureName = customRegion.CustomCultureName; try { /* This call is necessary to erase some changes that would have be applied to a custom culture */ /* IN006018 and IN007009 */ //UnregisterCustomRegion(customCultureName); /* If for some reason a custom culture has not been removed, we will not attempt to recreate/register it */ if (!customRegionExists(customCultureName)) { var baseCultureInfo = new CultureInfo(customRegion.BaseCulture); var regionInfo = new RegionInfo(customRegion.Region); /* This block of code is responsible for POS custom region creation */ var customRegionBuilder = new CultureAndRegionInfoBuilder(customCultureName, CultureAndRegionModifiers.None); customRegionBuilder.LoadDataFromCultureInfo(baseCultureInfo); customRegionBuilder.LoadDataFromRegionInfo(regionInfo); customRegionBuilder.Register(); _log.Debug(string.Format("Custom Culture [{0}] Created and Registered Successfully", customCultureName)); } } catch (Exception e) { _log.Debug(string.Format("Error when Creating and Registering [{0}] Custom Culture: {1}", customCultureName, e)); } } }
public static CultureAndRegionInfoBuilder CreateTpCulture() { CultureAndRegionInfoBuilder cib = new CultureAndRegionInfoBuilder("x-tp", CultureAndRegionModifiers.None); CultureInfo ci = new CultureInfo("en-US"); cib.LoadDataFromCultureInfo(ci); // Populate the new CultureAndRegionInfoBuilder object with region information. RegionInfo ri = new RegionInfo("US"); cib.LoadDataFromRegionInfo(ri); //cib.CultureName = "toki pona"; cib.CultureEnglishName = "toki pona"; cib.CultureNativeName = "toki pona"; cib.CurrencyEnglishName = "mani"; cib.CurrencyNativeName = "mani"; cib.ISOCurrencySymbol = "mani"; cib.RegionEnglishName = "Land of toki pona"; //cib.RegionName = "ma pi toki pona"; cib.RegionNativeName = "ma pi toki pona"; cib.ThreeLetterISOLanguageName = "xtp"; cib.ThreeLetterISORegionName = "XTP"; cib.ThreeLetterISORegionName = "XTP"; cib.ThreeLetterWindowsLanguageName = "XTP"; cib.ThreeLetterWindowsRegionName = "XTP"; cib.TwoLetterISOLanguageName = "tp"; cib.TwoLetterISORegionName = "tp"; return(cib); }
public static void Main() { // Create a custom culture for ru-US. CultureAndRegionInfoBuilder car1 = new CultureAndRegionInfoBuilder("ru-US", CultureAndRegionModifiers.None); car1.LoadDataFromCultureInfo(CultureInfo.CreateSpecificCulture("ru-RU")); car1.LoadDataFromRegionInfo(new RegionInfo("en-US")); car1.CultureEnglishName = "Russian (United States)"; car1.CultureNativeName = "русский (США)"; car1.CurrencyNativeName = "Доллар (США)"; car1.RegionNativeName = "США"; // Register the culture. try { car1.Register(); } catch (InvalidOperationException) { // Swallow the exception: the culture already is registered. } // Use the custom culture. CultureInfo ci = CultureInfo.CreateSpecificCulture("ru-US"); Thread.CurrentThread.CurrentCulture = ci; Console.WriteLine("Current Culture: {0}", Thread.CurrentThread.CurrentCulture.Name); Console.WriteLine("Writing System: {0}", Thread.CurrentThread.CurrentCulture.TextInfo); }
public static void Create() { // Create a custom culture CultureAndRegionInfoBuilder culAndReg = new CultureAndRegionInfoBuilder("en-HU", CultureAndRegionModifiers.None); culAndReg.LoadDataFromCultureInfo(CultureInfo.CreateSpecificCulture("en-HU")); culAndReg.LoadDataFromRegionInfo(new RegionInfo("HU")); culAndReg.CultureEnglishName = "English(Hungary)"; culAndReg.CultureNativeName = "English(Hungary)"; culAndReg.CurrencyNativeName = "Hungarian Forint"; culAndReg.RegionNativeName = "Hungarian-English"; // Register the culture. try { culAndReg.Register(); Console.Write("The new Culture and region is created for {0} :" + "en-HU"); } catch (InvalidOperationException ex) { Console.Write("The Operation Failed due to " + ex.Message); } }
public static void Main() { CultureAndRegionInfoBuilder cib = null; try { // Create a CultureAndRegionInfoBuilder object named "x-en-US-sample". Console.WriteLine("Create and explore the CultureAndRegionInfoBuilder...\n"); cib = new CultureAndRegionInfoBuilder( "x-en-US-sample", CultureAndRegionModifiers.None); // Populate the new CultureAndRegionInfoBuilder object with culture information. CultureInfo ci = new CultureInfo("en-US"); cib.LoadDataFromCultureInfo(ci); // Populate the new CultureAndRegionInfoBuilder object with region information. RegionInfo ri = new RegionInfo("US"); cib.LoadDataFromRegionInfo(ri); // Display some of the properties of the CultureAndRegionInfoBuilder object. Console.WriteLine("CultureName:. . . . . . . . . . {0}", cib.CultureName); Console.WriteLine("CultureEnglishName: . . . . . . {0}", cib.CultureEnglishName); Console.WriteLine("CultureNativeName:. . . . . . . {0}", cib.CultureNativeName); Console.WriteLine("GeoId:. . . . . . . . . . . . . {0}", cib.GeoId); Console.WriteLine("IsMetric: . . . . . . . . . . . {0}", cib.IsMetric); Console.WriteLine("ISOCurrencySymbol:. . . . . . . {0}", cib.ISOCurrencySymbol); Console.WriteLine("RegionEnglishName:. . . . . . . {0}", cib.RegionEnglishName); Console.WriteLine("RegionName: . . . . . . . . . . {0}", cib.RegionName); Console.WriteLine("RegionNativeName: . . . . . . . {0}", cib.RegionNativeName); Console.WriteLine("ThreeLetterISOLanguageName: . . {0}", cib.ThreeLetterISOLanguageName); Console.WriteLine("ThreeLetterISORegionName: . . . {0}", cib.ThreeLetterISORegionName); Console.WriteLine("ThreeLetterWindowsLanguageName: {0}", cib.ThreeLetterWindowsLanguageName); Console.WriteLine("ThreeLetterWindowsRegionName: . {0}", cib.ThreeLetterWindowsRegionName); Console.WriteLine("TwoLetterISOLanguageName: . . . {0}", cib.TwoLetterISOLanguageName); Console.WriteLine("TwoLetterISORegionName: . . . . {0}", cib.TwoLetterISORegionName); Console.WriteLine(); // Register the custom culture. Console.WriteLine("Register the custom culture..."); cib.Register(); // Display some of the properties of the custom culture. Console.WriteLine("Create and explore the custom culture...\n"); ci = new CultureInfo("x-en-US-sample"); 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.WriteLine("\nNote:\n" + "Use the example in the Unregister method topic to remove the custom culture."); } catch (Exception e) { Console.WriteLine(e); } }
private static void RegisterCustomCulture(string customCultureName, string parentCultureName) { Console.WriteLine("Registering {0}", customCultureName); try { CultureAndRegionInfoBuilder cib = new CultureAndRegionInfoBuilder(customCultureName, CultureAndRegionModifiers.None); CultureInfo ci = new CultureInfo(parentCultureName); cib.LoadDataFromCultureInfo(ci); RegionInfo ri = new RegionInfo(parentCultureName); cib.LoadDataFromRegionInfo(ri); cib.Register(); Console.WriteLine("Success."); } catch (InvalidOperationException) { // This is OK, means that this is already registered. Console.WriteLine("The custom culture {0} was already registered", customCultureName); } catch (Exception ex) { Console.WriteLine("Registering the custom culture {0} failed", customCultureName); Console.WriteLine(ex); } Console.WriteLine(); }
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); } }
private void DoRegistration() { var cib = new CultureAndRegionInfoBuilder("und", CultureAndRegionModifiers.None); var ci = new CultureInfo("en-US"); cib.LoadDataFromCultureInfo(ci); var ri = new RegionInfo("US"); cib.LoadDataFromRegionInfo(ri); cib.Register(); }
public int Action() { var filePath = InputFile; if (File.Exists(filePath) == false) { filePath = Path.Combine(".", filePath); if (File.Exists(filePath) == false) { Console.WriteLine($"File not found: '{InputFile}'."); return(1); } } try { var match = _cultureRegex.Match(InputFile); if (match.Success) { var cultureName = match.Groups[1].Value; if (CultureInfo.GetCultures(CultureTypes.AllCultures).FirstOrDefault(x => x.Name.ToLowerInvariant() == cultureName.ToLowerInvariant()) != null) { Console.WriteLine($"Cannot import - culture '{cultureName}' already exists."); return(1); } // Build and register a temporary culture with the name of what we want to import. // CreateFromLdml method will fail when trying to load a culture from file if it doesn't already exist. var tempCulture = new CultureAndRegionInfoBuilder(cultureName, CultureAndRegionModifiers.None); tempCulture.LoadDataFromCultureInfo(CultureInfo.CurrentCulture); tempCulture.LoadDataFromRegionInfo(RegionInfo.CurrentRegion); tempCulture.Register(); // Now load up the culture we actually want to import var culture = CultureAndRegionInfoBuilder.CreateFromLdml(filePath); // Unregister the temporary culture CultureAndRegionInfoBuilder.Unregister(cultureName); // Register the real culture loaded from file culture.Register(); Console.WriteLine($"Culture '{culture.CultureName}' has been installed."); } } catch (Exception e) { Console.Write(e.Message); } return(0); }
public static void Main() { // 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 cib = null; try { cib = 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"); cib.LoadDataFromCultureInfo(ci); // Populate the new CultureAndRegionInfoBuilder object with region information. RegionInfo ri = new RegionInfo("US"); cib.LoadDataFromRegionInfo(ri); // Display some of the properties for the x-en-US-sample custom culture. Console.Clear(); Console.WriteLine("CultureName:. . . . . . . . . . {0}", cib.CultureName); Console.WriteLine("CultureEnglishName: . . . . . . {0}", cib.CultureEnglishName); Console.WriteLine("CultureNativeName:. . . . . . . {0}", cib.CultureNativeName); Console.WriteLine("GeoId:. . . . . . . . . . . . . {0}", cib.GeoId); Console.WriteLine("IsMetric: . . . . . . . . . . . {0}", cib.IsMetric); Console.WriteLine("ISOCurrencySymbol:. . . . . . . {0}", cib.ISOCurrencySymbol); Console.WriteLine("RegionEnglishName:. . . . . . . {0}", cib.RegionEnglishName); Console.WriteLine("RegionName: . . . . . . . . . . {0}", cib.RegionName); Console.WriteLine("RegionNativeName: . . . . . . . {0}", cib.RegionNativeName); Console.WriteLine("ThreeLetterISOLanguageName: . . {0}", cib.ThreeLetterISOLanguageName); Console.WriteLine("ThreeLetterISORegionName: . . . {0}", cib.ThreeLetterISORegionName); Console.WriteLine("ThreeLetterWindowsLanguageName: {0}", cib.ThreeLetterWindowsLanguageName); Console.WriteLine("ThreeLetterWindowsRegionName: . {0}", cib.ThreeLetterWindowsRegionName); Console.WriteLine("TwoLetterISOLanguageName: . . . {0}", cib.TwoLetterISOLanguageName); Console.WriteLine("TwoLetterISORegionName: . . . . {0}", cib.TwoLetterISORegionName); }
static void InstallCulture(string cultureId, string cultureName, string basedOn) { CultureInfo cultureInfo = new CultureInfo(basedOn); RegionInfo regionInfo = new RegionInfo(cultureInfo.Name); CultureAndRegionInfoBuilder cultureAndRegionInfoBuilder = new CultureAndRegionInfoBuilder(cultureId, CultureAndRegionModifiers.None); cultureAndRegionInfoBuilder.LoadDataFromCultureInfo(cultureInfo); cultureAndRegionInfoBuilder.LoadDataFromRegionInfo(regionInfo); cultureAndRegionInfoBuilder.CultureEnglishName = cultureName; cultureAndRegionInfoBuilder.CultureNativeName = cultureName; cultureAndRegionInfoBuilder.Register(); }
private static void Main(string[] args) { const string path = "cultures.xml"; XmlSerializer serializer = new XmlSerializer(typeof(Cultures)); StreamReader reader = new StreamReader(path); Cultures culturesImport = (Cultures)serializer.Deserialize(reader); reader.Close(); foreach (Culture culture in culturesImport.CultureList) { if (!culture.Code.CultureExists()) { try { CultureAndRegionInfoBuilder cib = new CultureAndRegionInfoBuilder(culture.Code, CultureAndRegionModifiers.None); cib.LoadDataFromCultureInfo(new CultureInfo(culture.BaseFromCode)); cib.LoadDataFromRegionInfo(new RegionInfo(culture.BaseFromRegion)); cib.CultureEnglishName = $"{culture.Language} ({culture.Country})"; cib.CultureNativeName = cib.CultureEnglishName; cib.IetfLanguageTag = culture.Code; cib.RegionEnglishName = culture.Country; cib.RegionNativeName = cib.RegionEnglishName; cib.ISOCurrencySymbol = culture.CurrencyIso; cib.NumberFormat.CurrencySymbol = culture.CurrencySymbol; cib.CurrencyEnglishName = culture.CurrencyName; cib.CurrencyNativeName = cib.CurrencyEnglishName; cib.ThreeLetterISOLanguageName = culture.ThreeLetterIsoName; cib.ThreeLetterWindowsLanguageName = culture.ThreeLetterWinName; cib.TwoLetterISOLanguageName = culture.TwoLetterIsoName; cib.Register(); Console.WriteLine(culture.Code + " => created"); } catch (Exception e) { Console.WriteLine("Could not register {0} - {1}", culture.Code, e.Message); } } else { Console.WriteLine("{0} already exsists", culture.Code); } } Console.WriteLine("Finished - press any key to exit"); Console.ReadKey(); }
private void RegisterCulture(string cultureName) { if (TryGetCultureInfo(cultureName) != null) { Log.LogMessage(MessageImportance.Low, $"Culture {cultureName} is already registered"); return; } var cultureNameParts = ParseCultureNameRegex.Match(cultureName); if (!cultureNameParts.Success) { throw new Exception($"{cultureName} is not a valid culture name"); } var baseCultureCode = cultureNameParts.Groups["culture"].Value; var regionCode = cultureNameParts.Groups["region"].Value; var baseCulture = TryGetCultureInfo(baseCultureCode); if (baseCulture == null) { throw new Exception($"Unable to find any pre-existing culture named {baseCultureCode} to load from"); } var baseRegion = TryGetRegionInfo(regionCode); var cultureType = (baseRegion == null) ? CultureAndRegionModifiers.Neutral : CultureAndRegionModifiers.None; var builder = new CultureAndRegionInfoBuilder(cultureName, cultureType); builder.LoadDataFromCultureInfo(baseCulture); builder.Parent = baseCulture; if (baseRegion != null) { builder.LoadDataFromRegionInfo(baseRegion); } builder.Register(); var culture = new CultureInfo(cultureName); string cultureTypeString = culture.IsNeutralCulture ? "neutral" : "supplemental"; Log.LogMessage(MessageImportance.High, $"Registered new {cultureTypeString} culture {cultureName} from {baseCulture.Name}"); }
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(); }
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(); }
public void CanCreateCustomCulture() { CultureAndRegionInfoBuilder builder = new CultureAndRegionInfoBuilder(CustomCultureName, CultureAndRegionModifiers.None); builder.LoadDataFromCultureInfo(CultureInfo.GetCultureInfo("en-US")); builder.LoadDataFromRegionInfo(new RegionInfo("en-US")); NumberFormatInfo numberFormat = new NumberFormatInfo(); numberFormat.CurrencyDecimalDigits = 4; numberFormat.CurrencyDecimalSeparator = "-"; numberFormat.CurrencySymbol = "@"; DateTimeFormatInfo dateTimeFormat = new DateTimeFormatInfo(); dateTimeFormat.DateSeparator = "."; dateTimeFormat.DayNames = new string[7] { "FirstDay", "SecondDay", "ThirdDay", "ForthDay", "FifthDay", "SixthDay", "SeventhDay" }; builder.NumberFormat = numberFormat; builder.GregorianDateTimeFormat = dateTimeFormat; builder.Register(); Thread.CurrentThread.CurrentCulture = new CultureInfo(CustomCultureName); string currencyString = 10000.0m.ToString("C"); Assert.That(currencyString, Is.EqualTo("@10,000-0000")); string longDatetimeString = new DateTime(2007, 10, 30).ToString("D"); Assert.That(longDatetimeString, Is.EqualTo("ThirdDay, 30 October 2007")); string shortDatetimeString = new DateTime(2007, 10, 30).ToString("d"); Assert.That(shortDatetimeString, Is.EqualTo("10.30.2007")); }
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(); }
private static void addCustomCulture(CustomCulture culture) { CultureAndRegionInfoBuilder cib = null; try { var cultures = CultureInfo.GetCultures(CultureTypes.AllCultures).ToList(); var addCulture = true; foreach (CultureInfo info in cultures) { if (string.Compare(info.Name, culture.CultureName, true) == 0) { addCulture = false; break; } } if (addCulture) { Console.WriteLine("adding culture " + culture.CultureName); cib = new CultureAndRegionInfoBuilder(culture.CultureName, CultureAndRegionModifiers.None); cib.LoadDataFromCultureInfo(new CultureInfo(culture.BaseFrom)); cib.LoadDataFromRegionInfo(new RegionInfo(culture.BaseFromReg)); cib.CultureEnglishName = culture.EnglishName; cib.CultureNativeName = culture.NativeName; cib.IetfLanguageTag = culture.CultureLangTag; cib.RegionEnglishName = culture.RegEnglishName; cib.RegionNativeName = culture.RegNativeName; cib.Register(); System.Console.WriteLine(cib.CultureName + " => created"); } else { Console.WriteLine("already exists " + culture.CultureName); } } catch (Exception e) { System.Console.WriteLine(e.Message); } }
public static String CopyMobileLocaleForSystem(string fromLocale) { String MobilePostfix = "-MOBI"; if (fromLocale.EndsWith(MobilePostfix)) { return(fromLocale); } string toLocale = fromLocale + MobilePostfix; //CultureAndRegionInfoBuilder cib = new CultureAndRegionInfoBuilder(this.MobileCultureName, CultureAndRegionModifiers.None); CultureAndRegionInfoBuilder cib = new CultureAndRegionInfoBuilder(toLocale, CultureAndRegionModifiers.None); // Populate the new CultureAndRegionInfoBuilder object with culture information. CultureInfo ci = new CultureInfo(fromLocale); cib.LoadDataFromCultureInfo(ci); // Populate the new CultureAndRegionInfoBuilder object with region information. String BaseRegion = fromLocale.Split('-')[1]; RegionInfo ri = new RegionInfo(BaseRegion); cib.LoadDataFromRegionInfo(ri); cib.CultureEnglishName = "Mobile " + cib.CultureEnglishName; cib.CultureNativeName = "Mobile " + cib.CultureNativeName; try { cib.Register(); } catch (UnauthorizedAccessException uaex) { throw uaex; } catch (Exception) {} return(fromLocale + MobilePostfix); }
private static CultureInfo CreateCultureInfo() { try { return(new CultureInfo(_cultureName)); } catch (ArgumentException) { try { CultureAndRegionInfoBuilder cultureAndRegionInfoBuilder = new CultureAndRegionInfoBuilder(_cultureName, CultureAndRegionModifiers.None); cultureAndRegionInfoBuilder.LoadDataFromCultureInfo(CultureInfo.InvariantCulture); cultureAndRegionInfoBuilder.LoadDataFromRegionInfo(new RegionInfo("US")); cultureAndRegionInfoBuilder.ThreeLetterWindowsRegionName = "bwl"; cultureAndRegionInfoBuilder.ThreeLetterISORegionName = "bwl"; cultureAndRegionInfoBuilder.TwoLetterISORegionName = "bl"; cultureAndRegionInfoBuilder.RegionEnglishName = "Backwards Land"; cultureAndRegionInfoBuilder.RegionNativeName = "Wark"; cultureAndRegionInfoBuilder.NumberFormat.NegativeSign = "+"; cultureAndRegionInfoBuilder.NumberFormat.PositiveSign = "-"; cultureAndRegionInfoBuilder.NumberFormat.NumberDecimalSeparator = ";"; cultureAndRegionInfoBuilder.NumberFormat.NumberGroupSeparator = ":"; cultureAndRegionInfoBuilder.NumberFormat.NumberGroupSizes = new int[] { 2, 3, 4, 5 }; cultureAndRegionInfoBuilder.NumberFormat.CurrencyDecimalSeparator = ";"; cultureAndRegionInfoBuilder.NumberFormat.CurrencyGroupSeparator = ":"; cultureAndRegionInfoBuilder.NumberFormat.CurrencyGroupSizes = new int[] { 2, 3, 4, 5 }; cultureAndRegionInfoBuilder.NumberFormat.PercentDecimalSeparator = ";"; cultureAndRegionInfoBuilder.NumberFormat.PercentGroupSeparator = ":"; cultureAndRegionInfoBuilder.NumberFormat.PercentGroupSizes = new int[] { 2, 3, 4, 5 }; cultureAndRegionInfoBuilder.Register(); return(new CultureInfo(_cultureName)); } catch (UnauthorizedAccessException) { Assert.Ignore("Unable to register custom culture definition. You may need to run NUnit as an administrator."); return(CultureInfo.InvariantCulture); } } }
//- creates custom culture for country identified by EIDSS country ID public static void Register(string lang, long countryID) { if (!CountryCodes.ContainsKey(countryID)) { throw new Exception(string.Format("\'{0}\' - Unsupported country ID.", countryID)); } if (!CultureExists(lang, countryID)) { throw new Exception(string.Format("Unsupported pair culture name - country ID.")); } try { string cultureName = FormCustomCultureName(lang, countryID); if ((!IsCultureRegistered(cultureName)) && Core.SupportedLanguages.All.ContainsKey(lang)) { string oldCultureName = Core.SupportedLanguages.All[lang]; CultureAndRegionInfoBuilder cib = new CultureAndRegionInfoBuilder(cultureName, CultureAndRegionModifiers.None); // Populate the new CultureAndRegionInfoBuilder object with culture information. CultureInfo ci = new CultureInfo(oldCultureName); cib.LoadDataFromCultureInfo(ci); // Populate the new CultureAndRegionInfoBuilder object with region information. RegionInfo ri = new RegionInfo(oldCultureName); cib.LoadDataFromRegionInfo(ri); cib.CultureEnglishName = GetRegistrationCultureName(lang, countryID); //"English (Georgia)"; cib.CultureNativeName = GetRegistrationCultureName(lang, countryID); cib.RegionNativeName = GetRegistrationCultureName(lang, countryID); cib.RegionEnglishName = GetRegistrationCultureName(lang, countryID); cib.Parent = ci; cib.Register(); } } catch (Exception e) { Debug.WriteLine("can't register custom culture {0}-{1}", lang, countryID); Debug.WriteLine("error: {0}", e); } }
/** * Method to create a new culture either by mixing or inheriting from the * InvariantCulture */ public void GetNewCultureInfo(NumberFormatInfo numberFormat, DateTimeFormatInfo dateFormat, string locale, string name) { try { CultureInfo ci = new CultureInfo(locale); RegionInfo ri; //In case the locale name is empty as is for Invariant culture if (locale.Length == 0) { ri = RegionInfo.CurrentRegion; } else { ri = new RegionInfo(locale); } // See if we're neutral CultureAndRegionModifiers mods = CultureAndRegionModifiers.None; if (name.IndexOf('-') < 0) { mods |= CultureAndRegionModifiers.Neutral; } // See if we already have one try { CultureInfo test = CultureInfo.GetCultureInfo(name); mods |= CultureAndRegionModifiers.Replacement; } catch (System.ArgumentException) { // name doesn't exist (yet) } //Use the builder to register the culture CultureAndRegionInfoBuilder cib = new CultureAndRegionInfoBuilder( name, mods); cib.LoadDataFromCultureInfo(ci); cib.LoadDataFromRegionInfo(ri); cib.NumberFormat = numberFormat; cib.GregorianDateTimeFormat = dateFormat; cib.IetfLanguageTag = name; cib.Register(); //Add the new culture using the DisplayCulture Add(name); MessageBox.Show(Constants.SuccessMessage); } catch (System.IO.IOException) { //The .nlp file already exists MessageBox.Show(Constants.ErrorFileFound); } catch (System.ArgumentOutOfRangeException ex) { MessageBox.Show(ex.ToString()); } }