mirror of
https://github.com/steveiliop56/tinyauth.git
synced 2025-10-28 20:55:42 +00:00
i18n: internationalize required error
This commit is contained in:
@@ -12,6 +12,7 @@ import {
|
|||||||
} from "../ui/form";
|
} from "../ui/form";
|
||||||
import { Button } from "../ui/button";
|
import { Button } from "../ui/button";
|
||||||
import { loginSchema, LoginSchema } from "@/schemas/login-schema";
|
import { loginSchema, LoginSchema } from "@/schemas/login-schema";
|
||||||
|
import z from "zod";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
onSubmit: (data: LoginSchema) => void;
|
onSubmit: (data: LoginSchema) => void;
|
||||||
@@ -22,6 +23,11 @@ export const LoginForm = (props: Props) => {
|
|||||||
const { onSubmit, loading } = props;
|
const { onSubmit, loading } = props;
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
z.config({
|
||||||
|
customError: (iss) =>
|
||||||
|
iss.input === undefined ? t("fieldRequired") : t("invalidInput"),
|
||||||
|
});
|
||||||
|
|
||||||
const form = useForm<LoginSchema>({
|
const form = useForm<LoginSchema>({
|
||||||
resolver: zodResolver(loginSchema),
|
resolver: zodResolver(loginSchema),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import {
|
|||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import { useForm } from "react-hook-form";
|
import { useForm } from "react-hook-form";
|
||||||
import { totpSchema, TotpSchema } from "@/schemas/totp-schema";
|
import { totpSchema, TotpSchema } from "@/schemas/totp-schema";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import z from "zod";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
formId: string;
|
formId: string;
|
||||||
@@ -17,6 +19,12 @@ interface Props {
|
|||||||
|
|
||||||
export const TotpForm = (props: Props) => {
|
export const TotpForm = (props: Props) => {
|
||||||
const { formId, onSubmit, loading } = props;
|
const { formId, onSubmit, loading } = props;
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
z.config({
|
||||||
|
customError: (iss) =>
|
||||||
|
iss.input === undefined ? t("fieldRequired") : t("invalidInput"),
|
||||||
|
});
|
||||||
|
|
||||||
const form = useForm<TotpSchema>({
|
const form = useForm<TotpSchema>({
|
||||||
resolver: zodResolver(totpSchema),
|
resolver: zodResolver(totpSchema),
|
||||||
|
|||||||
@@ -51,5 +51,7 @@
|
|||||||
"failedToFetchProvidersTitle": "Failed to load authentication providers. Please check your configuration.",
|
"failedToFetchProvidersTitle": "Failed to load authentication providers. Please check your configuration.",
|
||||||
"errorTitle": "An error occurred",
|
"errorTitle": "An error occurred",
|
||||||
"errorSubtitle": "An error occurred while trying to perform this action. Please check the console for more information.",
|
"errorSubtitle": "An error occurred while trying to perform this action. Please check the console for more information.",
|
||||||
"forgotPasswordMessage": "You can reset your password by changing the `USERS` environment variable."
|
"forgotPasswordMessage": "You can reset your password by changing the `USERS` environment variable.",
|
||||||
|
"fieldRequired": "This field is required",
|
||||||
|
"invalidInput": "Invalid input"
|
||||||
}
|
}
|
||||||
@@ -51,5 +51,7 @@
|
|||||||
"failedToFetchProvidersTitle": "Failed to load authentication providers. Please check your configuration.",
|
"failedToFetchProvidersTitle": "Failed to load authentication providers. Please check your configuration.",
|
||||||
"errorTitle": "An error occurred",
|
"errorTitle": "An error occurred",
|
||||||
"errorSubtitle": "An error occurred while trying to perform this action. Please check the console for more information.",
|
"errorSubtitle": "An error occurred while trying to perform this action. Please check the console for more information.",
|
||||||
"forgotPasswordMessage": "You can reset your password by changing the `USERS` environment variable."
|
"forgotPasswordMessage": "You can reset your password by changing the `USERS` environment variable.",
|
||||||
|
"fieldRequired": "This field is required",
|
||||||
|
"invalidInput": "Invalid input"
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user