Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide default localization and globalization for data-annotation generated by tag helpers and model annotations #59916

Open
1 task done
fredericDelaporte opened this issue Jan 17, 2025 · 0 comments
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates

Comments

@fredericDelaporte
Copy link

fredericDelaporte commented Jan 17, 2025

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

HTML form input field tag helpers are rendered useless for many developers by the lack of default localization and globalization for the data-annotations they generate.

Using them in an non-English application causes the display of English validation messages to the user, which is a no-go.

Moreover, culture sensitive inputs do not work.
Have a decimal number input field and an application in French. The number will be output in the input field with a comma as decimal separator (default for french culture). But submitting the form will be blocked by the field considered filled with a value which is "not a number", because the data annotation validation expect a dot for the decimal separator. Complying with this still does not work, because the model binder on server side then rejects the value because it expects a comma as decimal separator.

This causes us to avoid using input field tag helpers entirely.

Describe the solution you'd like

Have default globalization and localization available for data-annotation.

Some workarounds:

  • Follow the globalization & localization documentation. That means every project has to supply its own translations and globalization of the default data-annotations. There is no value in having to do this over and over.
  • Do not use these tag helpers and write your own HTML instead. Using HTML 5 validation attributes ends up being far better for us than using tag helpers. That outputs messages in the browser default interface language, which suits our users far better than hard-coded English messages. And that allows us to avoid the culture sensitive input field trouble by setting them to type text and validating their value through the pattern attribute. (Meaning providing our own message in the title attribute, but that is still better than having to localize all the other cases too.)

Additional context

This is a regression compared to the situation with MVC in .Net Framework, in which data-annotations generated by default HTML helpers (InputFor and the like) were having packages per languages providing default localization and globalization, like this one. (Or was it this or this? Anyway, it was available.)

Related issues:

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Jan 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates
Projects
None yet
Development

No branches or pull requests

1 participant