当用户在OpenClaw中提出以下需求时,调用本技能:
When users request the following in OpenClaw, invoke this skill:
| 用户指令 / User Commands | 执行动作 / Execution Actions |
|---|---|
| --------- | --------- |
| "翻译文档" / "翻译文件" / "翻译PDF/Word" "Translate document" / "Translate file" / "Translate PDF/Word" | 调用程序自动翻译指定文件 Invoke program to automatically translate specified file |
| "批量翻译" / "翻译文件夹" "Batch translation" / "Translate folder" | 批量处理文件夹内所有支持格式的文件 Batch process all supported format files in folder |
用户说 / User says:"帮我翻译这个PDF文件"
"Help me translate this PDF file"
Claude执行 / Claude executes:
python src/main.py --file document.pdf --engine cloud
用户说 / User says:"批量翻译这个文件夹"
"Batch translate this folder"
Claude执行 / Claude executes:
python src/main.py --dir ./documents --engine cloud --model "DeepSeek (V3/R1)"
当用户需要翻译文档时,执行以下流程:
When users need to translate documents, execute the following process:
# 翻译单个文件 / Translate single file
python src/main.py --file document.pdf --engine cloud
# 批量翻译文件夹 / Batch translate folder
python src/main.py --dir ./documents --output ./translated
# 指定模型和语言方向 / Specify model and language direction
python src/main.py --file doc.docx --model "GPT-4o" --sl en --tl zh-CN
# 使用Ollama本地模型 / Use Ollama local model
python src/main.py --file doc.pdf --engine ollama
# DeepSeek API密钥 / API Key
$env:DEEPSEEK_API_KEY="your-api-key-here"
# OpenAI API密钥 / API Key
$env:OPENAI_API_KEY="your-api-key-here"
# Anthropic API密钥 / API Key
$env:ANTHROPIC_API_KEY="your-api-key-here"
# SiliconFlow API密钥 / API Key
$env:SILICONFLOW_API_KEY="your-api-key-here"
| 引擎 / Engine | 说明 / Description | 适用场景 / Use Cases |
|---|---|---|
| ------ | ------ | --------- |
| cloud | 云端大模型(DeepSeek/GPT-4o/Claude等) Cloud large models (DeepSeek/GPT-4o/Claude, etc.) | 高质量翻译,推荐 High-quality translation, recommended |
| ollama | 本地Ollama模型 Local Ollama model | 隐私保护,离线使用 Privacy protection, offline use |
| python | 内置translate库 Built-in translate library | 紧急备用,质量一般 Emergency backup, average quality |
output/ # 输出文件夹(自动创建)<br># Output folder (automatically created)
├── translated_原文件名.docx # 翻译后的Word文档<br># Translated Word document
├── translated_原文件名.pdf # 翻译后的PDF(通过Word转换)<br># Translated PDF (converted from Word)
├── translated_原文件名.xlsx # 翻译后的Excel<br># Translated Excel
├── translated_原文件名.pptx # 翻译后的PPT<br># Translated PPT
tmp/ # 临时文件夹<br># Temporary folder
└── [PDF转Word临时文件] # 自动清理<br># [PDF to Word temporary files] # Auto cleanup
Xtranslate/
├── SKILL.md # 核心指令 + 元数据<br># Core instructions + metadata
├── requirements.txt # Python依赖列表<br># Python dependency list
├── Xtranslate.spec # PyInstaller打包配置<br># PyInstaller packaging configuration
│
├── src/ # 源代码目录<br># Source code directory
│ ├── config.py # 全局配置(引擎、模型、语言等)<br># Global configuration (engines, models, languages, etc.)
│ ├── main.py # 命令行入口程序<br># Command line entry program
│ ├── translator.py # 翻译引擎模块<br># Translation engine module
│ ├── file_handler.py # 文件读写处理器<br># File read/write processor
│ ├── analyzer.py # 文本分析与关键词提取<br># Text analysis and keyword extraction
│ ├── formatter.py # Word排版优化器<br># Word layout optimizer
│ ├── crypto_utils.py # API Key加密工具<br># API Key encryption tool
│ ├── translation_monitor.py # 翻译过程监控器<br># Translation process monitor
│ └── ...
│
├── templates/ # 代码模板<br># Code templates
│ ├── module.py.md # Python模块模板<br># Python module template
│ └── translator_engine.py.md # 新增引擎模板<br># New engine template
│
├── examples/ # 代码示例<br># Code examples
│ ├── good.md # 优秀代码示例<br># Excellent code examples
│ └── anti-pattern.md # 反模式示例<br># Anti-pattern examples
│
├── references/ # 规范参考<br># Specification references
│ ├── naming-convention.md # 命名规范<br># Naming convention
│ └── project-structure.md # 项目结构规范<br># Project structure specification
│
├── scripts/ # 辅助脚本<br># Auxiliary scripts
│ └── check-deps.py # 依赖检查脚本<br># Dependency check script
│
├── translation_monitor.json # 翻译监控记录文件<br># Translation monitoring record file
├── analyze_performance.py # 性能分析脚本<br># Performance analysis script
├── view_monitor.py # 监控记录查看脚本<br># Monitoring record viewing script
├── view_detail.py # 详细记录查看脚本<br># Detailed record viewing script
│
├── build/ # 构建文件<br># Build files
├── dist/ # 可执行文件输出<br># Executable file output
│ └── Xtranslate.exe # Windows可执行文件<br># Windows executable file
├── output/ # 翻译结果输出<br># Translation result output
└── tmp/ # 临时文件<br># Temporary files
| 模块 / Module | 功能 / Function |
|---|---|
| ------ | ------ |
| config.py | 全局配置管理,包含模型配置、API设置、批次参数 Global configuration management, including model configuration, API settings, batch parameters |
| main.py | 命令行入口,支持参数解析和批量处理 Command line entry, supports parameter parsing and batch processing |
| translator.py | 翻译核心,支持cloud/ollama/python三种引擎 Translation core, supports cloud/ollama/python three engines |
| file_handler.py | 多格式文件读写(Word/Excel/PPT/PDF/TXT等) Multi-format file read/write (Word/Excel/PPT/PDF/TXT, etc.) |
| analyzer.py | 使用jieba进行中文关键词提取 Use jieba for Chinese keyword extraction |
| formatter.py | Word文档自动排版优化 Word document automatic layout optimization |
| crypto_utils.py | Fernet加密API Key Fernet encrypt API Key |
|---|---|
| translation_monitor.py | 翻译过程全程监控,性能统计与自动分析 Full-process monitoring of translation, performance statistics and automatic analysis |
pip install -r requirements.txt
translation_monitor.json - 存储所有翻译记录translation_monitor.json - Store all translation recordsanalyze_performance.py - 性能深度分析脚本analyze_performance.py - Performance deep analysis scriptview_monitor.py - 查看记录概览view_monitor.py - View record overviewview_detail.py - 查看详细记录view_detail.py - View detailed records# 查看翻译记录概览 / View translation record overview
python view_monitor.py
# 查看详细记录 / View detailed records
python view_detail.py
# 性能深度分析 / Performance deep analysis
python analyze_performance.py
| 问题 / Issues | 解决方案 / Solutions |
|---|---|
| ------ | ---------- |
| API Key错误 / API Key error | 检查环境变量是否正确设置 Check if environment variables are correctly set |
| PDF转换失败 / PDF conversion failed | 确保PDF非扫描件,有可选中文字 Ensure PDF is not scanned and has selectable text |
| Ollama连接失败 / Ollama connection failed | 确保Ollama服务已启动 Ensure Ollama service is started |
|---|---|
| 翻译质量差 / Poor translation quality | 尝试切换云端模型,或使用关键词引导 Try switching cloud models, or use keyword guidance |
| 排版错乱 / Layout disorder | 检查原文档格式是否过于复杂 Check if original document format is too complex |
| 翻译速度慢 / Slow translation speed | 使用analyze_performance.py分析性能瓶颈 Use analyze_performance.py to analyze performance bottlenecks |
| 监控记录异常 / Monitoring record exception | 检查translation_monitor.json文件权限 Check translation_monitor.json file permissions |
| 大文档处理过慢 / Large document processing too slow | 检查是否启用了性能优化配置 Check if performance optimization configuration is enabled |
| 并发处理失败 / Concurrent processing failed | 降低concurrent参数或检查API限制 Reduce concurrent parameter or check API limits |
注意:本工具仅供个人学习研究使用,请遵守相关平台规则。
共 1 个版本