2016-12-16 45 views
1

我一直在使用以下設置我的以前的應用程序的web.config<system.web>全球化在.net核心

<system.web> 
    <globalization culture="en-AU" uiCulture="en-AU" /> 
</system.web> 

現在在我的新的.NET的核心項目,我不知道如何把這個設置在appsettings.json文件。

感謝您的幫助, 尼古拉

回答

4

的定位在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; 
        }); 
} 
+1

感謝您的支持。 :) – Nik