实战范例:管道组合技
yaku 从 stdin 读取、写入 stdout,天生适合 Unix 管道。
翻译 PDF
Section titled “翻译 PDF”使用 markitdown 从 PDF 提取文字,再翻译:
markitdown report.pdf | yaku --to zh-CN --format md使用 curl 获取页面并翻译内容:
curl -s https://example.com | yaku --to zh-CN翻译 Markdown 内容:
curl -s https://raw.githubusercontent.com/user/repo/main/README.md | \ yaku --to zh-CN --format md翻译 GitHub issue
Section titled “翻译 GitHub issue”使用 GitHub CLI 获取并翻译 issue:
# 翻译 issue 内容gh issue view 123 --json body -q .body | yaku --to zh-CN
# 翻译 issue 的所有评论gh api repos/owner/repo/issues/123/comments \ --jq '.[].body' | yaku --to zh-CN翻译 API 响应
Section titled “翻译 API 响应”# 翻译 JSON API 响应curl -s https://api.example.com/products | yaku --to zh-CN --format json
# 翻译后用 jq 格式化curl -s https://api.example.com/data | \ yaku --to zh-CN --format json | jq '.'翻译剪贴板内容
Section titled “翻译剪贴板内容”# macOS:翻译剪贴板并覆盖pbpaste | yaku --to zh-CN | pbcopy
# Linux (xclip)xclip -selection clipboard -o | yaku --to zh-CN | xclip -selection clipboard翻译并写入文件
Section titled “翻译并写入文件”# 使用 -o 选项echo "Hello" | yaku --to zh-CN -o greeting.txt
# 使用 shell 重定向echo "Hello" | yaku --to zh-CN > greeting.txt
# 用循环翻译多个文件for f in docs/en/*.md; do yaku --to zh-CN -f "$f" -o "docs/zh-CN/$(basename "$f")"done翻译 man page
Section titled “翻译 man page”man ls | col -b | yaku --to zh-CN | lesscol -b 会移除 man page 输出中的格式控制码。
搭配文字处理工具
Section titled “搭配文字处理工具”# 只翻译前 100 行head -100 large-doc.md | yaku --to zh-CN --format md
# 翻译后计算字数yaku --to zh-CN -f article.en.md | wc -w
# 从代码中提取字符串并翻译grep -Eo '"[^"]*"' src/strings.go | yaku --to zh-CN- 用管道时记得加
--format。 没有扩展名可检测时,yaku 默认使用纯文本。请明确指定--format md、--format json或--format yaml。 - 翻译前先过滤。 用
head、tail或grep缩减输入量,节省 token 和时间。 - 输出文件时用
-o代替>。-o选项会在 stderr 打印确认信息,更清楚地表示文件已写入。