Form Error Message Localization #4270
chuwong35122
started this conversation in
General
Replies: 2 comments 2 replies
-
I think const FormMessage = React.forwardRef<
HTMLParagraphElement,
React.HTMLAttributes<HTMLParagraphElement>
>(({className, children, ...props}, ref) => {
const {error, formMessageId} = useFormField()
const t = useTranslations()
const body = error ? String(t(error?.message as any)) : children
if (!body) {
return null
}
return (
<p
ref={ref}
id={formMessageId}
className={cn("text-[0.8rem] font-medium text-destructive", className)}
{...props}
>
{body}
</p>
)
});
FormMessage.displayName = "FormMessage"; |
Beta Was this translation helpful? Give feedback.
2 replies
-
You can use a schema for validation. And apply translations directly to it.
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi. I'm using next-intl as my localization library of choice and is currently working on form. How should I approach form error mesage localization that fits shadcn-ui's form taxonomy?
Like how should I render the localized to the selected locale
Beta Was this translation helpful? Give feedback.
All reactions