I\'m having some odd issues with a web application written using Asp.Net Core 1.1, using the full .Net Framework v4.6.2.
I want to force the application to use a swedish
Take a look at Microsoft ASP.NET Core Docs - Globalization and localization.
4) Added RequestLocalization to Configure(...) in Startup.cs
From docs:
The current culture on a request is set in the localization Middleware. The localization middleware is enabled in the Configure method of Startup.cs file.
Note, the localization middleware must be configured before any middleware which might check the request culture (for example, app.UseMvc()).
5) In my controller constructor setting the current threads culture
6) In my controller actions setting the current threads culture
Instead of setting in the constructor or in every action, try set the culture at OnActionExecuting
filter. Here is an example code:
public class InternationalizationAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
var cultureInfo = CultureInfo.GetCultureInfo("sv-SE");
Thread.CurrentThread.CurrentCulture = cultureInfo;
Thread.CurrentThread.CurrentUICulture = cultureInfo;
}
}
In your controller class, put this: [Internationalization]
.