ASP.NET Core comes with built-in localization features through the Localization middleware. This middleware will update the current Culture and current UI Culture based on information provided by one or more 'RequestCultureProviders'
The default providers are
- QueryStringRequestCultureProvider
- CookieRequestCultureProvider
- AcceptLanguageHeaderRequestCultureProvider
It is also possible to set a default culture when no culture information could be resolved through one of the configured providers. This is useful if your website or application targets a standard audience in one region or country.
To set a default culture, we need to configure the DefaultRequestCulture property of the RequestLocalizationOptions:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.UseRequestLocalization(new RequestLocalizationOptions | |
{ | |
DefaultRequestCulture = new RequestCulture("nl-BE") | |
}); |
Now when no culture information could be resolved through one the providers, 'nl-BE' will be used as our default culture.