wip: i18n chinese

This commit is contained in:
elvis liao
2024-09-26 17:57:30 +08:00
parent 85df8eb09d
commit 0abb030889
18 changed files with 289 additions and 184 deletions

View File

@@ -15,16 +15,18 @@ import { zodResolver } from "@hookform/resolvers/zod";
import { useState } from "react";
import { useForm } from "react-hook-form";
import { useNavigate } from "react-router-dom";
import { useTranslation } from "react-i18next";
import { z } from "zod";
const formSchema = z.object({
email: z.string().email("请输入正确的邮箱"),
email: z.string().email("setting.account.email.valid.message"),
});
const Account = () => {
const { toast } = useToast();
const navigate = useNavigate();
const { t } = useTranslation();
const [changed, setChanged] = useState(false);
@@ -43,8 +45,8 @@ const Account = () => {
getPb().authStore.clear();
toast({
title: "修改账户邮箱功",
description: "请重新登录",
title: t("setting.account.email.change.succeed"),
description: t("setting.account.log.back.in"),
});
setTimeout(() => {
navigate("/login");
@@ -52,7 +54,7 @@ const Account = () => {
} catch (e) {
const message = getErrMessage(e);
toast({
title: "修改账户邮箱失败",
title: t("setting.account.email.change.failed"),
description: message,
variant: "destructive",
});
@@ -72,10 +74,10 @@ const Account = () => {
name="email"
render={({ field }) => (
<FormItem>
<FormLabel></FormLabel>
<FormLabel>{t('email')}</FormLabel>
<FormControl>
<Input
placeholder="请输入邮箱"
placeholder={t('setting.email.placeholder')}
{...field}
type="email"
onChange={(e) => {
@@ -92,10 +94,10 @@ const Account = () => {
<div className="flex justify-end">
{changed ? (
<Button type="submit"></Button>
<Button type="submit">{t('setting.submit')}</Button>
) : (
<Button type="submit" disabled variant={"secondary"}>
{t('setting.submit')}
</Button>
)}
</div>

View File

@@ -9,15 +9,18 @@ import {
AccordionTrigger,
} from "@/components/ui/accordion";
import { NotifyProvider } from "@/providers/notify";
import { useTranslation } from "react-i18next";
const Notify = () => {
const { t } = useTranslation();
return (
<>
<NotifyProvider>
<div className="border rounded-sm p-5 shadow-lg">
<Accordion type={"multiple"} className="dark:text-stone-200">
<AccordionItem value="item-1" className="dark:border-stone-200">
<AccordionTrigger></AccordionTrigger>
<AccordionTrigger>{t('template')}</AccordionTrigger>
<AccordionContent>
<NotifyTemplate />
</AccordionContent>

View File

@@ -14,29 +14,31 @@ import { getPb } from "@/repository/api";
import { zodResolver } from "@hookform/resolvers/zod";
import { useForm } from "react-hook-form";
import { useNavigate } from "react-router-dom";
import { useTranslation } from "react-i18next";
import { z } from "zod";
const formSchema = z
.object({
oldPassword: z.string().min(10, {
message: "密码至少10个字符",
message: "setting.password.length.message",
}),
newPassword: z.string().min(10, {
message: "密码至少10个字符",
message: "setting.password.length.message",
}),
confirmPassword: z.string().min(10, {
message: "密码至少10个字符",
message: "setting.password.length.message",
}),
})
.refine((data) => data.newPassword === data.confirmPassword, {
message: "两次密码不一致",
message: "setting.password.not.match",
path: ["confirmPassword"],
});
const Password = () => {
const { toast } = useToast();
const navigate = useNavigate();
const { t } = useTranslation();
const form = useForm<z.infer<typeof formSchema>>({
resolver: zodResolver(formSchema),
@@ -66,8 +68,8 @@ const Password = () => {
getPb().authStore.clear();
toast({
title: "修改密码成功",
description: "请重新登录",
title: t('setting.password.change.succeed'),
description: t("setting.account.log.back.in"),
});
setTimeout(() => {
navigate("/login");
@@ -75,7 +77,7 @@ const Password = () => {
} catch (e) {
const message = getErrMessage(e);
toast({
title: "修改密码失败",
title: t('setting.password.change.failed'),
description: message,
variant: "destructive",
});
@@ -95,9 +97,9 @@ const Password = () => {
name="oldPassword"
render={({ field }) => (
<FormItem>
<FormLabel></FormLabel>
<FormLabel>{t('setting.password.current.password')}</FormLabel>
<FormControl>
<Input placeholder="当前密码" {...field} type="password" />
<Input placeholder={t('setting.password.current.password')} {...field} type="password" />
</FormControl>
<FormMessage />
@@ -110,7 +112,7 @@ const Password = () => {
name="newPassword"
render={({ field }) => (
<FormItem>
<FormLabel></FormLabel>
<FormLabel>{t('setting.password.new.password')}</FormLabel>
<FormControl>
<Input
placeholder="newPassword"
@@ -129,7 +131,7 @@ const Password = () => {
name="confirmPassword"
render={({ field }) => (
<FormItem>
<FormLabel></FormLabel>
<FormLabel>{t('setting.password.confirm.password')}</FormLabel>
<FormControl>
<Input
placeholder="confirmPassword"
@@ -143,7 +145,7 @@ const Password = () => {
)}
/>
<div className="flex justify-end">
<Button type="submit"></Button>
<Button type="submit">{t('setting.submit')}</Button>
</div>
</form>
</Form>