Skip to content

Commit c03da47

Browse files
committed
docs: 开始翻译Go代码中的中文注释和字符串
🌍 代码国际化第一阶段: - docs/package.json - 翻译项目描述为英文 - examples/01-basic-usage/main.go - 完全翻译为英文 - examples/08-position-aware-editor/main.go - 部分翻译 ✅ 翻译内容: - 代码注释翻译为英文 - 输出字符串翻译为英文 - 错误消息翻译为英文 - 保持代码逻辑和功能不变 🎯 用户体验: - 示例代码对国际用户更友好 - 输出信息清晰易懂 - 符合国际开源项目标准 📝 进度: - 已完成: 2个重要示例文件 - 待处理: 其他examples和pkg目录下的文件 这是代码国际化的第一步,确保用户看到的 示例代码和输出都是英文的。
1 parent f37ebc5 commit c03da47

File tree

3 files changed

+39
-39
lines changed

3 files changed

+39
-39
lines changed

docs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "docs",
33
"version": "1.0.0",
4-
"description": "欢迎使用 Python Requirements Parser 的官方文档!这是一个用 Go 语言编写的高性能 Python requirements.txt 文件解析器和编辑器。",
4+
"description": "Welcome to the official documentation for Python Requirements Parser! This is a high-performance Python requirements.txt file parser and editor written in Go.",
55
"main": "index.js",
66
"scripts": {
77
"dev": "vitepress dev",

examples/01-basic-usage/main.go

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,69 +9,69 @@ import (
99
)
1010

1111
func main() {
12-
// 创建示例文件
12+
// Create example file
1313
reqContent := `
14-
# 这是一个注释行
15-
flask==2.0.1 # 指定精确版本
16-
requests>=2.25.0,<3.0.0 # 版本范围
17-
uvicorn[standard]>=0.15.0 # 带extras
18-
pytest==7.0.0; python_version >= '3.6' # 带环境标记
14+
# This is a comment line
15+
flask==2.0.1 # Exact version specified
16+
requests>=2.25.0,<3.0.0 # Version range
17+
uvicorn[standard]>=0.15.0 # With extras
18+
pytest==7.0.0; python_version >= '3.6' # With environment markers
1919
20-
# 空行
20+
# Empty line
2121
2222
`
2323
err := os.WriteFile("requirements.txt", []byte(reqContent), 0644)
2424
if err != nil {
25-
log.Fatalf("创建示例文件失败: %v", err)
25+
log.Fatalf("Failed to create example file: %v", err)
2626
}
2727
defer os.Remove("requirements.txt")
2828

29-
// 创建解析器
29+
// Create parser
3030
p := parser.New()
3131

32-
// 解析文件
32+
// Parse file
3333
requirements, err := p.ParseFile("requirements.txt")
3434
if err != nil {
35-
log.Fatalf("解析失败: %v", err)
35+
log.Fatalf("Parse failed: %v", err)
3636
}
3737

38-
// 输出解析结果
39-
fmt.Println("解析结果:")
38+
// Output parse results
39+
fmt.Println("Parse Results:")
4040
fmt.Println("----------------------------------------")
4141
for i, req := range requirements {
42-
fmt.Printf("项目 #%d:\n", i+1)
42+
fmt.Printf("Project #%d:\n", i+1)
4343
if req.IsComment {
44-
fmt.Printf(" - 注释: %s\n", req.Comment)
44+
fmt.Printf(" - Comment: %s\n", req.Comment)
4545
} else if req.IsEmpty {
46-
fmt.Println(" - 空行")
46+
fmt.Println(" - Empty line")
4747
} else {
48-
fmt.Printf(" - 包名: %s\n", req.Name)
48+
fmt.Printf(" - Package: %s\n", req.Name)
4949
if req.Version != "" {
50-
fmt.Printf(" - 版本: %s\n", req.Version)
50+
fmt.Printf(" - Version: %s\n", req.Version)
5151
}
5252
if len(req.Extras) > 0 {
53-
fmt.Printf(" - 扩展: %v\n", req.Extras)
53+
fmt.Printf(" - Extras: %v\n", req.Extras)
5454
}
5555
if req.Markers != "" {
56-
fmt.Printf(" - 环境标记: %s\n", req.Markers)
56+
fmt.Printf(" - Environment Markers: %s\n", req.Markers)
5757
}
5858
if req.Comment != "" {
59-
fmt.Printf(" - 注释: %s\n", req.Comment)
59+
fmt.Printf(" - Comment: %s\n", req.Comment)
6060
}
6161
}
6262
fmt.Println("----------------------------------------")
6363
}
6464

65-
// 从字符串直接解析
66-
fmt.Println("\n从字符串解析:")
65+
// Parse from string directly
66+
fmt.Println("\nParse from string:")
6767
stringRequirements, err := p.ParseString("django[rest]>=3.2.0")
6868
if err != nil {
69-
log.Fatalf("从字符串解析失败: %v", err)
69+
log.Fatalf("Parse from string failed: %v", err)
7070
}
7171

72-
// 输出字符串解析结果
72+
// Output string parse results
7373
req := stringRequirements[0]
74-
fmt.Printf("包名: %s\n", req.Name)
75-
fmt.Printf("版本: %s\n", req.Version)
76-
fmt.Printf("扩展: %v\n", req.Extras)
74+
fmt.Printf("Package: %s\n", req.Name)
75+
fmt.Printf("Version: %s\n", req.Version)
76+
fmt.Printf("Extras: %v\n", req.Extras)
7777
}

examples/08-position-aware-editor/main.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ import (
99
)
1010

1111
func main() {
12-
fmt.Println("=== 位置感知编辑器示例 ===")
13-
fmt.Println("演示最小化diff的编辑功能")
12+
fmt.Println("=== Position Aware Editor Example ===")
13+
fmt.Println("Demonstrating minimal diff editing functionality")
1414
fmt.Println()
1515

16-
// 创建位置感知编辑器
16+
// Create position aware editor
1717
posEditor := editor.NewPositionAwareEditor()
1818

19-
// 示例requirements.txt内容(保持复杂的格式)
19+
// Example requirements.txt content (maintaining complex formatting)
2020
originalContent := `# Production dependencies
2121
flask==1.0.0 # Web framework
2222
django>=3.2.0,<4.0.0 # Another web framework
@@ -39,22 +39,22 @@ https://example.com/package.whl
3939
-r dev-requirements.txt
4040
-c constraints.txt`
4141

42-
fmt.Println("原始 requirements.txt 内容:")
42+
fmt.Println("Original requirements.txt content:")
4343
fmt.Println(strings.Repeat("=", 50))
4444
fmt.Println(originalContent)
4545
fmt.Println(strings.Repeat("=", 50))
4646
fmt.Println()
4747

48-
// 解析文档
48+
// Parse document
4949
doc, err := posEditor.ParseRequirementsFile(originalContent)
5050
if err != nil {
51-
log.Fatalf("解析失败: %v", err)
51+
log.Fatalf("Parse failed: %v", err)
5252
}
5353

54-
// 显示解析出的包和位置信息
55-
fmt.Println("=== 解析结果和位置信息 ===")
54+
// Display parsed packages and position information
55+
fmt.Println("=== Parse Results and Position Information ===")
5656
packages := posEditor.ListPackages(doc)
57-
fmt.Printf("发现 %d 个包依赖:\n", len(packages))
57+
fmt.Printf("Found %d package dependencies:\n", len(packages))
5858
for _, pkg := range packages {
5959
fmt.Printf("📦 %s %s", pkg.Name, pkg.Version)
6060
if len(pkg.Extras) > 0 {

0 commit comments

Comments
 (0)