![](/img/trans.png)
[英]AdWords SDK looks for System.Web reference in .net core app
[英]<system.web> globalization in .net core
我一直在使用以下設置我以前的應用程序的web.config
。
<system.web>
<globalization culture="en-AU" uiCulture="en-AU" />
</system.web>
現在,在新的.net核心項目中,我不知道如何將此設置放入appsettings.json
文件中。
感謝您的幫助,尼古拉
本地化在Startup class
配置,並且可以在整個應用程序中使用。 在ConfigureServices
使用AddLocalization
方法定義資源和本地化。 然后可以在Configure方法中使用它。 此處,可以使用UseRequestLocalization
方法定義RequestLocalizationOptions
並將其添加到堆棧中。
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;
});
}
將這兩行添加到ConfigureServices中似乎具有所需的效果:
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("en-AU");
System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-AU");
我嘗試了一個經過認可的答案:首先,它需要一個LanguageActionFilter類,它不是標准的.net核心類,其后,出於使用首選區域性而不是系統默認區域性的簡單目的,它不起作用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.