Localization in ASP.NET Core

The default providers are:

  1. QueryStringRequestCultureProvider
  2. CookieRequestCultureProvider
  3. AcceptLanguageHeaderRequestCultureProvider

Most likely the culture is determined from the Accept-Language HTTP header that the browser is sending.

In Startup.cs put this fro Slovenian:

public void ConfigureServices(IServiceCollection services)
    CultureInfo[] supportedCultures = new[]
        new CultureInfo("sl"),
        new CultureInfo("en")

    services.Configure<RequestLocalizationOptions>(options =>
        options.DefaultRequestCulture = new RequestCulture("sl");
        options.SupportedCultures = supportedCultures;
        options.SupportedUICultures = supportedCultures;
        options.RequestCultureProviders = new List<IRequestCultureProvider>
            new QueryStringRequestCultureProvider(),
            new CookieRequestCultureProvider()

and in Configure method just use app.UseRequestLocalization(); before app.UseMvc();

You may also like

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.