我有asp.net核心应用程序,我想本地化和翻译(v 1.1.0)。我希望源代码支持英语和挪威语部署,我发现这可能是startup.cs配置
RequestLocalizationOptions localizationOptions = new RequestLocalizationOptions
{
SupportedCultures = new List<CultureInfo> { new CultureInfo("en-US"), new CultureInfo("nb-NO") },
SupportedUICultures = new List<CultureInfo> { new CultureInfo("en-US"), new CultureInfo("nb-NO") },
DefaultRequestCulture = new RequestCulture("nb-NO")
};
app.UseRequestLocalization(localizationOptions);
但是我希望每个部署只有一种文化和一种ui文化,所以我希望找到一种方法来在appsettings.json或环境变量中设置文化和ui文化。有可能吗?
答案 0 :(得分:8)
不确定
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);