Skip to content

Commit 76f57d7

Browse files
🌐 chore(i18n): 更新国际化字符串并优化本地化逻辑
- 【新增】代码评审相关的错误提示和报告标题的国际化 - 【新增】模型列表为空提示的国际化支持 - 【优化】SVN命令输出的本地化逻辑,使用LocalizationManager替代硬编码字符串 - 【优化】代码评审报告生成器的标题和标签的本地化处理 - 【重构】统一本地化字符串的格式和用语
1 parent 35cbe88 commit 76f57d7

File tree

5 files changed

+68
-21
lines changed

5 files changed

+68
-21
lines changed

i18n/en.json

+18-2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"openai.models.empty": "No OpenAI models available",
5959
"openai.models.error": "Failed to get OpenAI model list",
6060
"model.not.found": "Selected model not found",
61+
"model.list.empty": "Model list is empty",
6162
"no.commit.message.generated": "No commit message generated",
6263
"input.truncated": "Input content exceeds maximum character limit and has been truncated, this may affect the quality of generated results",
6364
"extension.activation.failed": "Extension activation failed: {0}",
@@ -91,9 +92,24 @@
9192
"doubao.apiKey.missing": "Doubao API Key is not configured. Would you like to configure it now?",
9293
"reviewing.code": "Reviewing code...",
9394
"getting.file.changes": "Getting file changes...",
94-
"reviewing.file": "Reviewing file: {0}",
95+
"reviewing.file": "file: {0}",
9596
"preparing.results": "Preparing review results...",
9697
"review.all.failed": "All files review failed",
9798
"review.complete.count": "Completed code review for {0} files",
98-
"review.results.title": "Code Review Results"
99+
"review.results.title": "Code Review Results",
100+
"codeReview.generation.failed": "Code review generation failed: {0}",
101+
"no.changes.selected": "No files selected for review",
102+
"no.changes.found": "No changes found for review",
103+
"review.file.failed": "Failed to review file: {0}",
104+
"code.review.failed": "Code review failed: {0}",
105+
"svn.no.files.selected": "No files selected to commit",
106+
"scm.no.provider": "No SVN or Git extension found, please install corresponding version control extension",
107+
"svn.lastModifiedAuthor": "Last Modified Author:",
108+
"svn.authRealm": "Authentication Realm:",
109+
"codeReview.report.title": "Code Review Report",
110+
"codeReview.report.summary": "Summary",
111+
"codeReview.report.findings": "Detailed Findings",
112+
"codeReview.issue.label": "Issue:",
113+
"codeReview.suggestion.label": "Suggestion:",
114+
"codeReview.documentation.label": "Documentation"
99115
}

i18n/zh-cn.json

+19-3
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,26 @@
9090
"dashscope.apiKey.missing": "DashScope API Key 未配置。是否现在配置?",
9191
"doubao.apiKey.missing": "豆包 API Key 未配置。是否现在配置?",
9292
"reviewing.code": "正在进行代码评审...",
93-
"getting.file.changes": "正在获取文件变更...",
94-
"reviewing.file": "正在评审文件:{0}",
93+
"getting.file.changes": "正在获取文件变更...",
94+
"reviewing.file": "评审文件:{0}",
9595
"preparing.results": "正在准备评审结果...",
9696
"review.all.failed": "所有文件评审失败",
9797
"review.complete.count": "已完成 {0} 个文件的代码评审",
98-
"review.results.title": "代码评审结果"
98+
"review.results.title": "代码评审结果",
99+
"codeReview.generation.failed": "代码评审生成失败: {0}",
100+
"model.list.empty": "模型列表为空",
101+
"no.changes.selected": "未选择任何待评审的文件",
102+
"no.changes.found": "未找到需要评审的变更",
103+
"review.file.failed": "评审文件失败: {0}",
104+
"code.review.failed": "代码评审失败: {0}",
105+
"svn.no.files.selected": "未选择要提交的文件",
106+
"scm.no.provider": "未找到可用的SVN或Git扩展,请安装对应的版本控制扩展",
107+
"svn.lastModifiedAuthor": "最后修改的作者:",
108+
"svn.authRealm": "认证领域:",
109+
"codeReview.report.title": "代码评审报告",
110+
"codeReview.report.summary": "总体摘要",
111+
"codeReview.report.findings": "详细问题",
112+
"codeReview.issue.label": "问题:",
113+
"codeReview.suggestion.label": "建议:",
114+
"codeReview.documentation.label": "相关文档"
99115
}

src/scm/SvnUtils.ts

+17-10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { exec } from "child_process";
22
import { promisify } from "util";
33
import * as fs from "fs";
44
import * as path from "path";
5+
import { LocalizationManager } from "../utils/LocalizationManager";
56

67
const execAsync = promisify(exec);
78

