diff --git a/README.en.md b/README.en.md
index a60ce703..5f15dd41 100644
--- a/README.en.md
+++ b/README.en.md
@@ -122,7 +122,7 @@ Practice statistics show total practice, accuracy and active months, with distri
### Explanations and demos
-- **🎬 SVG animated explanations**: AI generates step-by-step SVG animations of the solution, with play/pause, seeking, replay and full screen. On by default; turn it off in **Settings → General**.
+- **🎬 SVG animated explanations**: AI generates step-by-step SVG animations of the solution, with play/pause, seeking, replay and full screen. Animation text follows the interface language: the English interface generates an English version and the Chinese interface a Chinese one. Both are kept, and switching the language shows the matching version automatically. On by default; turn it off in **Settings → General**.
- **📐 GeoGebra demos**: for math and physics questions, AI can generate interactive GeoGebra figures. Off by default; turn it on in **Settings → General**.
- Generated animations and GeoGebra demos can be deleted (with confirmation).
diff --git a/README.md b/README.md
index f3fe0b86..7770d7d2 100644
--- a/README.md
+++ b/README.md
@@ -120,7 +120,7 @@
### 讲解与演示
-- **🎬 SVG 动画讲解**:AI 按解题思路生成分步骤的 SVG 动画,支持播放/暂停、拖动进度、重播和全屏。默认开启,可在「设置 → 通用」中关闭。
+- **🎬 SVG 动画讲解**:AI 按解题思路生成分步骤的 SVG 动画,支持播放/暂停、拖动进度、重播和全屏。动画文字与界面语言一致:中文界面生成中文版、英文界面生成英文版,两种版本分别保存,切换语言时自动显示对应版本。默认开启,可在「设置 → 通用」中关闭。
- **📐 GeoGebra 动态演示**:数学、物理题可由 AI 生成交互式 GeoGebra 图形。默认关闭,可在「设置 → 通用」中开启。
- 已生成的动画讲解和 GeoGebra 演示都可删除(需二次确认)。
diff --git a/doc/wiki/User-Guide.md b/doc/wiki/User-Guide.md
index 1be78928..fdc83115 100644
--- a/doc/wiki/User-Guide.md
+++ b/doc/wiki/User-Guide.md
@@ -50,7 +50,7 @@
## 配图和动态讲解
- **SVG 配图**:由 AI 根据题目生成静态 SVG,供详情、练习和打印使用;原图可单独查看。
-- **SVG 动画讲解**:按解题思路分步骤演示,支持暂停、拖动进度、重播和全屏,个人设置默认开启。
+- **SVG 动画讲解**:按解题思路分步骤演示,支持暂停、拖动进度、重播和全屏,个人设置默认开启。动画文字跟随界面语言,中英文版本分别生成和保存,切换语言时自动显示对应版本。
- **GeoGebra 动态演示**:供数学、物理题生成交互图形,个人设置默认关闭。
已生成的动画和 GeoGebra 演示可在确认后删除。生成的图形和解答需要人工核对,尤其是几何位置、计数过程和结论。
diff --git a/prisma/migrations/20261022000141_add_svg_animation_en/migration.sql b/prisma/migrations/20261022000141_add_svg_animation_en/migration.sql
new file mode 100644
index 00000000..183abbc0
--- /dev/null
+++ b/prisma/migrations/20261022000141_add_svg_animation_en/migration.sql
@@ -0,0 +1,2 @@
+-- 仅新增列:英文版 SVG 动画讲解(svgAnimation 为中文版),不影响已有数据。
+ALTER TABLE "ErrorItem" ADD COLUMN "svgAnimationEn" TEXT;
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index 6d99f6ee..ee3fb829 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -106,7 +106,8 @@ model ErrorItem {
mistakeStatus String? // not_attempted, wrong_attempt, unknown
knowledgePoints String? // [DEPRECATED] JSON string - kept for migration only
geogebraCommands String? // GeoGebra commands for interactive demo (JSON or newline-separated)
- svgAnimation String? // AI 生成的 SVG 动画讲解(已净化)
+ svgAnimation String? // AI 生成的 SVG 动画讲解(已净化),中文版
+ svgAnimationEn String? // 英文版 SVG 动画讲解(已净化),界面为英文时使用
// New: many-to-many relation with KnowledgeTag
tags KnowledgeTag[]
diff --git a/src/__tests__/integration/svg-animation.test.ts b/src/__tests__/integration/svg-animation.test.ts
index 461f32e2..dbd6d8df 100644
--- a/src/__tests__/integration/svg-animation.test.ts
+++ b/src/__tests__/integration/svg-animation.test.ts
@@ -20,8 +20,8 @@ import { POST, DELETE } from '@/app/api/error-items/[id]/svg-animation/route';
import { DELETE as DELETE_GEOGEBRA } from '@/app/api/error-items/[id]/geogebra/route';
const context = { params: Promise.resolve({ id: 'e1' }) };
-const generate = () => POST(new Request('http://localhost', { method: 'POST' }), context);
-const remove = () => DELETE(new Request('http://localhost', { method: 'DELETE' }), context);
+const generate = (body?: unknown) => POST(new Request('http://localhost', { method: 'POST', ...(body ? { body: JSON.stringify(body) } : {}) }), context);
+const remove = (query = '') => DELETE(new Request(`http://localhost${query}`, { method: 'DELETE' }), context);
const removeGeogebra = () => DELETE_GEOGEBRA(new Request('http://localhost', { method: 'DELETE' }), context);
const svg = '';
@@ -34,15 +34,35 @@ describe('SVG 动画讲解接口', () => {
mocks.errorItem.update.mockResolvedValue({});
});
- it('POST 把题目、答案、解析和配图交给 AI,保存生成的动画', async () => {
+ it('POST 把题目、答案、解析和配图交给 AI,未指定语言时生成并保存中文版动画', async () => {
mocks.generateSvgAnimation.mockResolvedValue(svg);
const response = await generate();
expect(response.status).toBe(200);
- expect(mocks.generateSvgAnimation).toHaveBeenCalledWith('求面积', '6', '底乘高', '');
+ expect(mocks.generateSvgAnimation).toHaveBeenCalledWith('求面积', '6', '底乘高', '', 'zh');
+ expect(mocks.errorItem.update).toHaveBeenCalledWith({ where: { id: 'e1' }, data: { svgAnimation: svg } });
+ expect(await response.json()).toEqual({ svgAnimation: svg, language: 'zh' });
+ });
+
+ it('POST language=en 时生成英文版动画,单独保存且不覆盖中文版', async () => {
+ mocks.generateSvgAnimation.mockResolvedValue(svg);
+
+ const response = await generate({ language: 'en' });
+
+ expect(response.status).toBe(200);
+ expect(mocks.generateSvgAnimation).toHaveBeenCalledWith('求面积', '6', '底乘高', '', 'en');
+ expect(mocks.errorItem.update).toHaveBeenCalledWith({ where: { id: 'e1' }, data: { svgAnimationEn: svg } });
+ expect(await response.json()).toEqual({ svgAnimation: svg, language: 'en' });
+ });
+
+ it('POST 不支持的语言按中文处理', async () => {
+ mocks.generateSvgAnimation.mockResolvedValue(svg);
+
+ await generate({ language: 'fr' });
+
+ expect(mocks.generateSvgAnimation.mock.calls[0][4]).toBe('zh');
expect(mocks.errorItem.update).toHaveBeenCalledWith({ where: { id: 'e1' }, data: { svgAnimation: svg } });
- expect(await response.json()).toEqual({ svgAnimation: svg });
});
it('POST 题目文字为空时返回 NO_QUESTION_TEXT,不调用 AI', async () => {
@@ -74,13 +94,20 @@ describe('SVG 动画讲解接口', () => {
expect((await response.json()).message).toBe('AI_TIMEOUT_ERROR');
});
- it('DELETE 清空已生成的动画', async () => {
+ it('DELETE 未指定语言时清空中文版动画', async () => {
const response = await remove();
expect(response.status).toBe(200);
expect(mocks.errorItem.update).toHaveBeenCalledWith({ where: { id: 'e1' }, data: { svgAnimation: null } });
});
+ it('DELETE language=en 只清空英文版动画', async () => {
+ const response = await remove('?language=en');
+
+ expect(response.status).toBe(200);
+ expect(mocks.errorItem.update).toHaveBeenCalledWith({ where: { id: 'e1' }, data: { svgAnimationEn: null } });
+ });
+
it('未登录返回 401,不能操作他人的题目', async () => {
mocks.session = null;
expect((await generate()).status).toBe(401);
diff --git a/src/__tests__/unit/ai/openai-provider.test.ts b/src/__tests__/unit/ai/openai-provider.test.ts
index 40a78db5..93af0701 100644
--- a/src/__tests__/unit/ai/openai-provider.test.ts
+++ b/src/__tests__/unit/ai/openai-provider.test.ts
@@ -392,6 +392,17 @@ describe('OpenAI Provider SVG 动画讲解', () => {
expect(svg).not.toContain('