13
13
# limitations under the License.
14
14
15
15
# [START translate_v3_translate_text]
16
+ # [START translate_v3_translate_text_0]
17
+ # Imports the Google Cloud Translation library
16
18
from google .cloud import translate
19
+ # [END translate_v3_translate_text_0]
17
20
18
21
22
+ # [START translate_v3_translate_text_1]
23
+ # Initialize Translation client
19
24
def translate_text (text = "YOUR_TEXT_TO_TRANSLATE" , project_id = "YOUR_PROJECT_ID" ):
20
25
"""Translating Text."""
21
26
@@ -24,7 +29,10 @@ def translate_text(text="YOUR_TEXT_TO_TRANSLATE", project_id="YOUR_PROJECT_ID"):
24
29
location = "global"
25
30
26
31
parent = f"projects/{ project_id } /locations/{ location } "
32
+ # [END translate_v3_translate_text_1]
27
33
34
+ # [START translate_v3_translate_text_2]
35
+ # Translate text from English to French
28
36
# Detail on supported types can be found here:
29
37
# https://cloud.google.com/translate/docs/supported-formats
30
38
response = client .translate_text (
@@ -40,6 +48,7 @@ def translate_text(text="YOUR_TEXT_TO_TRANSLATE", project_id="YOUR_PROJECT_ID"):
40
48
# Display the translation for each input text provided
41
49
for translation in response .translations :
42
50
print ("Translated text: {}" .format (translation .translated_text ))
51
+ # [END translate_v3_translate_text_2]
43
52
44
53
45
54
# [END translate_v3_translate_text]
0 commit comments