Skip to content

Commit

Permalink
🌐 chore(i18n): 更新国际化字符串并优化本地化逻辑
Browse files Browse the repository at this point in the history
- 【新增】代码评审相关的错误提示和报告标题的国际化
- 【新增】模型列表为空提示的国际化支持
- 【优化】SVN命令输出的本地化逻辑,使用LocalizationManager替代硬编码字符串
- 【优化】代码评审报告生成器的标题和标签的本地化处理
- 【重构】统一本地化字符串的格式和用语
  • Loading branch information
littleCareless committed Jan 22, 2025
1 parent 35cbe88 commit 76f57d7
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 21 deletions.
20 changes: 18 additions & 2 deletions i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"openai.models.empty": "No OpenAI models available",
"openai.models.error": "Failed to get OpenAI model list",
"model.not.found": "Selected model not found",
"model.list.empty": "Model list is empty",
"no.commit.message.generated": "No commit message generated",
"input.truncated": "Input content exceeds maximum character limit and has been truncated, this may affect the quality of generated results",
"extension.activation.failed": "Extension activation failed: {0}",
Expand Down Expand Up @@ -91,9 +92,24 @@
"doubao.apiKey.missing": "Doubao API Key is not configured. Would you like to configure it now?",
"reviewing.code": "Reviewing code...",
"getting.file.changes": "Getting file changes...",
"reviewing.file": "Reviewing file: {0}",
"reviewing.file": "file: {0}",
"preparing.results": "Preparing review results...",
"review.all.failed": "All files review failed",
"review.complete.count": "Completed code review for {0} files",
"review.results.title": "Code Review Results"
"review.results.title": "Code Review Results",
"codeReview.generation.failed": "Code review generation failed: {0}",
"no.changes.selected": "No files selected for review",
"no.changes.found": "No changes found for review",
"review.file.failed": "Failed to review file: {0}",
"code.review.failed": "Code review failed: {0}",
"svn.no.files.selected": "No files selected to commit",
"scm.no.provider": "No SVN or Git extension found, please install corresponding version control extension",
"svn.lastModifiedAuthor": "Last Modified Author:",
"svn.authRealm": "Authentication Realm:",
"codeReview.report.title": "Code Review Report",
"codeReview.report.summary": "Summary",
"codeReview.report.findings": "Detailed Findings",
"codeReview.issue.label": "Issue:",
"codeReview.suggestion.label": "Suggestion:",
"codeReview.documentation.label": "Documentation"
}
22 changes: 19 additions & 3 deletions i18n/zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,26 @@
"dashscope.apiKey.missing": "DashScope API Key 未配置。是否现在配置?",
"doubao.apiKey.missing": "豆包 API Key 未配置。是否现在配置?",
"reviewing.code": "正在进行代码评审...",
"getting.file.changes": "正在获取文件变更...",
"reviewing.file": "正在评审文件:{0}",
"getting.file.changes": "正在获取文件变更...",
"reviewing.file": "评审文件:{0}",
"preparing.results": "正在准备评审结果...",
"review.all.failed": "所有文件评审失败",
"review.complete.count": "已完成 {0} 个文件的代码评审",
"review.results.title": "代码评审结果"
"review.results.title": "代码评审结果",
"codeReview.generation.failed": "代码评审生成失败: {0}",
"model.list.empty": "模型列表为空",
"no.changes.selected": "未选择任何待评审的文件",
"no.changes.found": "未找到需要评审的变更",
"review.file.failed": "评审文件失败: {0}",
"code.review.failed": "代码评审失败: {0}",
"svn.no.files.selected": "未选择要提交的文件",
"scm.no.provider": "未找到可用的SVN或Git扩展,请安装对应的版本控制扩展",
"svn.lastModifiedAuthor": "最后修改的作者:",
"svn.authRealm": "认证领域:",
"codeReview.report.title": "代码评审报告",
"codeReview.report.summary": "总体摘要",
"codeReview.report.findings": "详细问题",
"codeReview.issue.label": "问题:",
"codeReview.suggestion.label": "建议:",
"codeReview.documentation.label": "相关文档"
}
27 changes: 17 additions & 10 deletions src/scm/SvnUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { exec } from "child_process";
import { promisify } from "util";
import * as fs from "fs";
import * as path from "path";
import { LocalizationManager } from "../utils/LocalizationManager";

