繁体   English   中英

ASP.Net Core 2.1 MVC本地化文化回退

[英]ASP.Net Core 2.1 MVC Localization culture fallback

我有一个关于ASP.Net Core 2.1 MVC App中的本地化的问题。

因此,在我的创业公司中,我拥有三种受支持的文化:

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”。

因此,在阅读了文档的这一部分之后:

"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 = zh-CN,它可以正常工作,并且我的显示器为英文。

所以我看不到我所缺少的东西,我是否以错误的方式理解了文档?

在此先感谢您的帮助

如果找不到,它将还原为该文化的父文化

en-GB不是en-US的父级文化,这就是为什么它退回到默认文化fr-CH的原因

如果所选区域性是en-US ,而您在受支持区域性中没有该区域,它将还原为父区域性,即en ,这意味着所请求的资源将为welcome.en.resx

对于en文化相同,如果未定义,则欢迎使用所选资源。resx

最后,如果找不到资源,则将选择默认的定义区域性。

同时,每种文化都有一个可以在CultureInfo.Parent找到的父文化。

在此处查找更多信息: 资源回退过程

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM