Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
YumaInaura opened this issue Feb 2, 2019 · 0 comments

Comments

@YumaInaura
Copy link
Owner

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

Google Translate API を有効化しておく

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

https://cloud.google.com/translate/docs/quickstart

トークンの取得

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant