-
-
Notifications
You must be signed in to change notification settings - Fork 567
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
Validation messages text in class public static properties (#711) #713
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Is this something to do with localization of the error messages? If so, I'm not sure I can really recommend this approach. You're adding a huge number of new public properties, expanding the maintenance surface, and spreading the feature all across the code base. I would suggest an approach that keeps the details of each class insular, centralizes the error strings for easier reference, and exposes a single point where localization can happen. I'm sure there are a million ways to do this, but I was involved in this exact same work on another repo I used to contribute to years ago, and here's what I came up with then: https://github.com/justinrainbow/json-schema/pull/364/files In short:
Just some ideas to get you thinking. |
Hi, I've created an issue. Got an answer that translation for this lib is not an important case and @vladar don't want to complicate things because of translation and proposed a minor changes so that we had at least some opportunity to translate the text of errors. @spawnia proposed another option with also minor changes that prevents silly errors, i agreed to this terms and did this PR to get a solution for my problem in a way acceptable to you. |
@Erindi I agree with that assessment and think we can merge this as-is. @shmax We do not have to guarantee stability of those messages forever. If someone decides to put in the time to develop a better translation system, we can change it in the next major release. |
@spawnia @Erindi This is not a "minor change". You touched 32 files. You added 50+ new public properties to the API surface that we will have to maintain, and eventually break once one of us takes the time to support this properly. But the point is that this is simply not how you localize a code base. With this approach a consumer of the library would have to figure out how to get access to each of these classes so he can set those strings, and it would do absolutely nothing for client side projects (eg. Javascript). If @Erindi is in that much of a hurry he can just fork the repo and merge his branch there. Let's not make a mess of this one. All that said, I'm happy to support this feature properly, but let's take the time to understand it and come up with a solution that is mature, robust, and a little more accessible to other consumers of this library. I'm free all weekend. |
@shmax I think both approaches will introduce the same surface area to maintain. The one you suggest would also touch 32 files and introduce a bunch of "breaking points" - basically every error message constant. One possible benefit of your approach is that it provides means to notify users when some error messages are deprecated/no longer used. On the other hand, setting missing public static property probably also counts as a similar notification (e.g. if we replace some message with a new one). Another benefit of your approach is a better DX for end-users: we'll have all the internal messages in a single place, so they are easier to reach (touch one class vs many), easier to diff, etc. But the downside is that it will be a bit harder to sync with the reference implementation than the existing one. And my biggest concern is that eventually, they will come up with their own system for message translations. It will be relatively easy to migrate to whatever they do from this PR. Can be harder with yours. Another downside that it is less convenient with custom validation rules. Now if you write your own validation rule, you will also have to duplicate our translation mechanism (have a separate class with your own codes/messages). So yeah, I see pros and cons of both approaches but I am not convinced that one is significantly better than the other. So I am inclined to merge this unless you are ready to post your own PR in the near future? If so, it should definitely address the case of custom validation rules somehow. |
@vladar Thanks for the feedback, but you skipped over a few key points.
I'm actually not arguing that my solution is perfect; it was my first crack at this kind of thing and in its own way it's probably a bit naive. But it's certainly more robust and functional as an actual localization mechanism than this one. The approach presented in this PR is not a mechanism; simply exposing what should be internal to the public API is a hack, not a feature. I am still happy to support this, but now that two and a half weeks have passed with no feedback from anyone, it seems this is not as urgent as we thought, so before I do anything perhaps we should agree on a rough architecture. I'll do a little more research when I get a chance. |
I had a look at the graphQL spec. It does not specifically discuss localization, but there seems to be an "extensions" entry on the error object that would suit the kind of thing I'm talking about: http://spec.graphql.org/draft/#example-fce18 If I can get some agreement from you guys that this would be a good avenue to explore I can start on this today. Let me know what you think. |
I see that we already have an |
Here's the 1-hour version: #718 |
I noticed that |
No description provided.