Skip to content

Update v2 samples to explicitly use v2 library #2498

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion translate/cloud-client/quickstart.py
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
2 changes: 1 addition & 1 deletion translate/cloud-client/requirements.txt
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 translate/cloud-client/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