本文介绍了在appsettings.json(asp.net核心本地化)中设置区域性和ui-culture吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有要定位和翻译(v 1.1.0)的asp.net核心应用程序.我希望源代码支持英语和挪威语部署,而我发现这可能是startup.cs配置
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 could be a startup.cs configuration
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文化.有可能吗?
However I want to have only one culture and one ui-culture for each deployment, so I hoped to find out a way to set culture and ui-culture in appsettings.json or enviroment variables. Is it possible?
推荐答案
可以.
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);
这篇关于在appsettings.json(asp.net核心本地化)中设置区域性和ui-culture吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!