Using translations 'outside' of React #28
-
I've enjoyed using talkr a lot, thanks for the great library! Currently, I am using zod to validate some forms, and some of the errors. I can get around this easily by either wrapping a schema inside a memo or creating a new hook: export const LayoutEdit = () => {
const { T } = useT();
const layoutEditSchema = useMemo(
() =>
z.object({
Title: z.string().min(1, { message: T('required') }),
ID: z.string().min(1, { message: T('required') }),
}),
[T]
);
... Out of ergonomic reasons, it would be great to define the schema outside, and use a function in them directly for the error messages. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @PointSingularity , thanks for your message! I don't know Zod, but you could simply write the translation key in the message field: const layoutEditSchema = z.object({
title: z.string().min(1, { message: "form.required" }),
id: z.string().min(1, { message: "form.required" ) }),
}) then loop over the errors and write: <p>{T(error.message)}</p> This way, you can keep your schemas out of your components. Let me know if it works. |
Beta Was this translation helpful? Give feedback.
Hi @PointSingularity , thanks for your message!
I don't know Zod, but you could simply write the translation key in the message field:
then loop over the errors and write:
This way, you can keep your schemas out of your components. Let me know if it works.