Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
docs(samples): Add Cloud Code tags for API Explorer pilot (#282)
Browse files Browse the repository at this point in the history
This adds region tags in order to support the Cloud Code API Explorer pilot
  • Loading branch information
abbycar committed Oct 25, 2021
1 parent 73b03aa commit 3e8df68
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions samples/snippets/translate_v3_translate_text.py
Expand Up @@ -13,9 +13,14 @@
# limitations under the License.

# [START translate_v3_translate_text]
# [START translate_v3_translate_text_0]
# Imports the Google Cloud Translation library
from google.cloud import translate
# [END translate_v3_translate_text_0]


# [START translate_v3_translate_text_1]
# Initialize Translation client
def translate_text(text="YOUR_TEXT_TO_TRANSLATE", project_id="YOUR_PROJECT_ID"):
"""Translating Text."""

Expand All @@ -24,7 +29,10 @@ def translate_text(text="YOUR_TEXT_TO_TRANSLATE", project_id="YOUR_PROJECT_ID"):
location = "global"

parent = f"projects/{project_id}/locations/{location}"
# [END translate_v3_translate_text_1]

# [START translate_v3_translate_text_2]
# Translate text from English to French
# Detail on supported types can be found here:
# https://cloud.google.com/translate/docs/supported-formats
response = client.translate_text(
Expand All @@ -40,6 +48,7 @@ def translate_text(text="YOUR_TEXT_TO_TRANSLATE", project_id="YOUR_PROJECT_ID"):
# Display the translation for each input text provided
for translation in response.translations:
print("Translated text: {}".format(translation.translated_text))
# [END translate_v3_translate_text_2]


# [END translate_v3_translate_text]

0 comments on commit 3e8df68

Please sign in to comment.