レシピ: パイプの組み合わせ
yakuはstdinから読み取り、stdoutに書き込むので、Unixパイプラインに自然にフィットします。
PDFの翻訳
Section titled “PDFの翻訳”markitdownでPDFからテキストを抽出し、翻訳します:
markitdown report.pdf | yaku --to ja --format mdWebページの翻訳
Section titled “Webページの翻訳”curlでページを取得し、内容を翻訳します:
curl -s https://example.com | yaku --to jaMarkdownコンテンツの場合:
curl -s https://raw.githubusercontent.com/user/repo/main/README.md | \ yaku --to ja --format mdGitHub issueの翻訳
Section titled “GitHub issueの翻訳”GitHub CLIを使ってissueを取得し翻訳します:
# issue本文を翻訳gh issue view 123 --json body -q .body | yaku --to ja
# issueの全コメントを翻訳gh api repos/owner/repo/issues/123/comments \ --jq '.[].body' | yaku --to jaAPIレスポンスの翻訳
Section titled “APIレスポンスの翻訳”# JSON APIレスポンスを翻訳curl -s https://api.example.com/products | yaku --to ja --format json
# 翻訳してjqでフォーマットcurl -s https://api.example.com/data | \ yaku --to ja --format json | jq '.'クリップボードの内容を翻訳
Section titled “クリップボードの内容を翻訳”# macOS: クリップボードを翻訳して上書きpbpaste | yaku --to ja | pbcopy
# Linux (xclip)xclip -selection clipboard -o | yaku --to ja | xclip -selection clipboard翻訳してファイルに書き込み
Section titled “翻訳してファイルに書き込み”# -oオプションを使用echo "Hello" | yaku --to ja -o greeting.txt
# シェルリダイレクトを使用echo "Hello" | yaku --to ja > greeting.txt
# ループで複数ファイルを翻訳for f in docs/en/*.md; do yaku --to ja -f "$f" -o "docs/ja/$(basename "$f")"donemanページの翻訳
Section titled “manページの翻訳”man ls | col -b | yaku --to ja | lesscol -bはmanページ出力からフォーマットコードを除去します。
テキスト処理との連携
Section titled “テキスト処理との連携”# 最初の100行だけ翻訳head -100 large-doc.md | yaku --to ja --format md
# 翻訳して単語数をカウントyaku --to ja -f article.en.md | wc -w
# コードから文字列を抽出して翻訳grep -Eo '"[^"]*"' src/strings.go | yaku --to ja- パイプ時は
--formatを使う。 ファイル拡張子がないとyakuはプレーンテキストをデフォルトにします。--format md、--format json、--format yamlを明示的に指定してください。 - 翻訳前にフィルタリングする。
head、tail、grepで入力サイズを減らしましょう。トークンと時間の節約になります。 - ファイル出力には
>より-oを使う。-oオプションはstderrに確認メッセージを表示するので、ファイルが書き込まれたことが明確になります。