Skip to content

Commit

Permalink
Update v2 samples to explicitly use v2 library [(#2498)](GoogleCloudP…
Browse files Browse the repository at this point in the history
  • Loading branch information
nnegrey authored and danoscarmike committed Jul 31, 2020
1 parent cf0fd3a commit 679661c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
def run_quickstart():
# [START translate_quickstart]
# Imports the Google Cloud client library
from google.cloud import translate
from google.cloud import translate_v2 as translate

# Instantiates a client
translate_client = translate.Client()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
google-cloud-translate==1.6.0
google-cloud-translate==2.0.0
google-cloud-storage==1.19.1
8 changes: 6 additions & 2 deletions packages/google-cloud-translate/samples/snippets/snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@

import argparse

from google.cloud import translate
import six


def detect_language(text):
# [START translate_detect_language]
"""Detects the text's language."""
from google.cloud import translate_v2 as translate
translate_client = translate.Client()

# Text can also be a sequence of strings, in which case this method
Expand All @@ -45,6 +45,7 @@ def detect_language(text):
def list_languages():
# [START translate_list_codes]
"""Lists all available languages."""
from google.cloud import translate_v2 as translate
translate_client = translate.Client()

results = translate_client.get_languages()
Expand All @@ -61,6 +62,7 @@ def list_languages_with_target(target):
Target must be an ISO 639-1 language code.
See https://g.co/cloud/translate/v2/translate-reference#supported_languages
"""
from google.cloud import translate_v2 as translate
translate_client = translate.Client()

results = translate_client.get_languages(target_language=target)
Expand All @@ -70,7 +72,7 @@ def list_languages_with_target(target):
# [END translate_list_language_names]


def translate_text_with_model(target, text, model=translate.NMT):
def translate_text_with_model(target, text, model='nmt'):
# [START translate_text_with_model]
"""Translates text into the target language.
Expand All @@ -79,6 +81,7 @@ def translate_text_with_model(target, text, model=translate.NMT):
Target must be an ISO 639-1 language code.
See https://g.co/cloud/translate/v2/translate-reference#supported_languages
"""
from google.cloud import translate_v2 as translate
translate_client = translate.Client()

if isinstance(text, six.binary_type):
Expand All @@ -103,6 +106,7 @@ def translate_text(target, text):
Target must be an ISO 639-1 language code.
See https://g.co/cloud/translate/v2/translate-reference#supported_languages
"""
from google.cloud import translate_v2 as translate
translate_client = translate.Client()

if isinstance(text, six.binary_type):
Expand Down

0 comments on commit 679661c

Please sign in to comment.