damienbod / AspNetCoreLocalization

Localization.SqlLocalizer & ASP.NET Core MVC Localization Examples
http://damienbod.com/2015/10/21/asp-net-5-mvc-6-localization/
MIT License
251 stars 101 forks source link

Localization of data annotation #16

Closed rpundlik closed 8 years ago

rpundlik commented 8 years ago

Hello, Thanks for the great project.

However, can you please tell how can we do localization of data annotations using SQL. I have written custom attribute for each of the validation(Like required,compare etc) and I want to implement localization logic in it.

Thanks for the help !

damienbod commented 8 years ago

Hi @rpundlik

I have a working example now for the Box.cs class

 [Required(ErrorMessage = "BoxLengthRequired")]
 [Range(1.0, 100.0, ErrorMessage = "BoxLengthRange")]
 public double Length { get; set; }

The SQL localization records are in the sqlite file. This can be tested using an invalid POST request.

http://localhost:5000/api/boxes?culture=it-CH

User-Agent: Fiddler
Host: localhost:5000
Content-Length: 46
Content-Type: application/json

{ "Id":7,"Height":10,"Width":10,"Length":1000}

Let me know if you require anything else. Sorry for the slow answer, was busy ...

Greetings Damien