Skip to content
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

Fix validation errors from resolvers are not translated #9191

Merged
merged 9 commits into from Aug 21, 2023

Conversation

djhi
Copy link
Contributor

@djhi djhi commented Aug 17, 2023

Fixes #9084

Copy link
Member

@fzaninotto fzaninotto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is missing some additional tests. Also, as this changes the behavior of the resolvers validation, I'd be more comfortable if this was released in a minor version. Would you mind targeting the next branch instead?

packages/ra-ui-materialui/src/form/SimpleForm.spec.tsx Outdated Show resolved Hide resolved
packages/ra-core/src/form/useInput.ts Show resolved Hide resolved
packages/ra-core/src/form/ValidationError.tsx Outdated Show resolved Hide resolved
packages/ra-core/src/form/ValidationError.tsx Outdated Show resolved Hide resolved
packages/ra-core/src/form/Form.stories.tsx Outdated Show resolved Hide resolved
Copy link
Member

@fzaninotto fzaninotto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, but we really need extensive tests showing that error message translation occurs once and only once in the 3 following cases:

  • per input validation
  • form-wide validation with validate
  • form-wide validation with resolvers

These tests may be scattered around several components, I'm not sure. A central test for this matter would be welcome.

@djhi
Copy link
Contributor Author

djhi commented Aug 18, 2023

Added to Form.spec.tsx

Comment on lines 35 to 38
return <>{translate(message, { _: message, ...args })}</>;
return <>{translate(message, args)}</>;
}

return <>{translate(errorMessage as string, { _: errorMessage })}</>;
return <>{translate(errorMessage as string)}</>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To allow warnings on missing translations

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But then it's a regression, as missing translation warnings will now get logged in the console while they were not in master.

If this is only for the purpose of tests, you can enable warning on missing message in the parameters of the polyglotI18nProvider options (https://airbnb.io/polyglot.js/#options-overview). And if it doesn't work, you'll have to use a spy i18nProvider.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fact that it silenced the missing translations warnings was actually a reggresion and was contradictory to the expected and documented behavior.

@fzaninotto fzaninotto merged commit 3161149 into master Aug 21, 2023
10 checks passed
@fzaninotto fzaninotto deleted the fix-validation-translations-when-using-resolvers branch August 21, 2023 07:35
@fzaninotto fzaninotto added this to the 4.13.2 milestone Aug 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFR Ready For Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

String error messages are not translated when using global validation
2 participants