LoginSignup
16
12

More than 3 years have passed since last update.

aws translateコマンドをシェルのエイリアスに設定すると便利

Last updated at Posted at 2019-05-10

AWS Translateが東京リージョンに来ましたね。わーい。
https://aws.amazon.com/jp/about-aws/whats-new/2019/05/amazon-translate-available-mumbai-singapore-tokyo-canadacentral/

ふと、これシェルのエイリアスに登録しとくと便利じゃね?
と思いついたのでやってみたよ。

こんなエイリアスを仕込む。

alias en='(){ aws --profile minamijoyo translate translate-text --source-language-code ja --target-language-code en --text $@ | jq -r .TranslatedText }'

alias ja='(){ aws --profile minamijoyo translate translate-text --source-language-code en --target-language-code ja --text $@ | jq -r .TranslatedText }'

※ 手元の環境はzshですが、bashだと無名関数使えない気がするので適当に関数にしたらよいんじゃないかな。
--profile minamijoyo のところは複数のAWSアカウントを切り替えて使ってるので、適宜自分のAWSプロファイルに読み替えて下さい。

こんなかんじで使う。

$ en "aws translateコマンドをシェルのエイリアスに設定すると便利です"
It is useful to set the aws translate command to an alias for the shell

$ ja "It is useful to set the aws translate command to an alias for the shell"
aws translateコマンドをシェルのエイリアスに設定すると便利です。

翻訳の精度は知らんけど。
コミットメッセージ書くのにぱっと英語で出てこないときとか、ブラウザすら開きたくないときとかによいんではなかろうか。

1点注意点として、料金は無料ではなくて、100 万文字あたり 15 USD (0.000015 USD/文字) です。
まぁAWSを普段使いしてる人がちょっと使う分には誤差でしょう。
https://aws.amazon.com/jp/translate/pricing/

16
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
12