@@ -20,8 +21,14 @@ export class SvnUtils {
2021
): Promise<string | undefined> {
2122
try {
2223
const { stdout } = await execAsync("svn info", { cwd: workspacePath });
23-
// 匹配"最后修改的作者:"后面的内容
24-
const authorMatch = stdout.match(/: (.+)/);
24+
// 改用LocalizationManager
25+
const authorMatch = stdout.match(
26+
new RegExp(
27+
`${LocalizationManager.getInstance().getMessage(
28+
"svn.lastModifiedAuthor"
29+
)} (.+)`
30+
)
31+
);
2532
return authorMatch?.[1]?.trim();
2633
} catch {
2734
return undefined;
@@ -122,16 +129,12 @@ export class SvnUtils {
122129
urlOutput: string
123130
): string | undefined {
124131
const credentials = this.parseCredentials(authOutput);
125-
console.log("credentials", credentials);
126-
console.log("urlOutput", urlOutput);
127132
// 从svn info输出中提取URL
128133
const urlMatch = urlOutput.match(/URL: (.+)/);
129-
console.log("urlMatch", urlMatch);
130134

131135
if (urlMatch) {
132136
const repoUrl = urlMatch[1].trim();
133137
const matchingCred = this.findMatchingCredential(credentials, repoUrl);
134-
console.log("matchingCred", matchingCred);
135138
if (matchingCred) {
136139
return matchingCred;
137140
}
@@ -147,15 +150,19 @@ export class SvnUtils {
147150
* @returns 包含用户名、认证领域和仓库ID的认证信息数组
148151
*/
149152
private static parseCredentials(authOutput: string) {
150-
// 按分隔线分割认证块
151153
return authOutput
152154
.split(/\n?-+\n/)
153155
.filter((block) => block.trim())
154156
.map((block) => {
155-
// 匹配用户名
156157
const usernameMatch = block.match(/Username: (.+)/);
157-
// 匹配认证领域和仓库ID
158-
const realmMatch = block.match(/: <([^>]+)>\s*([^\n]*)/);
158+
// 改用LocalizationManager
159+
const realmMatch = block.match(
160+
new RegExp(
161+
`${LocalizationManager.getInstance().getMessage(
162+
"svn.authRealm"
163+
)} <([^>]+)>\\s*([^\\n]*)`
164+
)
165+
);
159166
return {
160167
username: usernameMatch?.[1]?.trim() || null,
161168
realm: realmMatch?.[1]?.trim() || null,

src/services/ModelPickerService.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export class ModelPickerService {
9595
}
9696
return undefined;
9797
} catch (error) {
98-
console.error("获取模型列表失败:", error);
98+
console.error(locManager.getMessage("model.list.failed"), error);
9999
NotificationHandler.error("model.list.failed");
100100
return undefined;
101101
}

src/utils/CodeReviewReportGenerator.ts

+13-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import { CodeReviewResult, CodeReviewIssue } from "../ai/types";
2+
import * as vscode from "vscode";
3+
import { LocalizationManager } from "../utils/LocalizationManager";
24

35
/**
46
* 代码审查报告生成器,将代码审查结果转换为格式化的 Markdown 文档
57
*/
68
export class CodeReviewReportGenerator {
9+
private static readonly locManager = LocalizationManager.getInstance();
10+
711
/**
812
* 不同严重程度对应的 emoji 图标
913
* @private
@@ -55,7 +59,9 @@ export class CodeReviewReportGenerator {
5559
* @returns {string} Markdown 格式的报告头部
5660
*/
5761
private static generateHeader(summary: string): string {
58-
return `# Code Review Report\n\n## Summary\n\n${summary}\n\n`;
62+
const title = this.locManager.getMessage("codeReview.report.title");
63+
const summaryLabel = this.locManager.getMessage("codeReview.report.summary");
64+
return `# ${title}\n\n## ${summaryLabel}\n\n${summary}\n\n`;
5965
}
6066

6167
/**
@@ -67,7 +73,8 @@ export class CodeReviewReportGenerator {
6773
private static generateDetailedFindings(
6874
sections: Record<string, CodeReviewIssue[]>
6975
): string {
70-
let markdown = `## Detailed Findings\n\n`;
76+
const findings = this.locManager.getMessage("codeReview.report.findings");
77+
let markdown = `## ${findings}\n\n`;
7178

7279
// 遍历每个文件的问题
7380
for (const [filePath, issues] of Object.entries(sections)) {
@@ -94,8 +101,8 @@ export class CodeReviewReportGenerator {
94101
}: Line ${issue.startLine}${issue.endLine ? `-${issue.endLine}` : ""}\n\n`;
95102

96103
// 添加问题描述和建议
97-
section += `**Issue:** ${issue.description}\n\n`;
98-
section += `**Suggestion:** ${issue.suggestion}\n\n`;
104+
section += `**${this.locManager.getMessage("codeReview.issue.label")}** ${issue.description}\n\n`;
105+
section += `**${this.locManager.getMessage("codeReview.suggestion.label")}** ${issue.suggestion}\n\n`;
99106

100107
// 如果有代码示例,添加代码块
101108
if (issue.code) {
@@ -104,7 +111,8 @@ export class CodeReviewReportGenerator {
104111

105112
// 如果有相关文档,添加链接
106113
if (issue.documentation) {
107-
section += `📚 [Documentation](${issue.documentation})\n\n`;
114+
const docLabel = this.locManager.getMessage("codeReview.documentation.label");
115+
section += `📚 [${docLabel}](${issue.documentation})\n\n`;
108116
}
109117

110118
section += `---\n\n`;

0 commit comments

Comments
 (0)