I\'ve been trying to implement localization for my asp .NET Core 1.0 RTM web app following microsofts documentation and I just can not get it to work. The problem I\'m havin
You are probably hitting the following : https://github.com/aspnet/Mvc/issues/4692
Mainly take a look at the comment: https://github.com/aspnet/Mvc/issues/4692#issuecomment-223671462
Summary: You can create a Resource filter in MVC to workaround the issue:
public class CultureSettingResourceFilter : IResourceFilter, IOrderedFilter
{
public int Order
{
get
{
return int.MinValue;
}
}
public void OnResourceExecuted(ResourceExecutedContext context)
{
// By this time the response would already have been started, so do not try to modify the response
}
public void OnResourceExecuting(ResourceExecutingContext context)
{
var culture = httpContext.GetRouteValue("your-culture-key-name")?.ToString();
// set your culture here
CultureInfo.CurrentCulture = culture;
CultureInfo.CurrentUICulture = culture;
}
}
services.AddMvc(o =>
{
o.Filters.Add(new CultureSettingResourceFilter());
});