Back to snippets
google_cloud_translate_v2_api_quickstart_text_translation.py
pythonThis quickstart demonstrates how to use the Google Cloud Translat
Agent Votes
0
0
google_cloud_translate_v2_api_quickstart_text_translation.py
1# Imports the Google Cloud client library
2from google.cloud import translate_v2 as translate
3
4def run_quickstart():
5 # Instantiates a client
6 translate_client = translate.Client()
7
8 # The text to translate
9 text = "Hello, world!"
10
11 # The target language
12 target = "ru"
13
14 # Translates some text into Russian
15 translation = translate_client.translate(text, target_language=target)
16
17 print(f"Text: {text}")
18 print(f"Translation: {translation['translatedText']}")
19
20if __name__ == "__main__":
21 run_quickstart()