コマンドラインでGoogle翻訳する
macOSやLinuxのコマンドラインでGoogle翻訳ができる「translate-shell」なるプログラムを発見した。複数のエンジンに対応しておりBing翻訳なんかもできるらしい。
注意 編集
インストール 編集
brew install translate-shell
基本 編集
基本形。
trans 翻訳元:翻訳先 "hello world"
こんな感じ。
trans en:ja "hello world"
言語一覧表示は「-R」。
trans -R
翻訳元を指定しなければ自動認識。
trans :ja "hello world"
翻訳先も指定しなければOSの言語(日本語)になる。
trans "hello world"
辞書モード 編集
単語などの意味を調べたい場合は「-d」。 dictionaryのdだ。bじゃないよ。
trans -d hello
訳文のみ表示 編集
元文章を表示しない場合は「-b」を付ける。
trans -b :ja "hello world"
パイプで使う 編集
パイプで渡した場合は行単位で翻訳される。知らずにcatしたものを渡したら一撃でGoogle先生に通信制限された。
cat README.md | trans -b
cat README.md | tr -d '\n' | trans -b