Skip to content

Commit 5587cb3

Browse files
Comprehensive proofreading and update of the Chinese part of Defold manuals and tutorials. (#565)
* 翻译校对 * 修正 * 完成翻译 * 添加工具说明 * 修正脚本更加通用 * 修正确编码
1 parent ab87153 commit 5587cb3

File tree

4 files changed

+111
-54
lines changed

4 files changed

+111
-54
lines changed

scripts/README.md

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Documentation Consistency Checker
22

3-
A Python script designed to check consistency between English and Chinese documentation files in the Defold project. This tool compares file structures and Markdown syntax trees to ensure translations maintain the same structure and formatting.
3+
A Python script designed to check consistency between documentation files in different languages for the Defold project. This tool compares file structures and Markdown syntax trees to ensure translations maintain the same structure and formatting.
44

55
## Features
66

7-
- **File Structure Comparison**: Compares the directory structure between English and Chinese documentation
7+
- **File Structure Comparison**: Compares the directory structure between source and target documentation directories
88
- **Markdown Syntax Tree Analysis**: Analyzes and compares Markdown syntax elements including:
99
- Headers (h1, h2, h3, etc.)
1010
- Code blocks
@@ -34,52 +34,49 @@ A Python script designed to check consistency between English and Chinese docume
3434

3535
### Basic Usage
3636

37-
To run a full comparison between English and Chinese documentation:
37+
To run a full comparison between source and target documentation directories:
3838

3939
```bash
40-
python scripts/docs_consistency_checker.py
40+
python docs_consistency_checker.py --source-dir ./docs/en --target-dir ./docs/zh
4141
```
4242

43-
This will:
44-
- Use default paths: `docs/en` for English documentation and `docs/zh` for Chinese documentation
45-
- Generate an output file named `docs_structure_comparison.xlsx`
46-
4743
### Advanced Usage
4844

4945
#### Specify Custom Directories
5046

5147
```bash
52-
python scripts/docs_consistency_checker.py --en-dir /path/to/english/docs --zh-dir /path/to/chinese/docs
48+
python docs_consistency_checker.py --source-dir /path/to/source/docs --target-dir /path/to/target/docs
5349
```
5450

5551
#### Check a Specific File
5652

5753
```bash
58-
python scripts/docs_consistency_checker.py --file manuals/game-project/game-project.md
54+
python docs_consistency_checker.py --source-dir ./docs/en --target-dir ./docs/zh --file manuals/game-project/game-project.md
5955
```
6056

6157
#### Check Specific File Pairs
6258

6359
```bash
64-
python scripts/docs_consistency_checker.py --en-file /path/to/english/file.md --zh-file /path/to/chinese/file.md
60+
python docs_consistency_checker.py --source-file /path/to/source/file.md --target-file /path/to/target/file.md
6561
```
6662

6763
#### Specify Output File
6864

6965
```bash
70-
python scripts/docs_consistency_checker.py --output custom_comparison.xlsx
66+
python docs_consistency_checker.py --source-dir ./docs/en --target-dir ./docs/zh --output custom_comparison.xlsx
7167
```
7268

7369
### Command Line Arguments
7470

7571
| Argument | Description |
7672
|----------|-------------|
7773
| `--file` | Specify a particular file to check (relative to docs directory) |
78-
| `--en-dir` | Path to English documentation directory |
79-
| `--zh-dir` | Path to Chinese documentation directory |
74+
| `--source-dir` | Path to source documentation directory |
75+
| `--target-dir` | Path to target documentation directory |
8076
| `--output` | Path for the output Excel file |
81-
| `--en-file` | Path to a specific English file |
82-
| `--zh-file` | Path to a specific Chinese file |
77+
| `--source-file` | Path to a specific source file |
78+
| `--target-file` | Path to a specific target file |
79+
| `--help` | Show help message and exit |
8380

8481
## Output
8582

@@ -88,21 +85,21 @@ The script generates an Excel file with the following columns:
8885
1. **File Path**: Relative path of the file
8986
2. **File Extension**: File extension type
9087
3. **Top Directory**: Top-level directory containing the file
91-
4. **English Version Exists**: Whether the file exists in English documentation
92-
5. **Chinese Version Exists**: Whether the file exists in Chinese documentation
88+
4. **Source Version Exists**: Whether the file exists in source documentation
89+
5. **Target Version Exists**: Whether the file exists in target documentation
9390
6. **Status**:
9491
- "Consistent" - File exists in both versions
95-
- "English Only" - File exists only in English version
96-
- "Chinese Only" - File exists only in Chinese version
92+
- "Source Only" - File exists only in source version
93+
- "Target Only" - File exists only in target version
9794
- "Does Not Exist" - File doesn't exist in either version
98-
7. **English File Size (KB)**: Size of the English file
99-
8. **Chinese File Size (KB)**: Size of the Chinese file
95+
7. **Source File Size (KB)**: Size of the source file
96+
8. **Target File Size (KB)**: Size of the target file
10097
9. **Markdown Syntax Consistency**: Results of Markdown syntax comparison
10198
10. **Formula**: Recommended actions for ensuring translation consistency
10299

103100
## How It Works
104101

105-
1. **File Collection**: The script recursively collects all files from both English and Chinese documentation directories.
102+
1. **File Collection**: The script recursively collects all files from both source and target documentation directories.
106103
2. **File Comparison**: It compares the file structures between the two directories.
107104
3. **Markdown Analysis**: For Markdown files that exist in both versions, the script:
108105
- Parses the Markdown content to build syntax trees
@@ -127,3 +124,23 @@ The script is organized into several modules:
127124
- `modules/file_handler.py`: File operations and utilities
128125
- `modules/markdown_handler.py`: Markdown parsing and comparison
129126
- `modules/excel_handler.py`: Excel report generation
127+
128+
### Compare entire documentation directories
129+
```bash
130+
python docs_consistency_checker.py --source-dir ../docs/en --target-dir ../docs/zh
131+
```
132+
133+
### Compare specific file
134+
```bash
135+
python docs_consistency_checker.py --source-dir ../docs/en --target-dir ../docs/zh --file manuals/introduction.md
136+
```
137+
138+
### Compare direct file paths
139+
```bash
140+
python docs_consistency_checker.py --source-file ../docs/en/manuals/introduction.md --target-file ../docs/zh/manuals/introduction.md
141+
```
142+
143+
### Get help
144+
```bash
145+
python docs_consistency_checker.py --help
146+
```

scripts/docs_consistency_checker.py

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,6 @@ def run_docs_consistency_check(source_dir=None, target_dir=None, output_file=Non
3131
# Set console encoding to resolve character display issues
3232
setup_console_encoding()
3333

34-
# Set default directories
35-
if source_dir is None:
36-
source_dir = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "docs", "source")
37-
38-
if target_dir is None:
39-
target_dir = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "docs", "target")
40-
41-
if output_file is None:
42-
output_file = "docs_structure_comparison.xlsx"
43-
4434
# If specific source and target file paths are specified, use these paths
4535
if source_file and target_file:
4636
print(f"Checking files: Source version {source_file}, Target version {target_file}")
@@ -127,8 +117,41 @@ def run_docs_consistency_check(source_dir=None, target_dir=None, output_file=Non
127117
print(f"{i}. {issue}")
128118
else:
129119
print("No inconsistency issues found, document structure is consistent")
120+
return
121+
122+
# Check if source and target directories are provided for directory-based operations
123+
if source_dir is None and target_dir is None:
124+
# Try to use current working directory as a fallback
125+
cwd = os.getcwd()
126+
if os.path.exists(os.path.join(cwd, "docs")):
127+
source_dir = os.path.join(cwd, "docs", "source")
128+
target_dir = os.path.join(cwd, "docs", "target")
129+
print(f"Using default directories based on current working directory:")
130+
print(f" Source directory: {source_dir}")
131+
print(f" Target directory: {target_dir}")
132+
else:
133+
print("Error: Source and target directories must be specified.")
134+
print("Usage examples:")
135+
print(" python docs_consistency_checker.py --source-dir ./docs/en --target-dir ./docs/zh")
136+
print(" python docs_consistency_checker.py --source-file ./docs/en/manuals/introduction.md --target-file ./docs/zh/manuals/introduction.md")
137+
print(" python docs_consistency_checker.py --source-dir ./docs/en --target-dir ./docs/zh --file manuals/introduction.md")
138+
return
139+
140+
# Check if source directory exists
141+
if source_dir and not os.path.exists(source_dir):
142+
print(f"Error: Source directory does not exist: {source_dir}")
143+
return
144+
145+
# Check if target directory exists
146+
if target_dir and not os.path.exists(target_dir):
147+
print(f"Error: Target directory does not exist: {target_dir}")
148+
return
149+
150+
if output_file is None:
151+
output_file = "docs_structure_comparison.xlsx"
152+
130153
# If a specific file is specified, only check that file
131-
elif specific_file:
154+
if specific_file:
132155
print(f"Checking specific file: {specific_file}")
133156

134157
# Build complete file paths

scripts/modules/excel_handler.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,19 +113,23 @@ def write_markdown_consistency(ws, row_num, consistency_result):
113113
ws.cell(row=row_num, column=9, value=consistency_result)
114114

115115

116-
def write_formula_text(ws, row_num, file_path, source_dir="docs\\source", target_dir="docs\\target"):
116+
def write_formula_text(ws, row_num, file_path, source_dir=None, target_dir=None):
117117
"""
118118
Write formula column
119119
120120
Parameters:
121121
ws: Worksheet object
122122
row_num: Row number
123123
file_path: File path
124-
source_dir: Source directory path
125-
target_dir: Target directory path
124+
source_dir: Source directory path (optional)
125+
target_dir: Target directory path (optional)
126126
"""
127+
# Use provided directory names or default to generic names
128+
source_dir_name = source_dir if source_dir else "source"
129+
target_dir_name = target_dir if target_dir else "target"
130+
127131
# Generate formula text based on file path
128-
formula_text = f"Compare {source_dir}\\{file_path} and {target_dir}\\{file_path} paragraph by paragraph with each heading as a paragraph, to ensure the target version is a complete and accurate translation of the source version."
132+
formula_text = f"Compare {source_dir_name}\\{file_path} and {target_dir_name}\\{file_path} paragraph by paragraph with each heading as a paragraph, to ensure the target version is a complete and accurate translation of the source version."
129133
ws.cell(row=row_num, column=10, value=formula_text)
130134

131135

scripts/modules/main.py

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,33 @@
66
from .markdown_handler import compare_markdown_syntax_trees
77

88

9-
# Default directory and output file path
10-
source_dir = "g:\\temp\\defold_doc\\docs\\source"
11-
target_dir = "g:\\temp\\defold_doc\\docs\\target"
12-
output_file = "docs_structure_comparison_updated.xlsx"
13-
14-
159
def main(source_dir_path=None, target_dir_path=None, output_file_path=None):
16-
# Use passed parameters or default values
17-
# Note: Keeping parameter names as source_dir_path and target_dir_path for clarity
18-
if source_dir_path is None:
19-
source_dir_path = globals().get('source_dir', "g:\\temp\\defold_doc\\docs\\source")
20-
21-
if target_dir_path is None:
22-
target_dir_path = globals().get('target_dir', "g:\\temp\\defold_doc\\docs\\target")
23-
10+
"""
11+
Main function for document consistency checking
12+
13+
Parameters:
14+
source_dir_path: Source document directory path (required)
15+
target_dir_path: Target document directory path (required)
16+
output_file_path: Output Excel file path (optional, defaults to docs_structure_comparison.xlsx)
17+
"""
18+
# Check if required parameters are provided
19+
if source_dir_path is None or target_dir_path is None:
20+
print("Error: Both source_dir_path and target_dir_path parameters are required.")
21+
print("Usage: main(source_dir_path='path/to/source', target_dir_path='path/to/target')")
22+
return
23+
24+
# Check if directories exist
25+
if not os.path.exists(source_dir_path):
26+
print(f"Error: Source directory does not exist: {source_dir_path}")
27+
return
28+
29+
if not os.path.exists(target_dir_path):
30+
print(f"Error: Target directory does not exist: {target_dir_path}")
31+
return
32+
33+
# Set default output file path if not provided
2434
if output_file_path is None:
25-
output_file_path = globals().get('output_file', "docs_structure_comparison_updated.xlsx")
35+
output_file_path = "docs_structure_comparison.xlsx"
2636

2737
# Set console encoding to resolve character display issues
2838
setup_console_encoding()
@@ -113,4 +123,7 @@ def main(source_dir_path=None, target_dir_path=None, output_file_path=None):
113123

114124

115125
if __name__ == "__main__":
116-
main()
126+
# When run directly, provide usage information
127+
print("This module is designed to be imported and used by docs_consistency_checker.py")
128+
print("Usage: from main import main")
129+
print(" main(source_dir_path='path/to/source', target_dir_path='path/to/target')")

0 commit comments

Comments
 (0)