From 225352bdc5697d5da82e7c49816d276f12410a1f Mon Sep 17 00:00:00 2001 From: margrop <1731827+margrop@users.noreply.github.com> Date: Fri, 4 Dec 2026 14:50:48 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=B8=85=E7=90=86=E5=89=8D=E7=AB=AF?= =?UTF-8?q?=E7=A1=AC=E7=BC=96=E7=A0=81=E6=96=87=E6=A1=88=E5=B9=B6=E6=8C=89?= =?UTF-8?q?=E8=AF=AD=E8=A8=80=E6=98=BE=E7=A4=BA=E5=B9=B4=E7=BA=A7=E4=B8=8E?= =?UTF-8?q?=E5=88=86=E5=80=BC=E6=8B=AC=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refs: https://github.com/margrop/wrong-notebook/issues/89 --- e2e/i18n-consistency.spec.ts | 73 +++++++++++++++++++ src/app/error-items/[id]/page.tsx | 4 +- src/app/exams/[id]/exam-detail-questions.tsx | 2 +- src/app/exams/[id]/page.tsx | 2 +- src/app/exams/[id]/print/exam-print-sheet.tsx | 6 +- src/components/banks/bank-detail.tsx | 3 +- src/components/banks/bank-question-card.tsx | 6 +- src/components/error-detail/question-card.tsx | 2 +- .../import-batch/draft-item-card.tsx | 5 +- .../import-tasks/import-task-card.tsx | 2 +- .../mobile-nav-preference-setting.tsx | 6 +- src/components/tags/custom-tags.tsx | 2 +- src/lib/i18n/en.ts | 9 +++ src/lib/i18n/zh.ts | 9 +++ 14 files changed, 111 insertions(+), 20 deletions(-) create mode 100644 e2e/i18n-consistency.spec.ts diff --git a/e2e/i18n-consistency.spec.ts b/e2e/i18n-consistency.spec.ts new file mode 100644 index 00000000..82f5ac96 --- /dev/null +++ b/e2e/i18n-consistency.spec.ts @@ -0,0 +1,73 @@ +import { test, expect, type Page } from './support/fixtures'; +import { ADMIN_PASSWORD } from './helpers'; + +async function login(page: Page) { + const hydrated = page.waitForResponse((response) => response.url().endsWith('/api/register/status')); + await page.goto('/login'); + await hydrated; + await page.getByLabel(/邮箱|Email/).fill('admin@localhost'); + await page.getByLabel(/^密码$|^Password$/).fill(ADMIN_PASSWORD); + await page.getByRole('button', { name: /登录|Login/ }).click(); + await page.waitForURL('**/', { timeout: 15000 }); +} + +/** 详情页中标题为 title 的卡片 */ +function card(page: Page, title: string) { + return page.locator('[data-slot="card"]').filter({ has: page.locator('[data-slot="card-title"]', { hasText: title }) }); +} + +test('错题详情编辑占位文案随界面语言切换,不再固定英文', async ({ page }) => { + test.setTimeout(60000); + await login(page); + const notebookRes = await page.request.post('/api/notebooks', { + data: { name: `语言文案测试-${Date.now()}`, stage: 'junior_high', subjectKey: 'physics' }, + }); + expect(notebookRes.ok()).toBeTruthy(); + const notebook = await notebookRes.json(); + const itemRes = await page.request.post('/api/error-items', { + data: { + subjectId: notebook.id, + questionText: `语言文案题目 ${Date.now() % 1000}`, + answerText: 's = vt', + analysis: '路程等于速度乘以时间。', + knowledgePoints: ['匀速直线运动'], + }, + }); + expect(itemRes.ok()).toBeTruthy(); + const item = await itemRes.json(); + + await page.goto(`/error-items/${item.id}`); + await expect(page.getByRole('heading', { name: '错题详情' })).toBeVisible({ timeout: 15000 }); + + await page.getByTitle('编辑 题目').click(); + expect(await card(page, '题目').locator('textarea').getAttribute('placeholder')).toBe('输入题目内容...'); + await card(page, '题目').getByRole('button', { name: '取消' }).click(); + + await page.getByTitle('编辑 参考答案').click(); + expect(await card(page, '参考答案').locator('textarea').getAttribute('placeholder')).toBe('输入答案...'); + await card(page, '参考答案').getByRole('button', { name: '取消' }).click(); + + await page.getByTitle('编辑 解析').click(); + expect(await card(page, '解析').locator('textarea').getAttribute('placeholder')).toBe('输入解析...'); + await card(page, '解析').getByRole('button', { name: '取消' }).click(); + + await page.evaluate(() => localStorage.setItem('app-language', 'en')); + await page.reload(); + await expect(page.getByRole('heading', { name: 'Wrong Answer Detail' })).toBeVisible({ timeout: 15000 }); + + await page.getByTitle('Edit Question', { exact: true }).click(); + expect(await card(page, 'Question').locator('textarea').getAttribute('placeholder')).toBe('Enter question text...'); + await card(page, 'Question').getByRole('button', { name: 'Cancel' }).click(); + + await page.getByTitle('Edit Correct Answer', { exact: true }).click(); + expect(await card(page, 'Correct Answer').locator('textarea').getAttribute('placeholder')).toBe('Enter answer...'); + await card(page, 'Correct Answer').getByRole('button', { name: 'Cancel' }).click(); + + await page.getByTitle('Edit Analysis', { exact: true }).click(); + expect(await card(page, 'Analysis').locator('textarea').getAttribute('placeholder')).toBe('Enter analysis...'); + await card(page, 'Analysis').getByRole('button', { name: 'Cancel' }).click(); + + await page.evaluate(() => localStorage.setItem('app-language', 'zh')); + expect((await page.request.delete(`/api/error-items/${item.id}/delete`)).ok()).toBeTruthy(); + expect((await page.request.delete(`/api/notebooks/${notebook.id}`)).ok()).toBeTruthy(); +}); diff --git a/src/app/error-items/[id]/page.tsx b/src/app/error-items/[id]/page.tsx index 98eb3260..2b77c4e8 100644 --- a/src/app/error-items/[id]/page.tsx +++ b/src/app/error-items/[id]/page.tsx @@ -218,7 +218,7 @@ export default function ErrorDetailPage() { onSave={(answerText) => saveFields({ answerText })} logLabel="answer" rows={5} - placeholder="Enter answer..." + placeholder={t.detail.answerPlaceholder} cardClassName="border-primary/20" titleClassName="text-primary" contentClassName="font-semibold" @@ -241,7 +241,7 @@ export default function ErrorDetailPage() { onSave={(analysis) => saveFields({ analysis })} logLabel="analysis" rows={12} - placeholder="Enter analysis..." + placeholder={t.detail.analysisPlaceholder} readOnly={readOnly} headerActions={ updateItem({ analysisFigureSvg })} onReload={reload} />} > diff --git a/src/app/exams/[id]/exam-detail-questions.tsx b/src/app/exams/[id]/exam-detail-questions.tsx index 5c8b4b6c..5d91ce16 100644 --- a/src/app/exams/[id]/exam-detail-questions.tsx +++ b/src/app/exams/[id]/exam-detail-questions.tsx @@ -47,7 +47,7 @@ function SectionHeader({ section }: { section: ExamSection } {summary} {section.scoreTotal !== null && section.unscored > 0 && ( - ({t.exam.sectionSummaryUnscored.replace("{count}", String(section.unscored))}) + {t.exam.parenthesizedUnscored.replace("{count}", String(section.unscored))} )} diff --git a/src/app/exams/[id]/page.tsx b/src/app/exams/[id]/page.tsx index aa7c3482..c0cadbe7 100644 --- a/src/app/exams/[id]/page.tsx +++ b/src/app/exams/[id]/page.tsx @@ -247,7 +247,7 @@ export default function ExamDetailPage() { {t.exam.totalScore.replace("{total}", formatExamScore(readyScoreSummary.total))} {readyScoreSummary.unscored > 0 && ( - ({t.exam.totalScoreUnscored.replace("{count}", String(readyScoreSummary.unscored))}) + {t.exam.parenthesizedUnscored.replace("{count}", String(readyScoreSummary.unscored))} )} )} diff --git a/src/app/exams/[id]/print/exam-print-sheet.tsx b/src/app/exams/[id]/print/exam-print-sheet.tsx index 5ca42f53..b7312e2d 100644 --- a/src/app/exams/[id]/print/exam-print-sheet.tsx +++ b/src/app/exams/[id]/print/exam-print-sheet.tsx @@ -68,7 +68,7 @@ function ExamPrintQuestion({
{displayNumber}. - {typeof question.score === 'number' && `(${formatExamScore(question.score)} ${scoreUnit})`} + {typeof question.score === 'number' && t.exam.parenthesizedScore.replace("{score}", formatExamScore(question.score)).replace("{unit}", scoreUnit)} {t.exam.sourceLabel}: {sourceNo} {showMarkers && } @@ -124,7 +124,7 @@ function ExamPrintSectionHeader({ section }: { section: ExamSection {summary} {section.scoreTotal !== null && section.unscored > 0 && ( - ({t.exam.sectionSummaryUnscored.replace("{count}", String(section.unscored))}) + {t.exam.parenthesizedUnscored.replace("{count}", String(section.unscored))} )}
@@ -149,7 +149,7 @@ export const ExamPrintSheet = forwardRef(fu const questions = paper.questions.filter((question) => question.status === "ready" && question.questionText); // 满分只统计已设分值的题目;全部未设时不显示满分行,打印与旧版一致 const fullScore = summarizeExamScores(questions.map((question) => question.score ?? null)).total; - const scoreUnit = language === "en" ? "pts" : "分"; + const scoreUnit = t.exam.scoreUnit; // 按题型分大题:开启且全卷均为就绪题目时才分组(与非分组打印的过滤口径一致) const sections = paper.groupByType ? groupExamQuestions(questions, language, customTypes) : null; diff --git a/src/components/banks/bank-detail.tsx b/src/components/banks/bank-detail.tsx index b7a97cd7..2cdf0a72 100644 --- a/src/components/banks/bank-detail.tsx +++ b/src/components/banks/bank-detail.tsx @@ -9,7 +9,6 @@ import { apiClient } from "@/lib/api-client"; import { confirmDialog, toast } from "@/lib/feedback"; import { getApiErrorMessage } from "@/lib/error-message"; import { frontendLogger } from "@/lib/frontend-logger"; -import { GRADE_NAMES } from "@/lib/grade-options"; import { BankQuestionCard } from "@/components/banks/bank-question-card"; import type { QuestionBankDetail } from "@/lib/question-bank/types"; import type { Notebook } from "@/types/api"; @@ -205,7 +204,7 @@ export function BankDetail({ bankId, notebooks, onChanged, onDeleted, canManage > {grades.map((value) => ( - + ))} diff --git a/src/components/banks/bank-question-card.tsx b/src/components/banks/bank-question-card.tsx index 282e0264..c7106131 100644 --- a/src/components/banks/bank-question-card.tsx +++ b/src/components/banks/bank-question-card.tsx @@ -10,7 +10,6 @@ import { useLanguage } from "@/contexts/LanguageContext"; import { apiClient } from "@/lib/api-client"; import { confirmDialog, toast } from "@/lib/feedback"; import { getApiErrorMessage } from "@/lib/error-message"; -import { GRADE_NAMES } from "@/lib/grade-options"; import { QUESTION_TYPE_NAMES_EN, QUESTION_TYPE_NAMES_ZH } from "@/lib/question/question-type"; import type { QuestionType } from "@/lib/question/question-type"; import type { BankQuestionRow } from "@/lib/question-bank/types"; @@ -69,12 +68,13 @@ export function BankQuestionCard({ bankId, question, notebooks, onChanged, canMa }; const questionTypeNames = language === "zh" ? QUESTION_TYPE_NAMES_ZH : QUESTION_TYPE_NAMES_EN; - const gradeName = question.grade ? GRADE_NAMES[question.grade - 1] : null; + const gradeName = question.grade ? t.gradeSelection.names[question.grade - 1] : null; + const semesterName = question.semester === "上" ? t.gradeSelection.firstSemester : question.semester === "下" ? t.gradeSelection.secondSemester : question.semester ?? ""; return (
- {gradeName && {gradeName}{question.semester ?? ""}} + {gradeName && {gradeName}{semesterName}} {question.questionType && {questionTypeNames[question.questionType as QuestionType] ?? question.questionType}} {question.source && {question.source}} diff --git a/src/components/error-detail/question-card.tsx b/src/components/error-detail/question-card.tsx index c703d0ea..b3b022b1 100644 --- a/src/components/error-detail/question-card.tsx +++ b/src/components/error-detail/question-card.tsx @@ -48,7 +48,7 @@ export function QuestionCard({ item, educationStage, saveFields, onUpdate, reloa {question.editing ? (
- +
diff --git a/src/components/import-batch/draft-item-card.tsx b/src/components/import-batch/draft-item-card.tsx index eef67f88..c0f840fe 100644 --- a/src/components/import-batch/draft-item-card.tsx +++ b/src/components/import-batch/draft-item-card.tsx @@ -44,6 +44,7 @@ interface DraftItemCardProps { /** 题目原图缩略图:点击放大,可删除 */ function ItemImageThumbnail({ image, alt, onRemove }: { image: string; alt: string; onRemove: () => void }) { + const { t } = useLanguage(); const [enlarged, setEnlarged] = useState(false); return (
@@ -61,7 +62,7 @@ function ItemImageThumbnail({ image, alt, onRemove }: { image: string; alt: stri variant="ghost" className="absolute -right-2 -top-2 h-6 w-6 rounded-full bg-background border shadow-sm" onClick={onRemove} - aria-label="删除图片" + aria-label={t.importBatch.removeImage} > @@ -70,7 +71,7 @@ function ItemImageThumbnail({ image, alt, onRemove }: { image: string; alt: stri type="button" className="fixed inset-0 z-50 flex items-center justify-center bg-black/80 p-4" onClick={() => setEnlarged(false)} - aria-label="关闭大图" + aria-label={t.importBatch.closeImage} > {alt} diff --git a/src/components/import-tasks/import-task-card.tsx b/src/components/import-tasks/import-task-card.tsx index 3d3a19ab..264a1a26 100644 --- a/src/components/import-tasks/import-task-card.tsx +++ b/src/components/import-tasks/import-task-card.tsx @@ -91,7 +91,7 @@ export function ImportTaskCard({ task, now, onReview, onViewItem, onRetry, onDis {task.attempts > 1 && {t.importTasks.attempts.replace("{count}", String(task.attempts))}}
{stages.length > 0 && ( -
    +
      {stages.map(({ stage, ms }) => (
    • {t.importTasks.timings[stage]} {formatDuration(ms)}
    • ))} diff --git a/src/components/settings/mobile-nav-preference-setting.tsx b/src/components/settings/mobile-nav-preference-setting.tsx index 7104b9b4..304fac59 100644 --- a/src/components/settings/mobile-nav-preference-setting.tsx +++ b/src/components/settings/mobile-nav-preference-setting.tsx @@ -40,12 +40,12 @@ export function MobileNavPreferenceSetting() { - {t.settings?.general?.mobileNavFourthOptions?.exams || "试卷"} - {t.settings?.general?.mobileNavFourthOptions?.review || "复习"} + {t.settings?.general?.mobileNavFourthOptions?.exams || "Exams"} + {t.settings?.general?.mobileNavFourthOptions?.review || "Review"}

      - {t.settings?.general?.mobileNavFourthDesc || "选择手机底部导航栏的第 4 个入口,默认为试卷。"} + {t.settings?.general?.mobileNavFourthDesc || "Choose the 4th entry in the mobile bottom navigation. Exams is the default."}

      {message &&

      {message}

      }
diff --git a/src/components/tags/custom-tags.tsx b/src/components/tags/custom-tags.tsx index 98015172..12a5de53 100644 --- a/src/components/tags/custom-tags.tsx +++ b/src/components/tags/custom-tags.tsx @@ -62,7 +62,7 @@ export function CustomTags({ tagSet }: CustomTagsProps) { await fetchCustomTags(); } catch (error) { frontendLogger.error('[Tags]', 'Failed to delete tag', { error }); - toast.error("Failed to delete tag"); + toast.error(t.tags?.custom?.deleteFailed || "Failed to delete tag"); } }; diff --git a/src/lib/i18n/en.ts b/src/lib/i18n/en.ts index bdc5864b..720c07a2 100644 --- a/src/lib/i18n/en.ts +++ b/src/lib/i18n/en.ts @@ -692,6 +692,9 @@ export const en = { wrongAnswerImageAlt: "My answer image", title: "Wrong Answer Detail", question: "Question", + questionPlaceholder: "Enter question text...", + answerPlaceholder: "Enter answer...", + analysisPlaceholder: "Enter analysis...", originalProblem: "Original Problem", yourNotes: "Your Answer / Notes", noNotes: "No notes added yet.", @@ -880,6 +883,7 @@ export const en = { success: "Tag added successfully!", exists: "Tag already exists", deleteConfirm: "Are you sure you want to delete tag \"{tag}\"?", + deleteFailed: "Failed to delete tag", selectGrade: "Select Grade", noGrade: "No Grade", }, @@ -1816,6 +1820,7 @@ export const en = { savedTo: "Saved to \"{notebook}\" (ID: {id})", duplicateSaved: "Duplicate question: recorded in the existing question's practice history", itemDeleted: "Saved, but the question has since been deleted", + timingsLabel: "Timings", timings: { read: "Read", convert: "Convert", @@ -1968,6 +1973,7 @@ export const en = { imageTextHint: "The text here only helps you recognize each question. After you start, each question is recognized again from its area on the photo.", questionImage: "Question image", removeImage: "Remove image", + closeImage: "Close image", submitting: "Submitting…", discard: "Discard batch", discardConfirm: "Discard this batch? Questions already imported are kept; unfinished results will be deleted.", @@ -2192,6 +2198,9 @@ export const en = { sectionSummary: "{count} question(s)", sectionSummaryScored: "{count} question(s), {total} pts in total", sectionSummaryUnscored: "{count} question(s) without score", + parenthesizedUnscored: " ({count} question(s) without score)", + parenthesizedScore: "({score} {unit})", + scoreUnit: "pts", answerKey: "Answer Key", answerLabel: "Answer", analysisLabel: "Analysis", diff --git a/src/lib/i18n/zh.ts b/src/lib/i18n/zh.ts index ebb7a1e7..741ff279 100644 --- a/src/lib/i18n/zh.ts +++ b/src/lib/i18n/zh.ts @@ -692,6 +692,9 @@ export const zh = { wrongAnswerImageAlt: "我的答案图片", title: "错题详情", question: "题目", + questionPlaceholder: "输入题目内容...", + answerPlaceholder: "输入答案...", + analysisPlaceholder: "输入解析...", originalProblem: "原始问题", yourNotes: "你的笔记 / 答案", noNotes: "暂无笔记", @@ -880,6 +883,7 @@ export const zh = { success: "标签添加成功!", exists: "标签已存在", deleteConfirm: "确定要删除标签 \"{tag}\" 吗?", + deleteFailed: "删除标签失败", selectGrade: "选择年级", noGrade: "不选择年级", }, @@ -1815,6 +1819,7 @@ export const zh = { savedTo: "已保存到「{notebook}」,题目 ID:{id}", duplicateSaved: "重复题:已记入原题的做错记录", itemDeleted: "已保存,但该错题之后已被删除", + timingsLabel: "耗时明细", timings: { read: "读取", convert: "转换", @@ -1967,6 +1972,7 @@ export const zh = { imageTextHint: "这里的文字仅用于辨认题目;开始后会按每道题在原图上的区域重新识别。", questionImage: "题目原图", removeImage: "删除图片", + closeImage: "关闭大图", submitting: "正在提交…", discard: "放弃这批", discardConfirm: "确定放弃这批题目?已导入的错题不受影响,未完成的结果将被删除。", @@ -2191,6 +2197,9 @@ export const zh = { sectionSummary: "共 {count} 题", sectionSummaryScored: "共 {count} 题,共 {total} 分", sectionSummaryUnscored: "{count} 题未设分值", + parenthesizedUnscored: "({count} 题未设分值)", + parenthesizedScore: "({score} {unit})", + scoreUnit: "分", answerKey: "参考答案与解析", answerLabel: "答案", analysisLabel: "解析",