I have a question concerning localization in a ASP.Net Core 2.1 MVC App.
So I have three supported culture, in my startup:
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
});
My resource file are named 'SharedView.en.resx', 'SharedView.fr.resx' and 'SharedView.de.resx'.
So after reading this part in the 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")"
I was thinking that when I make a request like https://localhost:xxxxx/Account/Login?cultur=en-US, I will have my translations in English, but it's not working and falling back to fr-CH.
If I use https://localhost:xxxxx/Account/Login?cultur=en-GB it's working and I've got my display in English.
So I don't see what I'm missing, do I understand the documentation in a false way?
Thanks in advance for your help
en-GB is not the parent culture of en-US, that’s why it is falling back to the default culture fr-CH.
When the selected culture is en-US which you don’t have it in supported cultures, it will revert to the parent culture which is en that’s mean the requested resource will be welcome.en.resx.
the same for en culture, if it is not defined, the selected resource will be welcome.resx,
Finally, if no resource is found, the default defined culture will be selected.
Meanwhile, each culture has one parent culture that you can find with
CultureInfo.Parent
Find more info here: The resource fallback process