跳到內容

實戰範例:Pipe 組合技

yaku 從 stdin 讀取、寫入 stdout,天生適合 Unix pipeline。

使用 markitdown 從 PDF 擷取文字,再翻譯:

Terminal window
markitdown report.pdf | yaku --to zh-TW --format md

使用 curl 擷取頁面並翻譯內容:

Terminal window
curl -s https://example.com | yaku --to zh-TW

翻譯 Markdown 內容:

Terminal window
curl -s https://raw.githubusercontent.com/user/repo/main/README.md | \
yaku --to zh-TW --format md

使用 GitHub CLI 擷取並翻譯 issue:

Terminal window
# 翻譯 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
Terminal window
# 翻譯 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 '.'
Terminal window
# macOS:翻譯剪貼簿並覆蓋
pbpaste | yaku --to zh-TW | pbcopy
# Linux (xclip)
xclip -selection clipboard -o | yaku --to zh-TW | xclip -selection clipboard
Terminal window
# 使用 -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
Terminal window
man ls | col -b | yaku --to zh-TW | less

col -b 會移除 man page 輸出中的格式控制碼。

Terminal window
# 只翻譯前 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
  • 翻譯前先過濾。headtailgrep 縮減輸入量,節省 token 和時間。
  • 輸出檔案時用 -o 取代 > -o 選項會在 stderr 印出確認訊息,更清楚地表示檔案已寫入。