I referred to the next page. Text Translation (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"]))
Execution method
export GOOGLE_APPLICATION_CREDENTIALS=./***.json
#
./ex01.py
Execution result
Text: Es war einmal ein kleines Mädchen.
Translation:Once upon a time there was a little girl.
Detected source language: de
Recommended Posts