【发布时间】:2019-02-22 14:24:39
【问题描述】:
我有一个关于 ASP.Net Core 2.1 MVC 应用程序本地化的问题。
因此,在我的创业公司中,我拥有三种受支持的文化:
services.Configure<RequestLocalizationOptions>(options =>
{
var supportedCultures = new[]
{
new CultureInfo("fr-CH"),
new CultureInfo("en-GB"),
new CultureInfo("de-DE")
};
options.DefaultRequestCulture = new RequestCulture(culture: "fr-CH", uiCulture: "fr-CH");
options.SupportedCultures = supportedCultures;
options.SupportedUICultures = supportedCultures;
options.RequestCultureProviders.Insert(0, new CustomerCultureProvider()); // Insert on top of the list so it's the first one to be executed
options.RequestCultureProviders.Insert(1, new WebAuthenticationBrokerCultureProvider()); // Insert as second of the list so it's the second one to be executed
});
我的资源文件名为“SharedView.en.resx”、“SharedView.fr.resx”和“SharedView.de.resx”。
所以在阅读了documentation中的这一部分之后:
"When searching for a resource, localization engages in "culture fallback". Starting from the requested culture, if not found, it reverts to the parent culture of that culture. As an aside, the CultureInfo.Parent property represents the parent culture. This usually (but not always) means removing the national signifier from the ISO. For example, the dialect of Spanish spoken in Mexico is "es-MX". It has the parent "es"—Spanish non-specific to any country.
Imagine your site receives a request for a "Welcome" resource using culture "fr-CA". The localization system looks for the following resources, in order, and selects the first match:
Welcome.fr-CA.resx
Welcome.fr.resx
Welcome.resx (if the NeutralResourcesLanguage is "fr-CA")"
我在想,当我提出像 https://localhost:xxxxx/Account/Login?cultur=en-US 这样的请求时,我会得到英文翻译,但它不起作用并退回到 fr-CH。
如果我使用https://localhost:xxxxx/Account/Login?cultur=en-GB,它就可以工作,而且我的显示器是英文的。
所以我看不到我缺少什么,我是否以错误的方式理解文档?
提前感谢您的帮助
【问题讨论】:
标签: c# .net asp.net-core asp.net-core-mvc-2.1