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(); }
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(); }
public static RegistrationResults RegisterCultureBasedOn(string newCultureCode, CultureInfo baseCulture, RegionInfo baseRegionInfo) { if (string.IsNullOrEmpty(newCultureCode) || baseCulture == null || baseRegionInfo == null) { return RegistrationResults.WrongCultureFromat; } try { var cultureInfoBuilder = new CultureAndRegionInfoBuilder(newCultureCode, CultureAndRegionModifiers.Neutral); cultureInfoBuilder.LoadDataFromCultureInfo(baseCulture); cultureInfoBuilder.LoadDataFromRegionInfo(baseRegionInfo); cultureInfoBuilder.Register(); } catch (Exception ex) { return RegistrationResults.AlreadyRegistered; } return RegistrationResults.JustRegistered; }
static void Main(string[] args) { // Create a CultureAndRegionIngoBuilder object CultureAndRegionInfoBuilder cib = new CultureAndRegionInfoBuilder("en-PL", CultureAndRegionModifiers.None); // Populate the new CultureAndRegionInfoBuilder object with culture information cib.LoadDataFromCultureInfo(new CultureInfo("en-US")); // Populate the new CultureAndRegionInfoBuilder object with region information. cib.LoadDataFromRegionInfo(new RegionInfo("US")); // Define culture specific settings. cib.CultureEnglishName = "Pig Latin"; cib.CultureNativeName = "Igpay Atinlay"; cib.IsMetric = true; cib.ISOCurrencySymbol = "PLD"; cib.RegionEnglishName = "Pig Latin Region"; cib.RegionNativeName = "Igpay Atinlay Egionray"; // Register the customer culture (requires administrative privilieges). //cib. //cib.Register(); // Display some of the properties of the custom culture. CultureInfo ci = new CultureInfo("en-PL"); 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); }
public void RegisterCulture() { try { var cultureBuilder = new CultureAndRegionInfoBuilder("en-UG", CultureAndRegionModifiers.None); cultureBuilder.LoadDataFromCultureInfo(new CultureInfo("en-GB")); cultureBuilder.LoadDataFromRegionInfo(new RegionInfo("GB")); cultureBuilder.CultureEnglishName = "Uganda (English)"; cultureBuilder.RegionNativeName = "Uganda"; cultureBuilder.ISOCurrencySymbol = "UGX"; cultureBuilder.NumberFormat.CurrencySymbol = "USh"; cultureBuilder.Register(); } catch (Exception ex) { Console.Write(ex.Message); } }
private static void DisplayCultureAndRegionInfoBuilderInformation(CultureAndRegionInfoBuilder cib) { // 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(); }
protected override void Load(ContainerBuilder builder) { base.Load(builder); builder .Register<ScreenshotTool>(c => new ScreenshotTool()) .As<IScreenshotTool>() .SingleInstance(); builder .RegisterCmdLineAction("register-pseudo-culture", "Installs the pseudo culture de-PZ with the current cultures defaults. Must be run with elevated windows priviledges. Don't forget to restart Visual Studio to apply the new culture.", scope => { CultureAndRegionInfoBuilder cib = new CultureAndRegionInfoBuilder("x-zb-Pseudo", CultureAndRegionModifiers.None); cib.LoadDataFromCultureInfo(CultureInfo.CurrentCulture); cib.LoadDataFromRegionInfo(RegionInfo.CurrentRegion); cib.Register(); Logging.Server.Info("pseudo-culture sucessfully registered."); }); }
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); } }
public static void Register(CultureAndRegionInfoBuilder builder) { builder.Register(); }
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 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; } } }
/// <summary> /// Creates a CultureAndRegionInfoBuilder object for the NCLDR culture /// </summary> /// <param name="cldrCultureName">The name of the CLDR culture from which to create the .NET culture</param> /// <param name="dotNetCultureName">The name of the .NET custom culture to create</param> /// <returns>A CultureAndRegionInfoBuilder object for the NCLDR culture</returns> public static CultureAndRegionInfoBuilder CreateNCldrCultureAndRegionInfoBuilder(string cldrCultureName, string dotNetCultureName) { Culture culture = Culture.GetCulture(cldrCultureName); CultureAndRegionModifiers cultureAndRegionModifiers = culture.IsNeutralCulture ? CultureAndRegionModifiers.Neutral : CultureAndRegionModifiers.None; CultureAndRegionInfoBuilder builder = new CultureAndRegionInfoBuilder(dotNetCultureName, cultureAndRegionModifiers); CultureInfo parentCultureInfo = GetParentCultureInfo(culture); builder.Parent = parentCultureInfo; builder.CultureEnglishName = culture.EnglishName; if (string.IsNullOrEmpty(culture.NativeName)) { builder.CultureNativeName = culture.EnglishName; } else { builder.CultureNativeName = culture.NativeName; } builder.TwoLetterISOLanguageName = culture.Identity.Language.Id; // CLDR does not have data for ThreeLetterISOLanguageName but one must be assigned for the culture to be valid builder.ThreeLetterISOLanguageName = culture.Identity.Language.Id; // CLDR does not have data for ThreeLetterWindowsLanguageName but one must be assigned for the culture to be valid builder.ThreeLetterWindowsLanguageName = culture.Identity.Language.Id; // The CultureAndRegionInfoBuilder requires dummy values for these properties // even though there is no region or currency values builder.RegionEnglishName = "xxx"; builder.RegionNativeName = "xxx"; builder.ThreeLetterISORegionName = "xxx"; builder.ThreeLetterWindowsRegionName = "xxx"; builder.TwoLetterISORegionName = "xx"; builder.ISOCurrencySymbol = "xx"; builder.CurrencyEnglishName = "xxx"; builder.CurrencyNativeName = "xxx"; if (culture.Identity.Region != null) { Region region = culture.Identity.Region; builder.RegionEnglishName = region.EnglishName; string regionNativeName = region.DisplayName(culture.Identity.Language.Id); if (string.IsNullOrEmpty(regionNativeName)) { builder.RegionNativeName = region.EnglishName; } else { builder.RegionNativeName = regionNativeName; } RegionCode regionCode = RegionExtensions.GetRegionCode(region.Id); if (regionCode != null && regionCode.Alpha3 != null) { builder.ThreeLetterISORegionName = regionCode.Alpha3; } else { builder.ThreeLetterISORegionName = region.Id; } // CLDR does not have data for ThreeLetterWindowsRegionName but one must be assigned for the culture to be valid builder.ThreeLetterWindowsRegionName = region.Id; builder.TwoLetterISORegionName = region.Id; builder.IsMetric = RegionExtensions.GetMeasurementSystem(region.Id).IsMetric; } else { builder.IsMetric = RegionExtensions.GetMeasurementSystem(NCldr.RegionIdForTheWorld).IsMetric; } // CLDR does not have data for KeyboardLayoutId or GeoId builder.IetfLanguageTag = cldrCultureName; builder.GregorianDateTimeFormat = CreateDateTimeFormatInfo(culture); builder.AvailableCalendars = GetAvailableCalendars(culture); builder.NumberFormat = CreateNumberFormatInfo(culture); if (culture.Numbers != null && culture.Numbers.CurrencyDisplayNameSets != null) { string currencyName = culture.Numbers.CurrentCurrencyPeriod.Id; if (!string.IsNullOrEmpty(currencyName)) { builder.ISOCurrencySymbol = currencyName; builder.CurrencyEnglishName = CultureExtensions.GetCurrencyDisplayName(currencyName, "en"); string currencyNativeName = CultureExtensions.GetCurrencyDisplayName(currencyName, culture.Identity.Language.Id); builder.CurrencyNativeName = currencyNativeName == null ? builder.CurrencyEnglishName : currencyNativeName; } } builder.TextInfo = parentCultureInfo.TextInfo; builder.CompareInfo = parentCultureInfo.CompareInfo; return builder; }
// Constructor. public UserDefinedCultureInfo(CultureAndRegionInfoBuilder builder) #if CONFIG_REFLECTION : base(builder.templateCulture.LCID, builder.templateCulture.UseUserOverride) #else : base(builder.templateCulture.GetHashCode(),
static void Main(string[] args) { CultureAndRegionInfoBuilder cib = null; try { // Create a CultureAndRegionInfoBuilder object named "x-en-US-sample". Console.WriteLine("Create and explore the CultureAndRegionInfoBuilder...\n"); cib = new CultureAndRegionInfoBuilder(customCultureLanguageCode, CultureAndRegionModifiers.None); // Populate the new CultureAndRegionInfoBuilder object with culture information. var defaultCulture = new CultureInfo("en-US"); Console.WriteLine("Culture to base custom culture on (\"en-US\")..."); DisplayCultureInformation(defaultCulture); cib.LoadDataFromCultureInfo(defaultCulture); Console.WriteLine("Displaying region information for Spain"); DisplayRegionInformation(new RegionInfo("ES")); Console.WriteLine("Displaying region information for Puerto Rico"); DisplayRegionInformation(new RegionInfo("PR")); Console.WriteLine("Displaying region information for the United Kingdom"); DisplayRegionInformation(new RegionInfo("GB")); var ri = new RegionInfo("CH"); Console.WriteLine("Displaying region information for Switzerland"); DisplayRegionInformation(ri); cib.LoadDataFromRegionInfo(ri); // Set the name up for the custom name. cib.CultureEnglishName = cib.CultureNativeName = "English (Switzerland)"; cib.ThreeLetterWindowsLanguageName = "END"; Console.WriteLine("Custom Culture Information..."); DisplayCultureAndRegionInfoBuilderInformation(cib); var ukCib = new CultureAndRegionInfoBuilder("en-GB", CultureAndRegionModifiers.Replacement); ukCib.LoadDataFromRegionInfo(new RegionInfo("GB")); DisplayCultureAndRegionInfoBuilderInformation(ukCib); // Register the custom culture. Console.WriteLine("Register the custom culture...\n"); cib.Register(); // Display some of the properties of the custom culture. Console.WriteLine("Create and explore the English (United Kingdom) culture...\n"); DisplayCultureInformation(new CultureInfo("en-gb")); Console.WriteLine("Create and explore the custom culture...\n"); DisplayCultureInformation(new CultureInfo(customCultureLanguageCode)); Console.WriteLine("Create and explore the Spanish (Spain) culture...\n"); DisplayCultureInformation(new CultureInfo("es")); Console.WriteLine("Create and explore the Spanish (Puerto Rico) culture...\n"); DisplayCultureInformation(new CultureInfo(puertoRicoLanguageCode)); //var rm = new ResourceManager("CustomCultureTest.App_GlobalResources.resources", Assembly.GetExecutingAssembly()); var rm = new CustomResourceManager("CustomCultureTest.App_GlobalResources.resources", Assembly.GetExecutingAssembly()); CultureInfo strCulture; String output; strCulture = new CultureInfo(customCultureLanguageCode); output = rm.GetString("Default", strCulture); Console.WriteLine("The current culture: {0}", strCulture.Name); Console.WriteLine("The value for the resource key... <{0}>\n", output); strCulture = new CultureInfo(puertoRicoLanguageCode); output = rm.GetString("Default", strCulture); Console.WriteLine("The current culture: {0}", strCulture.Name); Console.WriteLine("The value for the resource key... <{0}>\n", output); strCulture = new CultureInfo("en-GB"); output = rm.GetString("Default", strCulture); Console.WriteLine("The current culture: {0}", strCulture.Name); Console.WriteLine("The value for the resource key... <{0}>\n", output); Console.WriteLine("\nNote:\n" + "Use the example in the Unregister method topic to remove the custom culture."); } catch (Exception e) { if (Debugger.IsAttached) Debugger.Break(); Console.WriteLine(e); } finally { try { CultureAndRegionInfoBuilder.Unregister(customCultureLanguageCode); } catch { } } }
static void Main(string[] args) { string cultureName = "la-IT"; // A base culture that we can adapt for our own culture. CultureInfo ci = new CultureInfo("it-IT"); // Grab the region info too. RegionInfo ri = new RegionInfo(ci.Name); // Create the custom culture. CultureAndRegionInfoBuilder builder = new CultureAndRegionInfoBuilder("la-IT", CultureAndRegionModifiers.None); builder.LoadDataFromCultureInfo(ci); builder.LoadDataFromRegionInfo(ri); // Customization. You can use any way you prefer to load the data, XML, json, INI, database... Or better, in LDML format that we'll save later. builder.CultureEnglishName = "Latin"; builder.CultureNativeName = "Latina"; builder.CurrencyEnglishName = "Lira"; builder.CurrencyNativeName = "Lira"; builder.RegionEnglishName = "Italy"; builder.RegionNativeName = "Italia"; builder.ThreeLetterISOLanguageName = "lat"; builder.ThreeLetterISORegionName = "ita"; builder.ThreeLetterWindowsLanguageName = "LAT"; builder.ThreeLetterWindowsRegionName = "ITA"; builder.TwoLetterISOLanguageName = "la"; builder.TwoLetterISORegionName = "it"; // Save the custom info in LDML (XML) format to share. string outputDir = DateTime.Now.Ticks.ToString(); Directory.CreateDirectory(outputDir); string ldmlFileName = cultureName + ".LDML"; builder.Save(Path.Combine(outputDir, ldmlFileName)); // Save nlp file and registry tokens. Requires administrator priviledge. try { // Register in current system to make it work. builder.Register(); // Example to use the new culture through the name because all custom cultures share LCID 4096 (0x1000). ci = new CultureInfo(cultureName); string nlpFileName = cultureName + ".nlp"; string nlpFilePath = Path.Combine(Environment.GetEnvironmentVariable("WinDir"), "Globalization", nlpFileName); if (File.Exists(nlpFilePath)) { File.Copy(nlpFilePath, Path.Combine(outputDir, nlpFileName)); } else { throw new FileNotFoundException("nlp file doesn't exist, custom culture register failed", nlpFilePath); } // TODO: export reg doesn't work as expected yet. string registryToken = @"HKLM\SYSTEM\CurrentControlSet\Control\Nls\CustomLocale"; string registryFileName = cultureName + ".reg"; string[] arguments = { "export", registryToken, Path.Combine(outputDir, registryFileName) }; ProcessStartInfo process = new ProcessStartInfo("REG.exe", string.Join(" ", arguments)); Process.Start(process); } catch (Exception e) { Console.WriteLine(e.Message); while (!Exception.Equals(e.InnerException, null)) { e = e.InnerException; Console.WriteLine(e.Message); } } finally { // In fact, copy nlp file and import the registry tokens will enable the custom culture without the needs to run any program in administrator priviledge. // Once the necessary files are stored, feel free to revert the change to system. CultureAndRegionInfoBuilder.Unregister(cultureName); } }