abp (.net 5)设置默认请求语言为简体中文

https://docs.microsoft.com/en-us/aspnet/core/fundamentals/localization?view=aspnetcore-5.0

默认有3个provider, 移除AcceptLanguageHeaderRequestCultureProvider就可以了

对于Abp, 有UseAbpRequestLocalization方法

app.UseAbpRequestLocalization(options =>
{
    options.RequestCultureProviders = options.RequestCultureProviders.Where(a=> !(a is AcceptLanguageHeaderRequestCultureProvider)).ToList();
    options.SetDefaultCulture("zh-Hans");
});

 

如果是普通的.net 5应用则用UseRequestLocalization方法

app.UseRequestLocalization(options =>
{
    options.RequestCultureProviders = options.RequestCultureProviders.Where(a=> !(a is AcceptLanguageHeaderRequestCultureProvider)).ToList();
    options.SetDefaultCulture("zh-Hans");
});

 

而在abp vNext中目前生效的办法为在xxxHostModule.cs中增加

public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
 context.ServiceProvider.GetRequiredService<ISettingDefinitionManager>().Get(LocalizationSettingNames.DefaultLanguage).DefaultValue = "zh-Hans";
}

 

posted @ 2021-12-03 17:03  turingguo  阅读(305)  评论(0编辑  收藏  举报