title: Localization in .NET Core 2 Web API
body: <p>I've followed <a href="https://docs.microsoft.com/en-us/aspnet/core/fundamentals/localization" rel="nofollow noreferrer">this guide</a> for getting my localization to work with my validation. But either I've done something wrong, or it isn't supported.</p>
  
  <p>I have a <code>Controller</code>:</p>
  
  <pre><code>[HttpPost]
  public IActionResult Post([FromBody]Customer value)
  {
      if (ModelState.IsValid)
      {
          return Ok("Good job!");
      }
      return BadRequest(ModelState);
  }
  </code></pre>
  
  <p>I register my localizations like so:</p>
  
  <pre><code>services.AddLocalization(options =&gt; options.ResourcesPath = "Resources");
  services.AddMvc()
      .AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix)
      .AddDataAnnotationsLocalization();
  </code></pre>
  
  <p>And my model:</p>
  
  <pre><code>public class Customer
  {
      [Required]
      public string FirstName { get; set; }
      [Required]
      public string LastName { get; set; }
  }
  </code></pre>
  
  <p>Here's my resx and my directory (all resx look alike):</p>
  
  <p><a href="https://i.stack.imgur.com/7ZZsS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7ZZsS.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/ardn1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ardn1.png" alt="enter image description here"></a></p>
  
  <p>What I want is to let the resource-file determine what message is passed for the propertyname when it's invalid.</p>
  
  <p>Making this POST:</p>
  
  <pre><code>{
      "firstname":"John"
  }
  </code></pre>
  
  <p>Will currently return:</p>
  
  <pre><code>{
      "LastName": [
          "The LastName field is required."
      ]
  }
  </code></pre>
  
  <p><strong>Since I created a <code>Resource</code> for the <code>Customer</code> model I want the result to return this:</strong></p>
  
  <pre><code>{
      "LastName": [
          "The Surname field is required."
      ]
  }
  </code></pre>
  
  <p>I know I can use <code>Display</code> like this:</p>
  
  <pre><code>[Display(ResourceType = typeof(Models_Customer), Name = "FirstName")]
  </code></pre>
  
  <p>...but I thought that the entire point of <a href="https://docs.microsoft.com/en-us/aspnet/core/fundamentals/localization#resource-file-naming" rel="nofollow noreferrer">naming the resource-files</a> based on the model was to avoid it.</p>