I am not aware of any filter that sets the attribute, but you can definitely write an action filter to do the same.
If culture is being resolved through routing, use the following code:
using System.Globalization;
using System.Threading;
using System.Web.Mvc;
public class CultureAttribute : ActionFilterAttribute {
public override void OnActionExecuting(ActionExecutingContext filterContext) {
string language = (string)filterContext.RouteData.Values["language"] ?? "en";
string culture = (string)filterContext.RouteData.Values["culture"] ?? "US";
Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo(string.Format("{0}-{1}", language, culture));
Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(string.Format("{0}-{1}", language, culture));
}
}
If you have culture info set in your session variables use this code:
using System.Globalization;
using System.Threading;
using System.Web.Mvc;
public class CultureAttribute : ActionFilterAttribute {
public override void OnActionExecuting(ActionExecutingContext filterContext) {
string language = (string)filterContext.HttpContext.Session.Contents["language"] ?? "en";
string culture = (string)filterContext.HttpContext.Session.Contents["culture"] ?? "US";
Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo(string.Format("{0}-{1}", language, culture));
Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(string.Format("{0}-{1}", language, culture));
}
}
[Themed]
but for culture... – Crinoid