LoginSignup
0
0

More than 3 years have passed since last update.

Python3: Google Cloud Translation API の使い方 (Basic)

Last updated at Posted at 2020-11-24

次のページを参考にしました。
テキストの翻訳(Basic)

ex01.py
#! /usr/bin/python
#
#
from google.cloud import translate_v2 as translate

text="Es war einmal ein kleines Mädchen."
target="ja"

translate_client = translate.Client()
#
result = translate_client.translate(text, target_language=target)

print("Text: {}".format(result["input"]))
print("Translation: {}".format(result["translatedText"]))
print("Detected source language: {}".format(result["detectedSourceLanguage"]))

実行方法

export GOOGLE_APPLICATION_CREDENTIALS=./***.json
#
./ex01.py

実行結果

Text: Es war einmal ein kleines Mädchen.
Translation: 昔々、小さな女の子がいました。
Detected source language: de

関連ページ
https://qiita.com/ekzemplaro/items/7316dfb0534405520831

0
0
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
0
0