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); } }
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); } }
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; } } }
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); } }