_RJ 技術メモ

人生を豊かにする技術を提供する、筋肉

コマンドラインでGoogle翻訳をする

Bash Terminal alias bashrc google

自分だけかもしれませんが、翻訳したいときは、

テスト 翻訳
→test
test 翻訳
→テスト

のようにGoogleで検索するパターンが多いです。 これをいつものコマンド操作でできたらと思い以下を行いました。

Google翻訳のコマンドの導入

$ brew install translate-shell
$ trans {en=ja} "The server maintenance will end as scheduled."

¥The server maintenance will end as scheduled.

サーバーのメンテナンスはスケジュールどおりに終了します。
(Sābā no mentenansu wa sukejūru-dōri ni shūryō shimasu.)

Translations of The server maintenance will end as scheduled.
[ English -> 日本語 ]
...

aliasの登録

コマンドを省略したいため、~/bash_profileに以下のaliasを追記します。

alias t-ej="trans {en=ja}"
alias t-je="trans {ja=en}"

翻訳テスト

$ t-ej "The server maintenance will end as scheduled."

The server maintenance will end as scheduled.

サーバーのメンテナンスはスケジュールどおりに終了します。
(Sābā no mentenansu wa sukejūru-dōri ni shūryō shimasu.)

Translations of The server maintenance will end as scheduled.
[ English -> 日本語 ]

$ t-je "そのサーバーのメンテナンスはスケジュールどおりに終了します。"

サーバーのメンテナンスはスケジュールどおりに終了します。
(Sābā no mentenansu wa sukejūru-dōri ni shūryō shimasu.)

Server maintenance will be completed on schedule.

Translations of サーバーのメンテナンスはスケジュールどおりに終了します。
[ 日本語 -> English ]