Skip to content

Commit 9e8cf1e

Browse files
authored
Update v2 samples to explicitly use v2 library (GoogleCloudPlatform#2498)
1 parent 0e89d13 commit 9e8cf1e

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

translate/cloud-client/quickstart.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
def run_quickstart():
1919
# [START translate_quickstart]
2020
# Imports the Google Cloud client library
21-
from google.cloud import translate
21+
from google.cloud import translate_v2 as translate
2222

2323
# Instantiates a client
2424
translate_client = translate.Client()
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
google-cloud-translate==1.6.0
1+
google-cloud-translate==2.0.0
22
google-cloud-storage==1.19.1

translate/cloud-client/snippets.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323

2424
import argparse
2525

26-
from google.cloud import translate
2726
import six
2827

2928

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

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

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

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

7274

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

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

108112
if isinstance(text, six.binary_type):

0 commit comments

Comments
 (0)