我想在我的申请中允许所有的文化。正如你在下面所看到的,我只允许少数文化。而且我有一个定制的提供者,它可以获得用户的文化。如果他的文化不在SupportedCultures中,那就意味着我无法处理他的文化(即使我可以)。在指定SupportedCultures之前,我不知道将支持什么区域性。
例如,GetTheUserCulture()返回"de“。当我稍后尝试使用区域性时,它将返回到默认语言(在本例中为“en”)。或者我希望它是“德”。
有没有办法允许所有的文化?
const string defaultCulture = "en";
services.Configure<RequestLocalizationOptions>(options =>
{
var supportedCultures = new[]
{
new CultureInfo(defaultCulture),
new CultureInfo("fr-FR"),
new CultureInfo("fr"),
new CultureInfo("es"),
new CultureInfo("ru"),
new CultureInfo("ja"),
new CultureInfo("ar"),
new CultureInfo("zh"),
new CultureInfo("en-GB"),
new CultureInfo("en-UK")
};
options.DefaultRequestCulture = new RequestCulture(defaultCulture);
options.SupportedCultures = supportedCultures;
options.SupportedUICultures = supportedCultures;
options.RequestCultureProviders.Insert(0, new CustomRequestCultureProvider(async context =>
{
return new ProviderCultureResult(GetTheUserCulture());
}));
});发布于 2020-02-04 16:24:12
我们可以使用CultureInfo检索所有区域性,然后将其添加到SupportedCultures中。看起来是这样的:
services.Configure<RequestLocalizationOptions>(options =>
{
CultureInfo[] supportedCultures = CultureInfo.GetCultures(CultureTypes.AllCultures & ~CultureTypes.NeutralCultures)
.Where(cul => !String.IsNullOrEmpty(cul.Name))
.ToArray();
options.DefaultRequestCulture = new RequestCulture(defaultCulture);
options.SupportedCultures = supportedCultures;
options.SupportedUICultures = supportedCultures;
}https://stackoverflow.com/questions/60061208
复制相似问题