-
-
Notifications
You must be signed in to change notification settings - Fork 97
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
i17n support (custom error messages) #382
Comments
Hi! Sorry for the delayed response. I like the idea but I don’t know what would be the best way to provide the possibility to choose the language without runtime overhead, so this feature is zero cost |
I do also use Json schemas in my PHP projects and I have samthing like that
And my data gateway returns property path and error for it. So the app can use path to find correct UI element and show appropriate error message along to this UI element PS
It search for custom defined errors in schema. For eg "formatError" or "minLengthError" and etc So ... you can use multiple json schemas for each language and each language will have custom defined error messages |
My approach, from using python-jsonschema, is essentially to do post-processing on the ValidationError instances generated by iter_errors. I write my own translatable strings for each keyword; these strings contain placeholders and are translated using gettext. I then substitute values from the ValidationError into the placeholders. To support that approach, I created #650. Thinking of other options: Right now, the fmt::Display implementation for ValidationError already has format strings for all keywords. Perhaps these can be exposed (as read only) via the API. A user is then able to read and translate these format strings (using whatever tools they prefer). Finally, a new option can be added to initializers to accept a mapping of error type to format string, to override the default. This second option is fine if you are satisfied with the default strings and just want to be able to translate them. It is less work that having to fill in placeholders like in the first option. Both options can be pursued for the different needs. |
For the second option: Rereading the fmt::Display implementation, I see that there needs to be pluralization handling. Considering how complex pluralization is across languages (one, two, few, many, other in Arabic), I think it’d be best if this crate implemented i18n itself (eg with gettext) and people could contribute translations to new languages. My original “second option” above wouldn’t work due to the need for pluralization support (the min… and max… keywords). |
Hm, at first glance exposing kind + context (e.g. limits) looks like enough to build any translation. But a feature-gated built-in This way anybody can either use a built-in translation or build their own. I agree with your comments above :) The first step could be just exposing extra context. |
Thanks for that great crate!
I want to use this crate via Python but this module lacks i17n support so I should try parse English and translate into Japanese.
I believe this support make this more end user friendly.
The text was updated successfully, but these errors were encountered: