輸入與輸出
yaku 接受以下四種輸入方式,依優先順序檢查:
| 優先順序 | 方式 | 範例 |
|---|---|---|
| 1(最高) | 檔案(-f) | yaku --to zh-TW -f article.en.txt |
| 2 | 位置參數 | yaku --to zh-TW "Hello, world" |
| 3 | stdin pipe | echo "Hello" | yaku --to zh-TW |
| 4(最低) | 互動模式 | yaku --to zh-TW 然後輸入文字 + Ctrl+D |
同時提供多種輸入時,優先順序較高的來源會被採用。
檔案輸入(-f)
Section titled “檔案輸入(-f)”翻譯一個或多個檔案。指定多個檔案時,內容會被串接:
# 單一檔案yaku --to zh-TW -f README.en.md
# 多個檔案yaku --to zh-TW -f chapter1.en.md -f chapter2.en.mdyaku 會根據副檔名(.md、.json、.yaml)自動偵測格式。詳見格式感知翻譯。
在命令列直接傳入短文字:
yaku --to zh-TW "Good morning"yaku --to zh-TW "The meeting is tomorrow at ten."多個參數會以空格連接:
yaku --to zh-TW Hello world# 翻譯 "Hello world"stdin pipe
Section titled “stdin pipe”從其他指令 pipe 文字:
echo "Hello, world" | yaku --to zh-TWcat article.en.md | yaku --to zh-TWgit log --oneline -5 | yaku --to zh-TWcurl -s https://example.com/api/docs | yaku --to zh-TW只有在沒有 -f 選項且沒有位置參數時,yaku 才會讀取 stdin。yaku 會偵測 stdin 是 pipe 還是終端機:
-
Pipe 模式 — 靜默讀取(例如
echo "Hello" | yaku --to zh-TW) -
互動模式 — 如果在終端機中執行
yaku --to zh-TW且沒有輸入,yaku 會提示你直接輸入文字:Enter text to translate (Ctrl+D to finish):輸入或貼上文字,然後按 Ctrl+D 送出。
stdout(預設)
Section titled “stdout(預設)”yaku 將翻譯結果寫入 stdout,不含其他內容。錯誤訊息、提示和詳細資訊都輸出到 stderr。這讓輸出保持乾淨,方便 pipe 串接:
# Pipe 到剪貼簿(macOS)echo "Hello" | yaku --to zh-TW | pbcopy
# Pipe 到其他指令yaku --to zh-TW -f report.en.md | wc -w
# 重導向到檔案yaku --to zh-TW -f doc.en.md > translated.md檔案輸出(-o)
Section titled “檔案輸出(-o)”直接寫入檔案:
yaku --to zh-TW -f README.en.md -o README.mdyaku 會在 stderr 印出確認訊息:
Wrote README.md詳細輸出(--verbose)
Section titled “詳細輸出(--verbose)”將模型名稱、token 用量和經過時間印到 stderr:
echo "Hello" | yaku --to zh-TW --verbosestdout:
你好stderr:
Model: gemini-2.5-flash | Tokens: 42 in / 38 out | Time: 1.2s詳細資訊輸出到 stderr,所以 stdout 仍然可以乾淨地 pipe:
echo "Hello" | yaku --to zh-TW --verbose | pbcopy# 剪貼簿得到「你好」,終端機顯示模型資訊yaku 會自動清除翻譯文字中常見的 LLM 雜訊:
- 移除前導語 — 刪除不需要的前綴,例如「Here is the translation:」或「Translation:」
- 移除尾部說明 — 刪除 LLM 在雙換行後附加的備註(例如「Note: I translated X as Y because…」)
- 移除包裹引號 — 刪除
"text"或「text」包裹 - 移除程式碼圍欄 — 刪除輸出周圍的
```包裹
這在所有後端上自動執行。你不需要手動啟用。