Generate and edit Draw.io, Mermaid, and Excalidraw diagrams from natural language using a structured JSON spec.
Documents
Universal Translator
Try itTranslate Word, PDF, Excel, PowerPoint, HTML, Markdown, and TXT files into another language while preserving the original layout.
What it does
Framework that supplies Python parsing and write-back code for seven document formats (DOCX, XLSX, PPTX, PDF, HTML, MD, TXT). The agent plugs in its own LLM translation function via a translator_fn argument; the framework calls it per paragraph, cell, shape, or section and writes the result back into the same structure so layout and styling stay intact. A translate_folder helper handles mixed batches of files. The shipped _translate_text method is a stub for testing the parse flow only and must be replaced with a real LLM call before production. Document content is forwarded to the LLM configured in the agent environment (local or remote).
When to use it
- Translating a Word report into another language while keeping headings, tables, and styles intact
- Batch-translating every supported file inside a folder in one pass
- Translating a PowerPoint deck or HTML page by iterating slides and shapes and swapping text in place
- Converting a folder of mixed DOCX, XLSX, PPTX, MD, and TXT files to a target language
The skill document
Universal Translator
Translate any document format while preserving layout and formatting.
Features
- 📄 All Formats: Word, PDF, Excel, PPT, HTML, Markdown, TXT
- 📁 Batch Translation: Translate entire folders
- 🎯 Terminology: Keep terms consistent
- 🌍 50+ Languages: Chinese, English, Japanese, etc.
- 📐 Format Preserved: Keep original layout
Supported Formats
| Format | Extension | Method |
|---|---|---|
| Word | .docx | python-docx |
| Excel | .xlsx | openpyxl |
| PowerPoint | .pptx | python-pptx |
| pymupdf | ||
| HTML | .html | BeautifulSoup |
| Markdown | .md | text processing |
| Text | .txt | text processing |
Note: Only modern formats are supported. For .xls files, convert to .xlsx first.
Trigger Conditions
Only when the user asks to translate a document file (Word/PDF/Excel/PPT/HTML/MD/TXT) to another language.
How Translation Works
⚠️ 数据外发提醒:文档内容由 AI 读取并逐段发送至配置中的 LLM 进行翻译。LLM 的运行位置(本地/远程)取决于 OpenClaw 配置。
This is a Framework Skill: it provides document parsing boilerplate (read Word/Excel/PPT/PDF files, iterate paragraphs/cells/shapes, write output). The AI agent's own LLM performs the actual translation.
Translation workflow:
- Use the Python code below to open the document and extract text
- For each paragraph/cell/shape, translate the text using your LLM
- Write the translated text back into the document
- Save the output file
Note: The _translate_text method is a stub — you MUST replace it with actual LLM translation. The stub exists only to let you test the parsing flow; do not use it in production.
Python Code
import os
from pathlib import Path
from docx import Document
import openpyxl
from pptx import Presentation
class UniversalTranslator:
def __init__(self):
self.supported = {
'word': ['.docx'],
'excel': ['.xlsx', '.xls'],
'powerpoint': ['.pptx'],
'pdf': ['.pdf'],
'html': ['.html', '.htm'],
'markdown': ['.md'],
'text': ['.txt']
}
def detect_format(self, file_path):
"""Detect file format"""
ext = Path(file_path).suffix.lower()
for format_type, extensions in self.supported.items():
if ext in extensions:
return format_type
return 'unknown'
def translate_word(self, input_path, output_path, translator_fn):
"""Translate Word document.
Args:
translator_fn: callable(text, target_lang) -> translated_text
Agent should pass its LLM translate function here.
"""
doc = Document(input_path)
for para in doc.paragraphs:
if para.text.strip():
translated = translator_fn(para.text, 'en')
para.clear()
para.add_run(translated)
for table in doc.tables:
for row in table.rows:
for cell in row.cells:
if cell.text.strip():
translated = translator_fn(cell.text, 'en')
cell.text = translated
doc.save(output_path)
return output_path
def translate_excel(self, input_path, output_path, translator_fn):
"""Translate Excel file."""
wb = openpyxl.load_workbook(input_path)
for sheet in wb.worksheets:
for row in sheet.iter_rows():
for cell in row:
if cell.value and isinstance(cell.value, str):
translated = translator_fn(cell.value, 'en')
cell.value = translated
wb.save(output_path)
return output_path
def translate_pptx(self, input_path, output_path, translator_fn):
"""Translate PowerPoint."""
prs = Presentation(input_path)
for slide in prs.slides:
for shape in slide.shapes:
if hasattr(shape, 'text') and shape.text.strip():
translated = translator_fn(shape.text, 'en')
shape.text = translated
prs.save(output_path)
return output_path
def translate_markdown(self, input_path, output_path, translator_fn):
"""Translate Markdown file."""
with open(input_path, 'r', encoding='utf-8') as f:
content = f.read()
sections = content.split('\n\n')
translated_sections = []
for section in sections:
if section.strip():
translated = translator_fn(section, 'en')
translated_sections.append(translated)
else:
translated_sections.append('')
translated_content = '\n\n'.join(translated_sections)
with open(output_path, 'w', encoding='utf-8') as f:
f.write(translated_content)
return output_path
def translate_folder(self, folder_path, output_folder, target_lang, translator_fn):
"""Translate all files in folder."""
os.makedirs(output_folder, exist_ok=True)
results = []
for file_path in Path(folder_path).rglob('*'):
if file_path.is_file():
format_type = self.detect_format(str(file_path))
if format_type != 'unknown':
output_path = os.path.join(output_folder, file_path.name)
try:
if format_type == 'word':
self.translate_word(str(file_path), output_path, translator_fn)
elif format_type == 'excel':
self.translate_excel(str(file_path), output_path, translator_fn)
elif format_type == 'powerpoint':
self.translate_pptx(str(file_path), output_path, translator_fn)
elif format_type in ['markdown', 'text']:
self.translate_markdown(str(file_path), output_path, translator_fn)
results.append({'file': file_path.name, 'status': 'success'})
except Exception as e:
results.append({'file': file_path.name, 'status': 'error', 'error': str(e)})
return results
## Usage Examples
User: "Translate this Word document to English" Agent:
- pip install python-docx (if not installed)
- Use translator.translate_word() to parse .docx
- For each paragraph, call your LLM to translate
- Write translated text back, save output
User: "Translate all files in this folder to Chinese" Agent:
- Ensure required libs are installed
- Use translator.translate_folder() for parsing
- Translate text via your LLM
- Save all translated files
User: "翻译这份PDF成日文" Agent:
- Extract text from PDF
- Translate using your LLM
- Save as new document
## Notes
- Supports Word (.docx), Excel (.xlsx), PPT (.pptx), PDF, HTML, Markdown, TXT
- The parsing code preserves original formatting — the AI agent only replaces text content
- Install dependencies: `pip install python-docx openpyxl python-pptx`
- For PDF support: `pip install pymupdf`
- For HTML: `pip install beautifulsoup4`
Related skills
Join a video meeting as an AI bot with voice, avatar, and screenshare across four operating modes.
Stores durable facts in a categorized, plain-markdown vault on disk, alongside your agent's built-in memory.
Find why your productivity system keeps failing, then apply the smallest fix — capacity math, bottleneck routing, durable local notes.
Fetch raw ad creative, app, ranking, and revenue data from AdMapix as structured JSON.
Write, debug, and tune Playwright specs with locator strategy, trace diagnosis, and CI-aware timeouts.
More from tobewin
Browse all skillsGenerate editable PowerPoint decks from a JSON description with 11 slide layouts and 5 color themes.
Professional Excel spreadsheet generator. Use when user needs to create data tables, reports, charts, financial models, or any structured data in Excel forma...
中国新闻资讯聚合工具。Use when user wants to get latest news from Chinese sources. Supports multiple news sites (Sina, Sohu, NetEase, Tencent) via browser automation an...
Data analysis tool for Excel, CSV, Word, PDF, TXT, Markdown files. Use when user needs to analyze, summarize, or compare data from multiple files. Supports f...
Marketing plan generator with web research and Word output. Use when user needs to create marketing plans, promotional campaigns, social media strategies. Fe...
Data visualization chart generator. Use when user needs to create charts from data for reports, presentations, or documents. Supports bar, line, pie, scatter...