Set culture and ui-culture in appsettings.json (asp.net core localization)?

后端 未结 1 812
旧巷少年郎
旧巷少年郎 2021-01-18 06:15

I have asp.net core application which I want to localize and translate (v 1.1.0). I want the source code to support both english and norwegian deployments, and I found this

相关标签:
1条回答
  • 2021-01-18 07:04

    Sure.

    appsettings.json:

    {
        "SiteLocale" : "en-US"
    }
    

    Startup.cs:

    var locale = Configuration["SiteLocale"];
    RequestLocalizationOptions localizationOptions = new RequestLocalizationOptions
    {
        SupportedCultures = new List<CultureInfo> { new CultureInfo(locale) },
        SupportedUICultures = new List<CultureInfo> { new CultureInfo(locale) },
        DefaultRequestCulture = new RequestCulture(locale)
    };
    app.UseRequestLocalization(localizationOptions);
    
    0 讨论(0)
提交回复
热议问题