Skip to content

Commit fbe9193

Browse files
committed
feat: implement internationalization for theme modal and resume title handling
1 parent e6b2cd9 commit fbe9193

File tree

4 files changed

+50
-13
lines changed

4 files changed

+50
-13
lines changed

src/components/shared/ThemeModal.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import { useState } from "react";
44
import { motion } from "framer-motion";
5+
import { useTranslations } from "next-intl";
56
import {
67
AlertDialog,
78
AlertDialogAction,
@@ -10,7 +11,7 @@ import {
1011
AlertDialogDescription,
1112
AlertDialogFooter,
1213
AlertDialogHeader,
13-
AlertDialogTitle
14+
AlertDialogTitle,
1415
} from "@/components/ui/alert-dialog";
1516

1617
interface ThemedAlertDialogProps {
@@ -24,23 +25,24 @@ const ThemeModal = ({
2425
isOpen,
2526
onClose,
2627
onConfirm,
27-
title
28+
title,
2829
}: ThemedAlertDialogProps) => {
2930
const [isHovered, setIsHovered] = useState(false);
31+
const t = useTranslations("themeModal.delete");
3032

3133
const modalContent = {
3234
delete: {
33-
title: "确定要删除吗",
35+
title: t("title"),
3436
description: (
3537
<>
3638
<span>
37-
您确定要删除
39+
{t.raw("description").split("{title}")[0]}
3840
<span className="px-2 font-semibold text-primary">{title}</span>
3941
</span>
40-
吗?
42+
{t.raw("description").split("{title}")[1]}
4143
</>
4244
),
43-
confirmText: "删除",
45+
confirmText: t("confirmText"),
4446
illustration: (
4547
<svg
4648
className="h-32 w-32"
@@ -70,8 +72,8 @@ const ThemeModal = ({
7072
strokeLinecap="round"
7173
/>
7274
</svg>
73-
)
74-
}
75+
),
76+
},
7577
};
7678

7779
const content = modalContent["delete"];
@@ -110,7 +112,7 @@ const ThemeModal = ({
110112

111113
<AlertDialogFooter className="mt-8 flex w-full gap-4 sm:flex-row">
112114
<AlertDialogCancel className="flex-1 rounded-full dark:bg-gray-800 dark:text-neutral-200 text-base font-semibold text-gray-800 ">
113-
取消
115+
{t("cancelText")}
114116
</AlertDialogCancel>
115117
<AlertDialogAction
116118
onClick={onConfirm}

src/i18n/locales/en.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
"description": "Magic Resume is an open source resume editor, free, privacy-first. No registration required, all data stored locally, support data backup and export, ensuring your resume data is always available.",
66
"dashboard": "Dashboard",
77
"edit": "Edit",
8-
"delete": "Delete"
8+
"delete": "Delete",
9+
"newResume": "New Resume",
10+
"copy": "Copy"
911
},
1012
"home": {
1113
"header": {
@@ -615,5 +617,13 @@
615617
},
616618
"templates": {
617619
"switchTemplate": "Switch Template"
620+
},
621+
"themeModal": {
622+
"delete": {
623+
"title": "Confirm Deletion",
624+
"description": "Are you sure you want to delete {title}?",
625+
"confirmText": "Delete",
626+
"cancelText": "Cancel"
627+
}
618628
}
619629
}

src/i18n/locales/zh.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
"description": "魔方简历是一款开源的简历编辑器,免费,隐私优先。无需注册登录,数据完全存储在本地,支持数据导出备份,确保您的简历数据随时可用。",
66
"dashboard": "仪表盘",
77
"edit": "编辑",
8-
"delete": "删除"
8+
"delete": "删除",
9+
"newResume": "新建简历",
10+
"copy": "复制"
911
},
1012
"home": {
1113
"header": {
@@ -617,5 +619,13 @@
617619
},
618620
"templates": {
619621
"switchTemplate": "切换模板"
622+
},
623+
"themeModal": {
624+
"delete": {
625+
"title": "确定要删除吗",
626+
"description": "您确定要删除{title}吗?",
627+
"confirmText": "删除",
628+
"cancelText": "取消"
629+
}
620630
}
621631
}

src/store/useResumeStore.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,10 @@ export const useResumeStore = create(
136136
createdAt: new Date().toISOString(),
137137
updatedAt: new Date().toISOString(),
138138
templateId: template?.id,
139-
title: `新建简历 ${id.slice(0, 6)}`,
139+
title: `${locale === "en" ? "New Resume" : "新建简历"} ${id.slice(
140+
0,
141+
6
142+
)}`,
140143
};
141144

142145
set((state) => ({
@@ -227,10 +230,22 @@ export const useResumeStore = create(
227230
duplicateResume: (resumeId) => {
228231
const newId = generateUUID();
229232
const originalResume = get().resumes[resumeId];
233+
234+
// 获取当前语言环境
235+
const locale =
236+
typeof document !== "undefined"
237+
? document.cookie
238+
.split("; ")
239+
.find((row) => row.startsWith("NEXT_LOCALE="))
240+
?.split("=")[1] || "zh"
241+
: "zh";
242+
230243
const duplicatedResume = {
231244
...originalResume,
232245
id: newId,
233-
title: `${originalResume.title} (复制)`,
246+
title: `${originalResume.title} (${
247+
locale === "en" ? "Copy" : "复制"
248+
})`,
234249
createdAt: new Date().toISOString(),
235250
updatedAt: new Date().toISOString(),
236251
};

0 commit comments

Comments
 (0)