Data annotation localization problem

New Contributor

I am using Asp.net Core Blazor and I want to localize validation messages. I am also using Portable Object Localization. The validation message localization does not work. I think Blazor does not support data annotation localization. So is there any solution to localize the validation messages?

Sample of my po file code:

 

msgid "The {0} field is required"
msgstr[0] "موجودیت {0} لازمی میباشد"

 

Sample model code:

 

[Display(Name = "Location")]
[Required(ErrorMessage = "The {0} field is required")]
public string Location{ get; set; }

 

I also want to know if it is possible to pass a parameter to the localization string like:

 

 

msgid "Please Enter {0}"
msgstr[0] "لطفا {0} را وارد نمایید"

 

In my Blazor view I want something like this:

 

@Localize["Please Enter {0}","Employee Name"]
// Please Enter Employee Name
// لطفا اسم کارمند را وارد نمایید

 

1 Reply

Hi @najeeb-anwari,

Thanks for posting your issue here.

However this platform is used for how-to discussions and sharing best practices for building any app with .NET.Since your issue is a technical question, welcome to post it in Microsoft Q&A forum, the support team and communities on Microsoft Q&A will help you for any technical questions.
Besides, it will be appreciated if you can share it here once you post this technical question Microsoft Q&A.
Best Regards,
Lan Huang