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

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 1d4d2fd commit a065930
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion samples/snippets/quickstart.py
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
2 changes: 1 addition & 1 deletion samples/snippets/requirements.txt
@@ -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 samples/snippets/snippets.py
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 a065930

Please sign in to comment.