Skip to content

ave/trancelate-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

translate-cli

コマンドラインで動く英日翻訳ツール。複数の翻訳エンジンに対応し、結果を JSON で返す。

要件

  • macOS 26 以上
  • Swift 6.0 以上

ビルド

swift build

使い方

.build/debug/translate-cli [--engine <エンジン名>] <テキスト>

複数段落は \n で区切る:

.build/debug/translate-cli "First paragraph\nSecond paragraph"

翻訳エンジン

--engine オプションで翻訳エンジンを選択できる。デフォルトは translation

.build/debug/translate-cli --engine translation "Hello world"
.build/debug/translate-cli --engine foundation-models "Hello world"
.build/debug/translate-cli --engine deepl "Hello world"

translation(デフォルト)

Apple Translation framework を使ったオンデバイス翻訳。追加設定不要。

ソース言語は英語(en)固定。ターゲット言語はシステムの優先言語。

.build/debug/translate-cli "Hello, world."

foundation-models

Apple Intelligence の Foundation Models(オンデバイス LLM)を使った翻訳。追加設定不要。

Apple Intelligence が利用可能なデバイスと macOS 26 以上が必要。Apple Intelligence が無効またはモデルが未ダウンロードの場合はエラーになる。

.build/debug/translate-cli --engine foundation-models "Hello, world."

エラー例:

{ "error": "Foundation Models unavailable: ..." }

deepl

DeepL API Free を使ったクラウド翻訳。事前に API キーの取得と環境変数の設定が必要。

API キーの取得:

  1. DeepL API Free でアカウントを作成
  2. アカウントページから API キーをコピー

環境変数の設定:

export DEEPL_API_KEY="your-api-key-here"

~/.zshrc などに追記しておくと毎回不要:

echo 'export DEEPL_API_KEY="your-api-key-here"' >> ~/.zshrc
source ~/.zshrc

実行:

.build/debug/translate-cli --engine deepl "Hello, world."

ソース言語は英語(EN)、ターゲット言語は日本語(JA)固定。

エラー例:

エラー 原因
DEEPL_API_KEY environment variable not set 環境変数が未設定
DeepL rate limit exceeded (HTTP 429) レート制限
DeepL free tier quota exceeded (HTTP 456) 無料枠の上限超過

出力形式

成功時は stdout に JSON を出力する:

{
  "paragraphs": [
    {
      "original": "First paragraph",
      "translated": "最初の段落"
    },
    {
      "original": "Second paragraph",
      "translated": "2番目の段落"
    }
  ]
}

エラー時は stderr に JSON を出力し、exit code 1 で終了する:

{
  "error": "エラーメッセージ"
}

利用アプリ

  • translate-app — ElectronベースのWebページ翻訳リーダー

About

Macのネイティブ翻訳機能を利用した翻訳CLI

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages