zod icon indicating copy to clipboard operation
zod copied to clipboard

update makeIssue to support the force parameter returned from setErrorMap and allow Custom Message Translations

Open dev2xl opened this issue 1 year ago • 2 comments

Now you can define error messages at the schema level (like a translation key), and use setErrorMap like this to lookup the translation.

Returning force: true will prevent this message of being overwritten by the schema message. This allow to create and return more custom translations for messages.

// Translation logic ex. // error.message is the one defined at schema level; that now you can use it as the translation key

Usage:

z.setErrorMap((error, ctx) => {
  const message = getTranslatedMessageForKey(error.message);
  return { message, force: true };
});

dev2xl avatar Nov 09 '23 18:11 dev2xl

Deploy Preview for guileless-rolypoly-866f8a ready!

Built without sensitive environment variables

Name Link
Latest commit 800b31cbcee66199c6ecc5c4b82309385b86f52d
Latest deploy log https://app.netlify.com/sites/guileless-rolypoly-866f8a/deploys/654d20462c2d550008f6e6de
Deploy Preview https://deploy-preview-2950--guileless-rolypoly-866f8a.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

netlify[bot] avatar Nov 09 '23 18:11 netlify[bot]

I have a specific use case where this option would be really useful and kindly ask the maintainers of this project to consider merging this PR soon.

earthslasthope avatar Feb 01 '24 17:02 earthslasthope

Thanks for this PR. The error map system is being totally rewritten for Zod 4 so I'm afraid there's little point in modifying this API now. I'll keep this use case under consideration.

colinhacks avatar Apr 25 '24 04:04 colinhacks