Search code examples
asp.net-coreaspnetboilerplateasp.net-boilerplate

Use Gregorian Date with non English Culture in Abp framework .NET Core 3


When changing the language in ASP.net boilerplate (.NET core 3 with Angular) the date in the UI has been changed to Ar Culture I wanna use Gregorian Date with Ar Culture. Is there any straight forward solution without lots of workarounds I found below suggestions solution but I don't prefer such that solutions

https://forum.aspnetboilerplate.com/viewtopic.php?p=26993

Edited (more details):

in Abp framework there is a multi-language option, So when I switch the language to Arabic the whole system culture switched to Arabic culture with Hijri date format, I want to change the system to Arabic culture with gregorian date, How Could I do that and if there is a customized code where should I put it (for example in Startup.cs class) because I've tried customized code but the system didn't accept it in Configure Function in Startup.cs class

Startup.cs class code

 public void Configure(IApplicationBuilder app,  ILoggerFactory loggerFactory)
        {
/*****************************************************************************/

            CultureInfo myCIintl = new CultureInfo("ar-SA", false);
            Calendar[] myOptCals = new CultureInfo("ar-SA").OptionalCalendars;
            // Checks which ones are GregorianCalendar then determines the GregorianCalendar version.
            Console.WriteLine("The ar-SA culture supports the following calendars:");
            foreach (Calendar cal in myOptCals)
            {

                if (cal.GetType() == typeof(GregorianCalendar))
                {

                    GregorianCalendar myGreCal = (GregorianCalendar)cal;
                    myCIintl.DateTimeFormat.Calendar = myGreCal;
                    GregorianCalendarTypes calType = myGreCal.CalendarType;
                    Console.WriteLine("   {0} ({1})", cal, calType);
                }
                else
                {
                    Console.WriteLine("   {0}", cal);
                }
            }
/*****************************************************************************/

            app.UseAbp(options => { options.UseAbpRequestLocalization = false; }); // Initializes ABP framework.

            app.UseCors(_defaultCorsPolicyName); // Enable CORS!

            app.UseStaticFiles();

            app.UseRouting();

            app.UseAuthentication();

            app.UseAbpRequestLocalization();


            app.UseEndpoints(endpoints =>
            {
                endpoints.MapHub<AbpCommonHub>("/signalr");
                endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}");
                endpoints.MapControllerRoute("defaultWithArea", "{area}/{controller=Home}/{action=Index}/{id?}");
            });

            // Enable middleware to serve generated Swagger as a JSON endpoint
            app.UseSwagger();
            // Enable middleware to serve swagger-ui assets (HTML, JS, CSS etc.)
            app.UseSwaggerUI(options =>
            {
                options.SwaggerEndpoint(_appConfiguration["App:ServerRootAddress"].EnsureEndsWith('/') + "swagger/v1/swagger.json", "MyApp API V1");
                options.IndexStream = () => Assembly.GetExecutingAssembly()
                    .GetManifestResourceStream("MyApp .Web.Host.wwwroot.swagger.ui.index.html");
            }); // URL: /swagger
        }

Solution

  • I found the solution (easy workaround solution):

    first of all, if you want a rich of information related to date and calendar review this link but what I did is:

    1- Go to AbpLanguages database table and delete all records.

    2- In DefaultLanguagesCreator class change the ar to ar-EG because the default calendar for ar Culture is System.Globalization.UmAlQuraCalendar but ar-EG culture the default calendar for it is System.Globalization.GregorianCalendar (the calendar that I want)

    3- then clean, rebuild the solution.

    4- Don't forget to change the culture inside the XML localization file to ar-EG.