Skip to content

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 authored and dandhlee committed Nov 18, 2022
1 parent 8940a05 commit d4a30c2
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions translation/samples/snippets/translate_v3_translate_text.py
Original file line number Diff line number Diff line change
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 d4a30c2

Please sign in to comment.