3
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Google翻訳APIをシェルスクリプトで叩いて英語を日本語に翻訳する。ほとんど公式チュートリアルのまま。

Last updated at Posted at 2019-02-02

Google翻訳APIをシェルスクリプトで叩いて英語を日本語に翻訳する。ほとんど公式チュートリアルのまま。

Google Translate API を有効化しておく

チュートリアルのとおりに。

トークンの取得

Google Cloud の認証トークンを gcloud コマンドで取得する。環境変数でサービスアカウントファイルを指定する例。 · Issue #545 · YumaInaura/YumaInaura

Script

key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

curl "https://translation.googleapis.com/language/translate/v2" \
  -H "Authorization: Bearer $key" \
  -s -X POST -H "Content-Type: application/json" \
  --data "{ 'q': 'The Great Pyramid of Giza (also known as the Pyramid of Khufu or the Pyramid of Cheops) is the oldest and largest of the three pyramids in the Giza pyramid complex.', 'source': 'en', 'target': 'ja', 'format': 'text' }"

結果

$ sh example.sh
{
  "data": {
    "translations": [
      {
        "translatedText": "ギザの大ピラミッド(クフのピラミッドまたはチープのピラミッドとしても知られています)は、ギザピラミッド複合体の3つのピラミッドの中で最も古く、最も大きいピラミッドです。"
      }
    ]
  }
}

Ref

Cloud Translation API ドキュメント  |  Cloud Translation API  |  Google Cloud

クイックスタート  |  Cloud Translation API  |  Google Cloud

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

Twitter

3
6
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
3
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?