arktype: localization support: problem message parser
Request a feature
The maintainers of ArkType will do our best to provide prompt feedback for any feature requests- especially those that are concise and persuasive!
𤷠Motivation
What problem are you having?
The Problem class only expose the formatted message and not the other properties,
meaning the message cannot be localized into other languages.
Why should we prioritize solving it?
Any application supporting i18n probably need this support.
š” Solution
How do you think we should solve the problem?
There are a few ways to do it.
One way is to simplify the Problem class containing only the data, while there is a overridable problem parser that parse the problem into message.
There are other ways such as accepting a problem factory, exposing the problem data so that application can create their own message parser using the resulting problem instances, etc.
I think the parser approach is probably the best as it properly separate the concerns between problem reporter and message parsing.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 21 (9 by maintainers)
@unional I actually think that data was always exposed, although
ArkErrordoes need some documentation: https://github.com/arktypeio/arktype/issues/1273I will close this for now in favor of this discussion for additional feedback on how we can best support i18n internally.
The problem now is that in zod, we can specify each typeās error message easily like
But in ArkType, I did now see an easy approach, managing error messages is quite complicated.
For me thatās a major reason that stopped me from using ArkType. I respect it provides both ātextā and āfluentā method to manage type, meanwhile the shortage of managing āoptionā or what say ādetailā of each type is a bit confusing. From this perspective I think zod did a better job.
In other words, this might not be a āshortageā of ArkType, itās that when comparing between ArkType and zod, they actually gives different design.
When it comes to zod, itās actually acceptable to either specify error messages in typeās option or manage i18n globally (Iām a bit annoyed by how I need to set every localized error messages in EVERY type, even though they are almost the same so Iām desperately wanting for a new alternative).
But in ArkType, your type-specifying design only allow you to manage a global localization thing, since every type, if specified in ātextā method, as far as I see thereās no concept of āoptionsā. So in this situation, the best solution I can imagine is to figure out a way to manage i18n like date-dns does, the only change is to configure it via global option.
Hi, sorry missed that message @ssalbdivad.
Please donāt worry about it. Itās not open source and Iām just trying to figure out how to do it myself too.
@unional Whoops, my bad! Not so useful if you canāt access themš
Iāll be sure those are exposed for the next release, and the rest of this gives me good context to consider for some other details of this problem. Iāll keep this issue open until then to ensure I follow through with that!
I think the
dataandsourceare private atm: https://github.com/arktypeio/arktype/blob/main/src/traverse/problems.ts#L42-L43Yes, with that, it will support the
exposing the problem data so that application can create their own message parser using the resulting problem instancesscenario.i.e. something like: