Open liuliang-wt opened 3 years ago
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.
I'd like to see a simple and uniform way to do this as well.
The development story for blazor is another than the one for aspnet core and then there's ApiControllers
which also seem to have a slightly different usage. Chiming in Client/Server shared models in blazor and it all get's messy, since they'll influence each other.
Optimally there would just be ErrorCodes on the DataAnnotation, that'll just be used as lookup everywhere the DataAnnotation is printed. Same for the field name, which might be part of a DataAnnotation.
Hello guys I have the same issue with localization but I found this package. It is working but I also have another problem. How to pass a parameter to the localization string? I used to do this in Laravel framework in PHP easily like __(":resource added successfully!", ["resource" => "Student"]) In my localization files, I had localization for both the Student and ":resource added successfully!" strings.
I am having the same issue and look forward for this feature to be added to Blazor.
Yeah, this would be quite nice to have... :-\
Summary
Currently, the logic of handling localization of DataAnnotations is different in blazor and aspnetcore:
Motivation and goals
one advantage of blazor is that it can share some code between server side and the client. In most case, models with DataAnnotations and languages resource files have already be written on the server side. But because blazor use different logic to handle DataAnnotation localization, I can't share the model and resource files to blazor, I have to write it again in blazor...
Examples
At server side, I define model like this:
and use some thing like this in the startup:
services.AddMvc() .AddDataAnnotationsLocalization(options => { options.DataAnnotationLocalizerProvider = (type, factory) => factory.Create(typeof(SharedResource)); }); aspnetcore will look for the SharedResource for "_Admin.Account", "Validate.{0}required", etc....
In blazor, AddDataAnnotationsLocalization dosenot work, and for wsam mode, there is no AddDataAnnotationsLocalization at all, I have to write the same model again only because of localization. the model in blazor is like this:
I also need add a default Resx file without a language suffix and make it compiled to a class. ( I don't need this file on server side)