我有想要本地化和翻译的 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-culture,所以我希望找到一种在 appsettings.json 或环境变量中设置文化和 ui-culture 的方法。是否可以?
最佳答案
当然。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);
关于localization - 在 appsettings.json(asp.net 核心本地化)中设置文化和 ui-culture?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41336783/