Posts

....
Technical Blog for .NET Developers ©

Monday, January 4, 2021

Creating and Extending Cultures

When we are making use of Resources in order to display tags of different languages, we may need different displays for the same culture, depending on a specific area (i.e. dialects), or customizations in the content depending on the requirements

Registering a new culture is an action which requires admin privileges elevated, ideally from cmd. You have more info in MSDN

In this post we are extending an existing culture, and testing the customizations on the new culture. We are making use of System.Globalization namespace, and additionally adding a reference to sysglobl assembly



The code for registering the culture begins with the creation of the culture in disk


        CreateCultureAndSaveIt(@"D:\culture.xml");



This is the implementation:


        private static void CreateCultureAndSaveIt(string fileName)
        {
            CultureAndRegionInfoBuilder builder = new CultureAndRegionInfoBuilder("en-US-NY", CultureAndRegionModifiers.Neutral);

            CultureInfo parent = new CultureInfo("en-US");
            builder.LoadDataFromCultureInfo(parent);
            builder.LoadDataFromRegionInfo(new RegionInfo("US"));
            builder.Parent = parent;

            builder.RegionEnglishName = "New York";
            builder.RegionNativeName = "New York";
            builder.CultureEnglishName = "New York (United States)";
            builder.CultureNativeName = "New York (United States)";
            builder.NumberFormat.CurrencySymbol = "*";

            builder.Save(fileName);
        }



This method has created an xml file with the customizations specified



The next step is loading the culture into the system, this is made reading the ldml (language definition markup language) defined in the xml


            LoadCultureAndRegisterIt(fileName);



With the next implementation:


        private static void LoadCultureAndRegisterIt(string fileName)
        {
            CultureAndRegionInfoBuilder builder = CultureAndRegionInfoBuilder.CreateFromLdml(fileName);
            builder.Register();
        }



As result we have the culture installed into the system, in Windows/Globalization dir



Now it's time to test the new culture

Our web site has 2 sets of resources, and the next code in the index view







Sunday, January 3, 2021

Rosetta Code

This post is an implementation of this theorem proposed by RosettaCode.org, titled 100 doors



The only doors that remain open are those whose numbers are perfect squares.
Opening only those doors is an optimization that may also be expressed; however, as should be obvious, this defeats the intent of comparing implementations across programming languages.

I wrote the next algorithm in F#, with a slight difference which lead me to discover also the theorem of the distribution of odd numbers

The type Door:



The implementation of Visit Doors, and Set Matrix Doors:



The use of this algorithm is with C#, with a set of 1000 doors to review the results



Notice the distribution patterns of odds, fibonacci, and perfect square numbers on the board




METHOD SOFTWARE