在Abp框架中使用格里高利日期和非英语文化.NET核心3



当更改ASP.net样板文件(带Angular的.net core 3(中的语言时,UI中的日期已更改为Ar Culture我想将格里高利日期与Ar Cultural一起使用。有没有任何没有很多变通办法的直接解决方案我在下面找到了建议解决方案,但我不喜欢这样的解决方案

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

编辑(更多详细信息(:

在Abp框架中有一个多语言选项,所以当我将语言切换到阿拉伯语时,整个系统文化切换到具有Hijri日期格式的阿拉伯文化,我想将系统切换到具有gregorian日期的阿拉伯文化,我该怎么做?如果有自定义代码,我应该把它放在哪里(例如在Startup.cs类中(,因为我尝试过自定义代码,但系统在Startup.chs类的配置函数中不接受它

Startup.cs类代码

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
}

我找到了解决方案(简单的变通解决方案(:

首先,如果你想了解与日期和日历相关的丰富信息,请查看此链接,但我所做的是:

1-转到AbpLanguages数据库表并删除所有记录。

2-在DefaultLanguagesCreator类中,将ar更改为ar EG,因为ar区域性的默认日历是System。全球化UmAlQuraCalendar但ar EG区域性它的默认日历是系统。全球化GregorianCalendar(我想要的日历(

3-然后清洁,重建解决方案。

4-不要忘记将XML本地化文件中的区域性更改为ar EG

最新更新