
Translate En Zh
- 9 installs
- 33 repo stars
- Updated April 26, 2026
- bighardperson/computer-science-skills-collection
translate-en-zh is a Claude skill for bidirectional Chinese-English translation of text, code comments and documents, with bundled term glossaries for consistency.
About
This skill provides bidirectional Chinese-English translation for plain text, code comments and professional documents, auto-detecting the source language. It ships batch scripts (translate_batch.py, translate_markdown.py) and term glossaries for tech, business and common vocabulary to keep translations consistent. A developer uses it to translate documents, code comments or emails between Chinese and English at scale. It matters because it preserves markdown formatting and only translates comments inside code.
- Bidirectional Chinese-English translation with automatic source-language detection
- Batch file translation via translate_batch.py and translate_markdown.py, preserving markdown structure
- Bundled tech, business and common terminology glossaries for consistent term alignment
Translate En Zh by the numbers
- 9 all-time installs (skills.sh)
- Ranked #2,218 of 3,280 Productivity & Planning skills by installs in the Skillselion catalog
- Data as of Jul 30, 2026 (Skillselion catalog sync)
translate-en-zh capabilities & compatibility
Free; runs local Python scripts with the model
- Capabilities
- translation · localization
- Use cases
- translation · documentation
- Pricing
- Free
What translate-en-zh says it does
提供专业、准确的中英文双向翻译能力,支持普通文本、代码注释、专业文档等多种场景的翻译需求,内置常用术语库保证翻译一致性。
**代码注释翻译**:保留代码结构,仅翻译注释内容
`translate_markdown.py`:翻译Markdown文档,保留格式结构
npx skills add https://github.com/bighardperson/computer-science-skills-collection --skill translate-en-zhAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 9 |
|---|---|
| repo stars | ★ 33 |
| Last updated | April 26, 2026 |
| Repository | bighardperson/computer-science-skills-collection ↗ |
What it does
Translate text, documents and code comments between Chinese and English with consistent terminology.
Who is it for?
Translating between Chinese and English while keeping terminology consistent via built-in glossaries
Skip if: Languages other than Chinese and English; it is a dedicated zh-en tool
When should I use this skill?
The user needs Chinese-to-English or English-to-Chinese translation, or mentions 翻译, 英译中, 中译英 or 中英文转换
What you get
- Translated text or Markdown files with preserved structure
By the numbers
- 2 batch scripts (translate_batch.py, translate_markdown.py)
- 3 bundled term glossaries (tech, business, common)
Files
中英文互转工具
Overview
提供专业、准确的中英文双向翻译能力,支持普通文本、代码注释、专业文档等多种场景的翻译需求,内置常用术语库保证翻译一致性。
核心功能
1. 普通文本翻译
直接对用户输入的文本进行中英文互译,自动识别源语言:
- 输入英文 → 输出中文翻译
- 输入中文 → 输出英文翻译
- 支持长文本分段翻译,保持原有格式
2. 专业场景翻译优化
针对不同场景提供专业翻译:
- 代码注释翻译:保留代码结构,仅翻译注释内容
- 技术文档翻译:优先使用行业标准术语
- 商务邮件翻译:保持正式、专业的语气
- 日常对话翻译:符合口语化表达习惯
3. 批量翻译
支持批量处理多个文本段落或文件内容:
- 自动分割长文本,保持上下文一致性
- 支持Markdown格式文档翻译,保留格式结构
- 翻译结果可直接导出为文本或Markdown文件
使用指南
快速使用
用户提到翻译需求时,直接返回翻译结果,无需额外说明:
用户输入:"翻译这段文字:Hello world"
输出:"你好,世界"翻译原则
1. 准确性优先:保证翻译内容准确传达原意 2. 符合语境:根据使用场景选择合适的语气和术语 3. 保留格式:如果原文本有格式(如Markdown、代码块),翻译后保持格式不变 4. 术语一致:同一术语在整个翻译过程中保持统一
特殊场景处理
- 遇到专业术语不确定时,主动向用户确认
- 包含敏感内容的文本拒绝翻译,并说明原因
- 代码内容仅翻译注释部分,不修改代码逻辑
内置资源
scripts/
提供批量翻译工具脚本:
translate_batch.py:批量处理文本文件翻译translate_markdown.py:翻译Markdown文档,保留格式结构
references/
常用术语库参考:
tech_terms.md:IT/技术领域常用中英文术语对照business_terms.md:商务/金融领域常用中英文术语对照common_terms.md:日常通用术语对照表
{
"ownerId": "kn77ga7x5antejham5pq03ehs18327f8",
"slug": "translate-en-zh",
"version": "1.0.0",
"publishedAt": 1773804897672
}{
"version": 1,
"registry": "https://clawhub.ai",
"slug": "translate-en-zh",
"installedVersion": "1.0.0",
"installedAt": 1776068463020
}
#!/usr/bin/env python3
"""
批量文本翻译工具
支持中英文互译,自动识别源语言
"""
import sys
import argparse
from typing import List
def translate_text(text: str, target_lang: str = None) -> str:
"""
翻译文本
:param text: 待翻译文本
:param target_lang: 目标语言,'zh' 或 'en',自动识别时为 None
:return: 翻译结果
"""
# 简单的语言检测(仅检测是否包含中文字符)
has_chinese = any('\u4e00' <= c <= '\u9fff' for c in text)
# 确定翻译方向
if target_lang is None:
target_lang = 'en' if has_chinese else 'zh'
# 这里可以接入实际的翻译API,如百度翻译、谷歌翻译、DeepL等
# 示例:简单的演示翻译
if target_lang == 'zh':
# 英译中示例
translations = {
'hello': '你好',
'world': '世界',
'hello world': '你好,世界',
'welcome': '欢迎',
'thank you': '谢谢',
'goodbye': '再见'
}
return translations.get(text.lower(), f"[翻译] {text}")
else:
# 中译英示例
translations = {
'你好': 'Hello',
'世界': 'World',
'你好世界': 'Hello World',
'欢迎': 'Welcome',
'谢谢': 'Thank you',
'再见': 'Goodbye'
}
return translations.get(text, f"[Translate] {text}")
def translate_file(input_path: str, output_path: str = None, target_lang: str = None) -> None:
"""
翻译文件内容
:param input_path: 输入文件路径
:param output_path: 输出文件路径,默认在原文件名后加 .translated
:param target_lang: 目标语言
"""
try:
with open(input_path, 'r', encoding='utf-8') as f:
content = f.read()
lines = content.split('\n')
translated_lines = []
for line in lines:
if line.strip() == '':
translated_lines.append('')
continue
translated = translate_text(line, target_lang)
translated_lines.append(translated)
translated_content = '\n'.join(translated_lines)
if output_path is None:
output_path = f"{input_path}.translated"
with open(output_path, 'w', encoding='utf-8') as f:
f.write(translated_content)
print(f"翻译完成,结果已保存到: {output_path}")
except Exception as e:
print(f"翻译失败: {str(e)}")
sys.exit(1)
def main():
parser = argparse.ArgumentParser(description='中英文批量翻译工具')
parser.add_argument('input', help='输入文本或文件路径')
parser.add_argument('--target', '-t', choices=['zh', 'en'], help='目标语言,zh=中文,en=英文,默认自动识别')
parser.add_argument('--file', '-f', action='store_true', help='输入是文件路径')
parser.add_argument('--output', '-o', help='输出文件路径(仅文件模式有效)')
args = parser.parse_args()
if args.file:
translate_file(args.input, args.output, args.target)
else:
result = translate_text(args.input, args.target)
print(result)
if __name__ == '__main__':
main()
#!/usr/bin/env python3
"""
Markdown文档翻译工具
保留原始格式,仅翻译文本内容
"""
import re
import sys
import argparse
from translate_batch import translate_text
def is_markdown_special(line: str) -> bool:
"""
判断是否是Markdown特殊格式行,不需要翻译
"""
# 代码块标记
if line.strip().startswith('```'):
return True
# 标题
if line.strip().startswith('#'):
return False # 标题需要翻译
# 图片
if re.match(r'!\[.*\]\(.*\)', line.strip()):
return False # 图片alt文本需要翻译
# 链接
if re.match(r'\[.*\]\(.*\)', line.strip()):
return False # 链接文本需要翻译
# 列表项
if line.strip().startswith(('- ', '* ', '+ ')) or re.match(r'^\d+\. ', line.strip()):
return False # 列表内容需要翻译
# 水平线
if line.strip() in ('---', '***', '___'):
return True
# 引用块标记
if line.strip().startswith('>'):
return False # 引用内容需要翻译
# 表格分隔线
if re.match(r'^\|?\s*:?-+:?\s*(\|\s*:?-+:?\s*)*\|?$', line.strip()):
return True
# HTML标签
if re.match(r'<[^>]+>', line.strip()):
return True
# 注释
if line.strip().startswith('<!--') and line.strip().endswith('-->'):
return True
# 代码行(缩进4个空格或tab)
if line.startswith(' ') or line.startswith('\t'):
return True
return False
def translate_markdown_line(line: str, target_lang: str = None) -> str:
"""
翻译单行Markdown内容,保留格式
"""
original_line = line
leading_spaces = len(line) - len(line.lstrip())
line_stripped = line.lstrip()
# 处理列表项
list_match = re.match(r'^([-*+] |\d+\. )(.*)$', line_stripped)
if list_match:
prefix = list_match.group(1)
content = list_match.group(2)
translated = translate_text(content, target_lang)
return ' ' * leading_spaces + prefix + translated
# 处理引用块
quote_match = re.match(r'^(>+) ?(.*)$', line_stripped)
if quote_match:
prefix = quote_match.group(1) + ' '
content = quote_match.group(2)
translated = translate_text(content, target_lang)
return ' ' * leading_spaces + prefix + translated
# 处理标题
heading_match = re.match(r'^(#{1,6}) (.*)$', line_stripped)
if heading_match:
prefix = heading_match.group(1) + ' '
content = heading_match.group(2)
translated = translate_text(content, target_lang)
return ' ' * leading_spaces + prefix + translated
# 处理图片
def replace_image(match):
alt_text = match.group(1)
url = match.group(2)
translated_alt = translate_text(alt_text, target_lang)
return f''
line_stripped = re.sub(r'!\[(.*?)\]\((.*?)\)', replace_image, line_stripped)
# 处理链接
def replace_link(match):
link_text = match.group(1)
url = match.group(2)
translated_text = translate_text(link_text, target_lang)
return f'[{translated_text}]({url})'
line_stripped = re.sub(r'\[(.*?)\]\((.*?)\)', replace_link, line_stripped)
# 处理加粗
def replace_bold(match):
content = match.group(1)
translated = translate_text(content, target_lang)
return f'**{translated}**'
line_stripped = re.sub(r'\*\*(.*?)\*\*', replace_bold, line_stripped)
# 处理斜体
def replace_italic(match):
content = match.group(1)
translated = translate_text(content, target_lang)
return f'*{translated}*'
line_stripped = re.sub(r'\*(.*?)\*', replace_italic, line_stripped)
# 处理行内代码
parts = re.split(r'(`[^`]+`)', line_stripped)
translated_parts = []
for part in parts:
if part.startswith('`') and part.endswith('`'):
translated_parts.append(part) # 代码不翻译
else:
translated_parts.append(translate_text(part, target_lang))
line_stripped = ''.join(translated_parts)
return ' ' * leading_spaces + line_stripped
def translate_markdown_file(input_path: str, output_path: str = None, target_lang: str = None) -> None:
"""
翻译Markdown文件
"""
try:
with open(input_path, 'r', encoding='utf-8') as f:
lines = f.readlines()
translated_lines = []
in_code_block = False
for line in lines:
original_line = line.rstrip('\n')
# 处理代码块
if original_line.strip().startswith('```'):
in_code_block = not in_code_block
translated_lines.append(original_line)
continue
if in_code_block:
translated_lines.append(original_line)
continue
# 空行直接保留
if original_line.strip() == '':
translated_lines.append('')
continue
# 特殊格式行
if is_markdown_special(original_line):
translated_lines.append(original_line)
continue
# 翻译普通行
translated = translate_markdown_line(original_line, target_lang)
translated_lines.append(translated)
translated_content = '\n'.join(translated_lines) + '\n'
if output_path is None:
output_path = f"{input_path}.translated"
with open(output_path, 'w', encoding='utf-8') as f:
f.write(translated_content)
print(f"Markdown翻译完成,结果已保存到: {output_path}")
except Exception as e:
print(f"翻译失败: {str(e)}")
sys.exit(1)
def main():
parser = argparse.ArgumentParser(description='Markdown文档翻译工具')
parser.add_argument('input', help='输入Markdown文件路径')
parser.add_argument('--target', '-t', choices=['zh', 'en'], help='目标语言,zh=中文,en=英文,默认自动识别')
parser.add_argument('--output', '-o', help='输出文件路径')
args = parser.parse_args()
translate_markdown_file(args.input, args.output, args.target)
if __name__ == '__main__':
main()
Related skills
FAQ
How does translate-en-zh keep terms consistent?
It bundles glossaries (tech_terms.md, business_terms.md, common_terms.md) so the same term is translated the same way throughout.
Can it translate whole files?
Yes. It includes translate_batch.py for text files and translate_markdown.py that preserves markdown structure.