Some cultures uses calendars other than Gregorian like Hijri and Hebrew, here we will see how to force Gregorian calendar for other cultures as well.
This post is a part of series of posts regarding Building Multi Cultural Web Applicaton With ASP.NET Razor Pages 2.1, but you may apply this to other projects as well.
If you are working on a multi language web application, you may noticed that some cultures has different calendars like Arabic which uses Hijri calendar. In fact, practicaly a lot of Arabic countries are using Gregorian calendar, so we want our web application to use Arabic culture with gregorian calendar.
In a Razor Pages web application we configure services for request localization in the startup file, just add gregorian calendar to the culture you want in the supported cultures list as below :
/* startup.cs --> ConfigureServices */
var cultures = new CultureInfo[]
{
new CultureInfo("en"),
new CultureInfo("tr"),
new CultureInfo("ar") { DateTimeFormat = { Calendar = new GregorianCalendar() } }
};
services.Configure(ops =>
{
ops.DefaultRequestCulture = new RequestCulture("en");
ops.SupportedCultures = cultures;
ops.SupportedUICultures = cultures;
// add RouteValueRequestCultureProvider to the beginning of the providers list.
ops.RequestCultureProviders.Insert(0, new RouteValueRequestCultureProvider());
});