-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
trouble with native compatibility with ajv-i18n #1195
Comments
I think this issue should be solved once rjsf supports localization as an option, see #846 |
Great thank's for reference. May be yes, accorded functional may be solve this trouble. Or may be not - because trouble in structure of base error object. |
I am see the pull request, and i'am dont shure that added functionality are provides compatibility with ajv-i18n native provided functions at first - localize fuctions need incoming array of ajv validation errors or, i not uderstand 'convertMessagesText' magic :) In my solution - compatibility is achieved by modify only one property in basic error object (it's not clear why native ajv error is modifing inside of rjsf) and localize will be used 'as is' in existed transformErrors gear (not neead to add new rjsf property for this) |
No, it seems to work fine. If you add the following in
Then all the error messages are showing up properly in Russian. I believe this is because the localization function is called directly on the errors returned from ajv, before they are transformed to the format that rjsf returns. See https://github.com/mozilla-services/react-jsonschema-form/pull/846/files#diff-6ca5d88062570937214ee7ea244b05c5R161 |
Ok, thanks for your explanation. remains to whait for the target pull request (#846) will be aproved and the upcoming next master major version of rjsf released. I understand correctly ? |
@RUVATA Exactly! |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please leave a comment if this is still an issue for you. Thank you. |
Prerequisites
Description
Current realization of errors object incomes in transformErrors (https://react-jsonschema-form.readthedocs.io/en/latest/validation/#custom-error-messages) is incompatible with ajv-i18n (https://github.com/epoberezkin/ajv-i18n)
Since the AJV is used internally, it would be nice to ensure compatibility with AJV native i18n gear, especially considering that such compatibility is very simple to provide by expanding the "erorrs" with one property "keyword", the value for which already exists in members of incoming errors array members as "name" property.
See my playground sample (https://codesandbox.io/embed/vm3lz56j53?fontsize=14), where basic erros array normalizing by map for full compilibility with ajv-i18n localization function.
Steps to Reproduce
function transformErrors(errors) { localize_ru(errors); return i18n_normalized; }
function transformErrors(errors) { const i18n_normalized = errors.map(e => ({ ...e, keyword: e.name })); localize_ru(i18n_normalized); return i18n_normalized; }
Expected behavior
The erros array members (objects) will have 'keyword' property (duplicated 'name' property value)
PS: May be 'name' property will be renamed to 'keyword' with concurrent refactoring thats usages in other project sources
Actual behavior
The erros array members (objects) not have 'keyword' property, and ajv-i18n localization gear crashes called with the current errors array as argumnet
Version
current major - 1.2.1
The text was updated successfully, but these errors were encountered: