1313# limitations under the License.
1414
1515# [START translate_v3_translate_text]
16+ # [START translate_v3_translate_text_0]
17+ # Imports the Google Cloud Translation library
1618from google .cloud import translate
19+ # [END translate_v3_translate_text_0]
1720
1821
22+ # [START translate_v3_translate_text_1]
23+ # Initialize Translation client
1924def translate_text (text = "YOUR_TEXT_TO_TRANSLATE" , project_id = "YOUR_PROJECT_ID" ):
2025 """Translating Text."""
2126
@@ -24,7 +29,10 @@ def translate_text(text="YOUR_TEXT_TO_TRANSLATE", project_id="YOUR_PROJECT_ID"):
2429 location = "global"
2530
2631 parent = f"projects/{ project_id } /locations/{ location } "
32+ # [END translate_v3_translate_text_1]
2733
34+ # [START translate_v3_translate_text_2]
35+ # Translate text from English to French
2836 # Detail on supported types can be found here:
2937 # https://cloud.google.com/translate/docs/supported-formats
3038 response = client .translate_text (
@@ -40,6 +48,7 @@ def translate_text(text="YOUR_TEXT_TO_TRANSLATE", project_id="YOUR_PROJECT_ID"):
4048 # Display the translation for each input text provided
4149 for translation in response .translations :
4250 print ("Translated text: {}" .format (translation .translated_text ))
51+ # [END translate_v3_translate_text_2]
4352
4453
4554# [END translate_v3_translate_text]
0 commit comments