Skip to content

Culture Fallback Behavior

Ziya Mollamahmut edited this page Jan 15, 2020 · 2 revisions

Asp.Net Core uses localization culture providers to detect the request culture and respond accordingly. The culture checking process goes one by one through all registered providers, whenever a request culture is detected the check process stops and the localization process starts accordingly.

If the request culture is not found in the first provider, next provider will be checked. Finally if no culture is detected the default culture will be used.

ExpressLocalization is using the below order for request culture providers:

  1. RouteSegmentCultureProvider
  2. QueryStringRequestCultureProvider
  3. CookieRequestCultureProvider
  4. AcceptedLanguageHeaderRequestCultureProvider
  5. Use default request culture from startup settings

In order to restrict culture fallback to route culture provider only use below implementation in startup:

services.AddRazorPages()
        .AddExpressLocalization<LocalizationResource>(ops =>
        {
            // Use only route segment culture provider
             ops.UseAllCultureProviders = false;
               
            // the rest of the code...
        });

reference to issue #13

Clone this wiki locally