Omu
Omu

Reputation: 71188

Enabling Client-Based Culture in Asp.Net Core

In MVC 6 by default, CultureInfo.CurrentCulture is the one used by windows, not by the browser.

In MVC 5 I could put this in web.config:

<globalization culture="auto" uiCulture="auto"/>

and that would make the CultureInfo.CurrentCulture be the same as specified by the browser (Accept-Language header).

Is there a way to configure the MVC 6 app to use the browser culture by default?

Upvotes: 6

Views: 5089

Answers (1)

haim770
haim770

Reputation: 49095

You need to install the Microsoft.AspNet.Localization NuGet package and add the following to your Startup.cs:

public void Configure(IApplicationBuilder app)
{
    app.UseRequestLocalization();
    app.UseMvc();
}

By default, it registers the AcceptLanguageHeaderRequestCultureProvider as a culture-provider, that should be equivalent to the legacy enableClientBasedCulture setting.

Update:

As per your comment, since you're using the RC1 version, you must provide a default culture to the method. For example:

app.UseRequestLocalization(new RequestCulture("en"));

Upvotes: 3

Related Questions