Nik*_*Nik 2 c# globalization culture web-config asp.net-core
我一直在使用以下设置web.config我以前的应用程序.
<system.web>
<globalization culture="en-AU" uiCulture="en-AU" />
</system.web>
Run Code Online (Sandbox Code Playgroud)
现在在我的新.net核心项目中,我不知道如何将此设置放在appsettings.json文件中.
谢谢你的帮助,尼古拉
本地化配置在Startup class整个应用程序中并可以使用.该AddLocalization方法用于ConfigureServices定义资源和本地化.然后可以在Configure方法中使用它.这里,RequestLocalizationOptions可以使用该UseRequestLocalization方法定义并添加到堆栈中.
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;
});
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3441 次 |
| 最近记录: |