const execAsync = promisify(exec);

Expand All @@ -20,8 +21,14 @@ export class SvnUtils {
): Promise<string | undefined> {
try {
const { stdout } = await execAsync("svn info", { cwd: workspacePath });
// 匹配"最后修改的作者:"后面的内容
const authorMatch = stdout.match(/: (.+)/);
// 改用LocalizationManager
const authorMatch = stdout.match(
new RegExp(
`${LocalizationManager.getInstance().getMessage(
"svn.lastModifiedAuthor"
)} (.+)`
)
);
return authorMatch?.[1]?.trim();
} catch {
return undefined;
Expand Down Expand Up @@ -122,16 +129,12 @@ export class SvnUtils {
urlOutput: string
): string | undefined {
const credentials = this.parseCredentials(authOutput);
console.log("credentials", credentials);
console.log("urlOutput", urlOutput);
// 从svn info输出中提取URL
const urlMatch = urlOutput.match(/URL: (.+)/);
console.log("urlMatch", urlMatch);

if (urlMatch) {
const repoUrl = urlMatch[1].trim();
const matchingCred = this.findMatchingCredential(credentials, repoUrl);
console.log("matchingCred", matchingCred);
if (matchingCred) {
return matchingCred;
}
Expand All @@ -147,15 +150,19 @@ export class SvnUtils {
* @returns 包含用户名、认证领域和仓库ID的认证信息数组
*/
private static parseCredentials(authOutput: string) {
// 按分隔线分割认证块
return authOutput
.split(/\n?-+\n/)
.filter((block) => block.trim())
.map((block) => {
// 匹配用户名
const usernameMatch = block.match(/Username: (.+)/);
// 匹配认证领域和仓库ID
const realmMatch = block.match(/: <([^>]+)>\s*([^\n]*)/);
// 改用LocalizationManager
const realmMatch = block.match(
new RegExp(
`${LocalizationManager.getInstance().getMessage(
"svn.authRealm"
)} <([^>]+)>\\s*([^\\n]*)`
)
);
return {
username: usernameMatch?.[1]?.trim() || null,
realm: realmMatch?.[1]?.trim() || null,
Expand Down
2 changes: 1 addition & 1 deletion src/services/ModelPickerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class ModelPickerService {
}
return undefined;
} catch (error) {
console.error("获取模型列表失败:", error);
console.error(locManager.getMessage("model.list.failed"), error);
NotificationHandler.error("model.list.failed");
return undefined;
}
Expand Down
18 changes: 13 additions & 5 deletions src/utils/CodeReviewReportGenerator.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { CodeReviewResult, CodeReviewIssue } from "../ai/types";
import * as vscode from "vscode";
import { LocalizationManager } from "../utils/LocalizationManager";

/**
* 代码审查报告生成器,将代码审查结果转换为格式化的 Markdown 文档
*/
export class CodeReviewReportGenerator {
private static readonly locManager = LocalizationManager.getInstance();

/**
* 不同严重程度对应的 emoji 图标
* @private
Expand Down Expand Up @@ -55,7 +59,9 @@ export class CodeReviewReportGenerator {
* @returns {string} Markdown 格式的报告头部
*/
private static generateHeader(summary: string): string {
return `# Code Review Report\n\n## Summary\n\n${summary}\n\n`;
const title = this.locManager.getMessage("codeReview.report.title");
const summaryLabel = this.locManager.getMessage("codeReview.report.summary");
return `# ${title}\n\n## ${summaryLabel}\n\n${summary}\n\n`;
}

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

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

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

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

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

section += `---\n\n`;
Expand Down

0 comments on commit 76f57d7

Please sign in to comment.