1
我一直在使用以下設置我的以前的應用程序的web.config
。<system.web>全球化在.net核心
<system.web>
<globalization culture="en-AU" uiCulture="en-AU" />
</system.web>
現在在我的新的.NET的核心項目,我不知道如何把這個設置在appsettings.json
文件。
感謝您的幫助, 尼古拉
我一直在使用以下設置我的以前的應用程序的web.config
。<system.web>全球化在.net核心
<system.web>
<globalization culture="en-AU" uiCulture="en-AU" />
</system.web>
現在在我的新的.NET的核心項目,我不知道如何把這個設置在appsettings.json
文件。
感謝您的幫助, 尼古拉
的定位在Startup class
配置,並且可以在整個應用程序中使用。在ConfigureServices
中使用AddLocalization
方法來定義資源和本地化。這可以在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;
});
}
感謝您的支持。 :) – Nik