title: Error Message: Model not picking language-specific resource file
body: <p>I want to display model error message in spanish and I have defined those string in resourse files. I have done the same for other string on the page using razor syntax but the ones from ViewModel annotation are not being picked. </p>
  
  <p>It is actually picking the default values - English. So my guess is that may be the language/culture was not detected, but other string on the page are displayed in spanish</p>
  
  <pre><code>//Spanish: El campo {0} se requiere
  //English: The {0} field is required  &lt;--- this comes out always irrespective of set language
  
  [Required(ErrorMessageResourceName = "ErrorMessage_Required", 
       ErrorMessageResourceType = typeof(GlobalResources.Resources))]
  [Display(Name = "CardNumber", ResourceType = typeof(GlobalResources.Resources) )]
  public string CardNumber { get; set; }
  </code></pre>
  
  <p>I set the language in my Controller</p>
  
  <pre><code>protected override void OnActionExecuting(ActionExecutingContext filterContext)
  {
      base.OnActionExecuting(filterContext);
  
      HttpCookie cookie = Request.Cookies["lang"];
  
      string lang = cookie != null ? cookie.Value : "en-US";
      System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(lang);
  }
  </code></pre>
  
  <p>How do I extend the culture settings to ViewModels?</p>
  
  <p><strong>Update</strong>
  A similar post: <a href="https://stackoverflow.com/questions/7202607/mvc3-globalization-need-global-filter-before-model-binding">MVC3 globalization: need global filter before model binding</a></p>
  
  <p><strong>Update</strong>
  Changing the preferred language in my browser settings made it work. This means the model attributes is using this settings which is not affected by <code>System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(lang);</code>. <em>Is there a way to make this happen? - Still searching....</em></p>
  
  <p><strong>Update:</strong> Moving the code to <code>Application_AcquireRequestState</code> seems to solve it.</p>
  
  <pre><code>protected void Application_AcquireRequestState()
  {
      HttpCookie cookie = Request.Cookies["lang"];
  
      string lang = cookie != null ? cookie.Value : "en-US";
      System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(lang);
  }
  </code></pre>
  
  <p><a href="https://stackoverflow.com/questions/16218382/thread-currentthread-currentuiculture-vs-accept-language-in-viewmodels/16218779?noredirect=1#16218779">The explanation I got</a>, also found in the link posted in this question, that it was too late for the model to make use of the culture being set in controller overridden method as the binding had already occurred before the method is called. <a href="http://adamyan.blogspot.ch/" rel="nofollow noreferrer">This link was helpful</a></p>