< system.web> .net核心中的全球化 [英] <system.web> globalization in .net core
问题描述
我一直在使用以下设置来设置上一个应用程序的web.config
.
I have been using the following setting the the web.config
of my previous application.
<system.web>
<globalization culture="en-AU" uiCulture="en-AU" />
</system.web>
现在在新的.net核心项目中,我不知道如何将此设置放入appsettings.json
文件中.
Now in my new .net core project I don't know how to put this setting in the appsettings.json
file.
感谢您的帮助, 尼古拉
Thanks for your help, Nikolai
推荐答案
本地化是在Startup class
中配置的,可以在整个应用程序中使用. ConfigureServices
中使用AddLocalization
方法来定义资源和本地化.然后可以在Configure方法中使用它.在这里,可以定义RequestLocalizationOptions
,并使用UseRequestLocalization
方法将其添加到堆栈中.
The localization is configured in the Startup class
and can be used throughout the application. The AddLocalization
method is used in the ConfigureServices
to define the resources and localization. This can then be used in the Configure method. Here, the RequestLocalizationOptions
can be defined and is added to the stack using the UseRequestLocalization
method.
public void ConfigureServices(IServiceCollection services)
{
services.AddLocalization(options => options.ResourcesPath = "Resources");
services.AddMvc()
.AddViewLocalization()
.AddDataAnnotationsLocalization();
services.AddScoped<LanguageActionFilter>();
services.Configure<RequestLocalizationOptions>(
options =>
{
var supportedCultures = new List<CultureInfo>
{
new CultureInfo("en-US"),
new CultureInfo("de-CH"),
new CultureInfo("fr-CH"),
new CultureInfo("it-CH")
};
options.DefaultRequestCulture = new RequestCulture(culture: "en-US", uiCulture: "en-US");
options.SupportedCultures = supportedCultures;
options.SupportedUICultures = supportedCultures;
});
}
这篇关于< system.web> .net核心中的全球化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!