實戰範例:Pipe 組合技
yaku 從 stdin 讀取、寫入 stdout,天生適合 Unix pipeline。
翻譯 PDF
Section titled “翻譯 PDF”使用 markitdown 從 PDF 擷取文字,再翻譯:
markitdown report.pdf | yaku --to zh-TW --format md使用 curl 擷取頁面並翻譯內容:
curl -s https://example.com | yaku --to zh-TW翻譯 Markdown 內容:
curl -s https://raw.githubusercontent.com/user/repo/main/README.md | \ yaku --to zh-TW --format md翻譯 GitHub issue
Section titled “翻譯 GitHub issue”使用 GitHub CLI 擷取並翻譯 issue:
# 翻譯 issue 內容gh issue view 123 --json body -q .body | yaku --to zh-TW
# 翻譯 issue 的所有留言gh api repos/owner/repo/issues/123/comments \ --jq '.[].body' | yaku --to zh-TW翻譯 API 回應
Section titled “翻譯 API 回應”# 翻譯 JSON API 回應curl -s https://api.example.com/products | yaku --to zh-TW --format json
# 翻譯後用 jq 格式化curl -s https://api.example.com/data | \ yaku --to zh-TW --format json | jq '.'翻譯剪貼簿內容
Section titled “翻譯剪貼簿內容”# macOS:翻譯剪貼簿並覆蓋pbpaste | yaku --to zh-TW | pbcopy
# Linux (xclip)xclip -selection clipboard -o | yaku --to zh-TW | xclip -selection clipboard翻譯並寫入檔案
Section titled “翻譯並寫入檔案”# 使用 -o 選項echo "Hello" | yaku --to zh-TW -o greeting.txt
# 使用 shell 重新導向echo "Hello" | yaku --to zh-TW > greeting.txt
# 用迴圈翻譯多個檔案for f in docs/en/*.md; do yaku --to zh-TW -f "$f" -o "docs/zh-TW/$(basename "$f")"done翻譯 man page
Section titled “翻譯 man page”man ls | col -b | yaku --to zh-TW | lesscol -b 會移除 man page 輸出中的格式控制碼。
搭配文字處理工具
Section titled “搭配文字處理工具”# 只翻譯前 100 行head -100 large-doc.md | yaku --to zh-TW --format md
# 翻譯後計算字數yaku --to zh-TW -f article.en.md | wc -w
# 從程式碼中擷取字串並翻譯grep -Eo '"[^"]*"' src/strings.go | yaku --to zh-TW- 用 pipe 時記得加
--format。 沒有副檔名可偵測時,yaku 預設使用純文字。請明確指定--format md、--format json或--format yaml。 - 翻譯前先過濾。 用
head、tail或grep縮減輸入量,節省 token 和時間。 - 輸出檔案時用
-o取代>。-o選項會在 stderr 印出確認訊息,更清楚地表示檔案已寫入。