I have the following resource files in my ASP.NET MVC application to stored form validation error message for both English and Spanish
ErrorMessages.resx -- English Error Messages
ErrorMessages.sp.resx -- Spanish Error Messages
In my models that require the System.ComponentModel.DataAnnotations Required Attributes they are marked like this:
[Required(ErrorMessageResourceType = typeof(ErrorMessages), ErrorMessageResourceName)]
public string MyProperty { get; set; }
In my controller, I am reading a JavaScript cookie that contains the user's selected language on the site and programmatically set the 'CultureInfo' of the current thread and the HTTP session:
public ActionResult MyController()
{
var language = HttpContext.Request.Cookies["language"].Value;
if(language.Equals("english"))
{
HttpContext.Session["culture"] = "en-US";
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
}
else
{
HttpContext.Session["culture"] = "es-US";
Thread.CurrentThread.CurrentCulture = new CultureInfo("es-US");
}
}
How do I set the appropriate resource file once the CultureInfo value has been modified?
CultureInfovalue. Thanks for the suggestion