Provide localization for default error messages in System.ComponentModel.Annotations
Currently, using attributes like [Required] or [Range(1, 20)] in ASP.NET Core only gives you english error messages, no matter what culture you set. That is because .NET Core currently only has one (english) resource file. In this issue , @ryanbrandenburg suggested to create a issue here instead of aspnet/Localization to see if this could get resolved, so this is what I'm doing.
I wish I could just write, for example, [Required] and get localized error messages, without the need to write [Required(ErrorMessage = "bla bla bla")] all the time, or creating a lot of resource files, or creating a single big resource file for every annotation... All of these options introduce a lot of hassle for anyone developing applications in any language other than english. It's especially frustrating when all the Annotations you use are the default ones.
@krwq @tarekgh do you have any advice from general .NET Core localization point of view?
@karelz I believe the request here is to get the net core assemblies localized. neither me nor @krwq familiar or owning that. would be better to get the owner take a look.
CC @danmosemsft as he was involved in similar discussions before.
https://github.com/dotnet/corefx/pull/2713
@tarekgh does it mean .NET Core assemblies are not localized at all? (that would be a bit surprising to me)
I don't think we localize the net core assemblies. I believe the exception is Microsoft.CSharp dotnet/corefx#2713
@karelz @danmosemsft I don't think there is anything to do here from the area owner perspective. If the assembly resources are localized as part of a wider effort, then this would just start working. Beyond that I don't think we will do anything special to make this happen. Is there a general issue tracking this localization--#2713 seems to be specifically about Microsoft.CSharp.
@ajcvickers There is no plan for BCL-wide localization. Most texts don't need it as they are not exposed to end-customers (e.g. exception texts, etc.). System.ComponentModel.Annotations and Microsoft.CSharp are likely the only exceptions to that rule.
If you think it is valuable scenario for developers to enable localization of Annotations, then we should start the discussion how to make it happen.
Thanks @karelz. I agree with not localizing in general--I'm very happy that we have got there. However, maybe data annotations is special since these messages are intended for customers. I will talk to @divega about it.
@ajcvickers Do you have any update on that matter? It seems to effectively be a special case here, but an important one IMO. The validation messages are always (almost) displayed to the end users, not being able to provide localized ones is kind of a road blocker here.
Sure there are other options such as inheriting the attribute and customizing the error message, but it's not as clean and efficient.
cc: @terrajobst
It's too painful that I cannot localize the Required, EmailAddress etc annotations in the global scope. The validation messages are displayed to customer directly. How these going on?
@cycbluesky We discussed this again recently and at least for now we're not going to do localization here. Localization of the default strings only helps those using the default strings, and it is common to instead use custom strings that are more domain-specific and therefore more helpful.
We are not sure how feasible it is, but we would consider a PR that brings existing localized strings for data annotations from .NET Framework to .NET Core, in a similar fashion to how https://github.com/dotnet/corefx/pull/2713 did it for Microsoft.CSharp.
I believe those translations are not available as reference source, but if there is anyone willing to try this we can figure out next steps.
@ajcvickers It is not common to use custom strings. For basic things like Field xxx is required the message is evident enough. And in most cases is used just as is. So for all the people not living in English speaking nations or working on multilanguage products there should be an option for translation. I am actually sad to see issues dating back 2 years to fix this and nothing has been done in this time.
@divega Whatever you do please make that behaviour optional. Translating technical messages like exceptions or model validation errors is awful for developers that have to support users across the globe and prefer analysing error logs without Hungarian or Chinese messages intermixed.
A good UI shouldn't show these messages to the user anyhow.
@divega Whatever you do please make that behaviour optional. Translating technical messages like exceptions or model validation errors is awful for developers that have to support users across the globe and prefer analysing error logs without Hungarian or Chinese messages intermixed.
A good UI shouldn't show these messages to the user anyhow.
Well, apparently that has already begun. I was the one to open this issue and I hope I haven't created a monster. As @os1r1s110 said:
The validation messages are always (almost) displayed to the end users, not being able to provide localized ones is kind of a road blocker here.
And that is true.
However, I've noticed that since ASP.NET Core 2.2, kestrel messages seems to be translated as well (they appear translated on the console when debugging), which is awful.
Let's be very clear here: validation messages which are displayed to the final UI being translated is one thing; logging, exception and just everything else is another thing entirely. In fact, I think that if you keep going on this route, you should not only make it optional, but more specifically make it opt in.
Translated technical messages never really help no one. Even beginners. In fact, I think it may make their life harder, since obviously there's way more content in English than any other language. When I started programming, I always had to first search for the exception message in english and then search about the exception itself. It's not a very pleasant experience. There are times when two exceptions had similar texts and I ended up losing time just searching for their english equivalent. And no, it's not just as easy as translating back, because of course a sentence can be translated in various different ways. And to make it worse, much of the time the messages aren't simply translated - they're localized, which makes it even harder to translate back.
Some people want translated exceptions because they do want to show them to users. For example, many MSBuild messages contain verbatim .NET exception strings. Something like "The Copy task failed. {0}" where "{0}" is something like "Could not copy file 'abc'. File not found". In that situation they want the whole string translated or not at all. It is not easy to supply their own messages, because firstly there are many many possible messages, and secondly the .NET exceptions often provide key information only in the message string- for example, the file path. This will help a little, and only for IO.
Anyway - that is a much broader conversation - and at this time there is no effort planned to localize messages as we did in .NET Framework. I just wanted to point out that it is a valid debate to have.
Yea, sure, I think that saying they help no one was an exaggeration.
I do completely agree that it is a valid debate though; all I said is that I think it should be opt in. I really think english messages helps way more people than translated ones do.
I think it would be nice if this could be done programmatically - like through an API to get the translated message from a specific Culture. I didn't give much thought to this though and I don't how feasible is that.
@danmosemsft Having one global issue where we could voice concerns about localising developer facing strings would be great.
Because as seen here if someone provided a PR with translations there's a good chance this would be included without bigger input by the community.
If people have valid use cases for translating these messages I'm certainly not against it. But as someone who has to deal with translated exception messages when analysing bugs I want a programmatic, offline ability to get the English exception messages or model validation errors. The full framework approach simply doesn't work very well for those of us that have global user bases.
Considering that virtually no other language translates their exceptions should also hint that the value of doing so is far from universally recognised.
@danstur I hear you. Feel free to open such an issue if there isn't one. As mentioned above we aren't doing anything here for 3.0, at least