@@ -27,41 +27,18 @@ jobs:
27
27
issues : write
28
28
id-token : write
29
29
steps :
30
- - name : Checkout repository
31
- uses : actions/checkout@v4
32
- with :
33
- fetch-depth : 0
34
-
35
30
- name : Translate issue body with Claude (auto detect)
36
31
id : translate
37
32
uses : anthropics/claude-code-action@v1
38
33
with :
39
34
anthropic_api_key : ${{ secrets.ANTHROPIC_API_KEY }}
40
- github_token : ${{ secrets.GITHUB_TOKEN }}
41
35
prompt : |
42
- 你是一个专业的翻译助手。请翻译以下 GitHub issue 的内容。
43
-
44
- IMPORTANT: 只更新 issue 内容,不要创建 pull request 或分支。
45
-
46
- 任务:
47
- 1. 使用 mcp__github__get_issue 获取 issue 详情
48
- 2. 检测 issue 标题和内容的语言
49
- 3. 如果是中文,翻译成英文;如果是英文,翻译成中文
50
- 4. 不要解释,不要输出原文,只返回翻译内容。
51
-
52
- Issue 信息:
53
- - REPO: ${{ github.repository }}
54
- - ISSUE_NUMBER: ${{ github.event.issue.number }}
55
-
56
- 翻译格式:
57
- ---
58
- **Translation / 翻译**
59
- [翻译内容]
36
+ 你是一名专业的双语翻译。请自动检测下面文本的主要语言(只会是中文或英文):
37
+ - 如果主要语言是中文,请将其准确、地道地翻译为英文,只返回英文翻译。
38
+ - 如果主要语言是英文,请将其准确、地道地翻译为中文,只返回中文翻译。
39
+ - 不要解释,不要输出原文,只返回翻译内容。
60
40
---
61
- {{ issue.body }}
62
- env :
63
- ANTHROPIC_API_KEY : ${{ secrets.ANTHROPIC_API_KEY }}
64
- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
41
+ ${{ github.event.issue.body }}
65
42
66
43
- name : Update issue body with original and translation
67
44
uses : actions/github-script@v7
@@ -72,11 +49,22 @@ jobs:
72
49
const owner = context.repo.owner;
73
50
const repo = context.repo.repo;
74
51
const orig = context.payload.issue.body || '';
75
- const translated = `${{ steps.translate.outputs.result }}`.trim();
76
- const newBody = `## 原文\n${orig}\n\n## 翻译\n${translated}`;
77
- await github.rest.issues.update({
78
- owner,
79
- repo,
80
- issue_number,
81
- body: newBody,
82
- });
52
+
53
+ // Get the translation from the previous step
54
+ // Note: The exact output property may vary, trying common ones
55
+ const stepOutputs = ${{ toJson(steps.translate.outputs) }};
56
+ const translated = (stepOutputs.response || stepOutputs.result || stepOutputs.output || '').trim();
57
+
58
+ // Only update if we have a translation and it's different from original
59
+ if (translated && translated !== orig && translated !== 'undefined') {
60
+ const newBody = `## 原文 / Original\n${orig}\n\n## 翻译 / Translation\n${translated}`;
61
+ await github.rest.issues.update({
62
+ owner,
63
+ repo,
64
+ issue_number,
65
+ body: newBody,
66
+ });
67
+ console.log('Successfully updated issue with translation');
68
+ } else {
69
+ console.log('No valid translation received or translation same as original');
70
+ }
0 commit comments