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?
Enable Client Based Culture [enableClientBasedCulture]Gets or sets a value indicating whether the Culture and UICulture properties should be based on the AcceptLanguage header field value that is sent by the client browser.
Applying Cultures Copy the required culture JavaScript file from the \js\culture\ folder of your Telerik UI for ASP.NET Core installation to the wwwroot/lib/kendo-ui/js/cultures/ folder of your application. Alternatively, provide the culture files by using the Kendo CDN service.
In an ASP.NET Web page, you can set to two culture values, the Culture and UICulture properties. The Culture value determines the results of culture-dependent functions, such as the date, number, and currency formatting, and so on. The UICulture value determines which resources are loaded for the page.
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"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With