Skip to content

Commit 615c08e

Browse files
committed
Update v3 samples to use default library
1 parent 824d83b commit 615c08e

19 files changed

+35
-37
lines changed

translate/cloud-client/beta_snippets_test.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def unique_glossary_id():
6363
def test_translate_text(capsys):
6464
beta_snippets.translate_text(PROJECT_ID, 'Hello world')
6565
out, _ = capsys.readouterr()
66-
assert 'Zdravo svet' in out
66+
assert 'Zdravo svet' in out or 'Pozdrav svijetu' in out
6767

6868

6969
def test_batch_translate_text(capsys, bucket):
@@ -99,7 +99,6 @@ def test_create_glossary(capsys, unique_glossary_id):
9999
beta_snippets.create_glossary(PROJECT_ID, unique_glossary_id)
100100
out, _ = capsys.readouterr()
101101
assert 'Created' in out
102-
assert PROJECT_ID in out
103102
assert unique_glossary_id in out
104103
assert 'gs://cloud-samples-data/translation/glossary.csv' in out
105104

@@ -129,6 +128,5 @@ def test_delete_glossary(capsys, unique_glossary_id):
129128
beta_snippets.create_glossary(PROJECT_ID, unique_glossary_id)
130129
beta_snippets.delete_glossary(PROJECT_ID, unique_glossary_id)
131130
out, _ = capsys.readouterr()
132-
assert PROJECT_ID in out
133131
assert 'us-central1' in out
134132
assert unique_glossary_id in out

translate/cloud-client/quickstart.py

Lines changed: 1 addition & 1 deletion
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()
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
google-cloud-translate==1.7.0
1+
google-cloud-translate==2.0.0
22
google-cloud-storage==1.19.1

translate/cloud-client/snippets.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
import argparse
2525

26-
from google.cloud import translate
26+
from google.cloud import translate_v2 as translate
2727
import six
2828

2929

@@ -70,7 +70,7 @@ def list_languages_with_target(target):
7070
# [END translate_list_language_names]
7171

7272

73-
def translate_text_with_model(target, text, model=translate.NMT):
73+
def translate_text_with_model(target, text, model='nmt'):
7474
# [START translate_text_with_model]
7575
"""Translates text into the target language.
7676

translate/cloud-client/translate_v3_batch_translate_text.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@
2525
# usage: python3 translate_v3_batch_translate_text.py [--input_uri "gs://cloud-samples-data/text.txt"] [--output_uri "gs://YOUR_BUCKET_ID/path_to_store_results/"] [--project_id "[Google Cloud Project ID]"] [--location "us-central1"] [--source_lang en] [--target_lang ja]
2626

2727
# [START translate_v3_batch_translate_text]
28-
from google.cloud import translate_v3
28+
from google.cloud import translate
2929

3030
def sample_batch_translate_text(
3131
input_uri, output_uri, project_id, location, source_lang, target_lang
3232
):
3333
"""Batch translate text"""
3434

35-
client = translate_v3.TranslationServiceClient()
35+
client = translate.TranslationServiceClient()
3636

3737
# TODO(developer): Uncomment and set the following variables
3838
# input_uri = 'gs://cloud-samples-data/text.txt'

translate/cloud-client/translate_v3_batch_translate_text_with_glossary.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@
2525
# usage: python3 translate_v3_batch_translate_text_with_glossary.py [--input_uri "gs://cloud-samples-data/text.txt"] [--output_uri "gs://YOUR_BUCKET_ID/path_to_store_results/"] [--project "[Google Cloud Project ID]"] [--location "us-central1"] [--glossary_id "[YOUR_GLOSSARY_ID]"] [--target_language en] [--source_language de]
2626

2727
# [START translate_v3_batch_translate_text_with_glossary]
28-
from google.cloud import translate_v3
28+
from google.cloud import translate
2929

3030
def sample_batch_translate_text_with_glossary(
3131
input_uri, output_uri, project_id, location, source_lang, target_lang, glossary_id
3232
):
3333
"""Batch translate text with Glossary"""
3434

35-
client = translate_v3.TranslationServiceClient()
35+
client = translate.TranslationServiceClient()
3636

3737
# TODO(developer): Uncomment and set the following variables
3838
# input_uri = 'gs://cloud-samples-data/text.txt'
@@ -59,7 +59,7 @@ def sample_batch_translate_text_with_glossary(
5959
'us-central1', # The location of the glossary
6060
glossary_id)
6161

62-
glossary_config = translate_v3.types.TranslateTextGlossaryConfig(
62+
glossary_config = translate.types.TranslateTextGlossaryConfig(
6363
glossary=glossary_path)
6464

6565
glossaries = {"ja": glossary_config} #target lang as key

translate/cloud-client/translate_v3_batch_translate_text_with_glossary_and_model.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
# usage: python3 translate_v3_batch_translate_text_with_glossary_and_model.py [--input_uri "gs://cloud-samples-data/text.txt"] [--output_uri "gs://YOUR_BUCKET_ID/path_to_store_results/"] [--project "[Google Cloud Project ID]"] [--location "us-central1"] [--target_language en] [--source_language de] [--model_id "{your-model-id}"] [--glossary_id "{your-glossary-id}"]
2626

2727
# [START translate_v3_batch_translate_text_with_glossary_and_model]
28-
from google.cloud import translate_v3
28+
from google.cloud import translate
2929

3030
def sample_batch_translate_text_with_glossary_and_model(
3131
input_uri,
@@ -41,7 +41,7 @@ def sample_batch_translate_text_with_glossary_and_model(
4141
Batch translate text with Glossary and Translation model
4242
"""
4343

44-
client = translate_v3.TranslationServiceClient()
44+
client = translate.TranslationServiceClient()
4545

4646
# TODO(developer): Uncomment and set the following variables
4747
# input_uri = 'gs://cloud-samples-data/text.txt'
@@ -70,7 +70,7 @@ def sample_batch_translate_text_with_glossary_and_model(
7070
'us-central1', # The location of the glossary
7171
glossary_id)
7272

73-
glossary_config = translate_v3.types.TranslateTextGlossaryConfig(
73+
glossary_config = translate.types.TranslateTextGlossaryConfig(
7474
glossary=glossary_path)
7575
glossaries = {"ja": glossary_config} #target lang as key
7676

translate/cloud-client/translate_v3_batch_translate_text_with_model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
# usage: python3 translate_v3_batch_translate_text_with_model.py [--input_uri "gs://cloud-samples-data/text.txt"] [--output_uri "gs://YOUR_BUCKET_ID/path_to_store_results/"] [--project "[Google Cloud Project ID]"] [--location "us-central1"] [--target_language en] [--source_language de] [--model_id "{your-model-id}"]
2626

2727
# [START translate_v3_batch_translate_text_with_model]
28-
from google.cloud import translate_v3
28+
from google.cloud import translate
2929

3030

3131
def sample_batch_translate_text_with_model(
@@ -47,7 +47,7 @@ def sample_batch_translate_text_with_model(
4747
code.
4848
"""
4949

50-
client = translate_v3.TranslationServiceClient()
50+
client = translate.TranslationServiceClient()
5151

5252
# TODO(developer): Uncomment and set the following variables
5353
# input_uri = 'gs://cloud-samples-data/text.txt'

translate/cloud-client/translate_v3_create_glossary.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
# usage: python3 translate_v3_create_glossary.py [--project "[Google Cloud Project ID]"] [--glossary_id "my_glossary_id_123"]
2626

2727
# [START translate_v3_create_glossary]
28-
from google.cloud import translate_v3 as translate
28+
from google.cloud import translate
2929

3030
def sample_create_glossary(project_id, input_uri, glossary_id):
3131
"""Create Glossary"""

translate/cloud-client/translate_v3_delete_glossary.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
# usage: python3 translate_v3_delete_glossary.py [--project_id "[Google Cloud Project ID]"] [--glossary_id "[Glossary ID]"]
2626

2727
# [START translate_v3_delete_glossary]
28-
from google.cloud import translate_v3 as translate
28+
from google.cloud import translate
2929

3030
def sample_delete_glossary(project_id, glossary_id):
3131
"""Delete Glossary"""

translate/cloud-client/translate_v3_detect_language.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
# usage: python3 translate_v3_detect_language.py [--text "Hello, world!"] [--project_id "[Google Cloud project_id ID]"]
2626

2727
# [START translate_v3_detect_language]
28-
from google.cloud import translate_v3
28+
from google.cloud import translate
2929

3030

3131
def sample_detect_language(text, project_id):
@@ -36,7 +36,7 @@ def sample_detect_language(text, project_id):
3636
text The text string for performing language detection
3737
"""
3838

39-
client = translate_v3.TranslationServiceClient()
39+
client = translate.TranslationServiceClient()
4040

4141
# TODO(developer): Uncomment and set the following variables
4242
# text = 'Hello, world!'

translate/cloud-client/translate_v3_get_glossary.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
# usage: python3 translate_v3_get_glossary.py [--project_id "[Google Cloud Project ID]"] [--glossary_id "[Glossary ID]"]
2626

2727
# [START translate_v3_get_glossary]
28-
from google.cloud import translate_v3
28+
from google.cloud import translate
2929

3030
def sample_get_glossary(project_id, glossary_id):
3131
"""Get Glossary"""
3232

33-
client = translate_v3.TranslationServiceClient()
33+
client = translate.TranslationServiceClient()
3434

3535
# TODO(developer): Uncomment and set the following variables
3636
# project = '[Google Cloud Project ID]'

translate/cloud-client/translate_v3_get_supported_languages.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
# usage: python3 translate_v3_get_supported_languages.py [--project_id "[Google Cloud Project ID]"]
2626

2727
# [START translate_v3_get_supported_languages]
28-
from google.cloud import translate_v3
28+
from google.cloud import translate
2929

3030
def sample_get_supported_languages(project_id):
3131
"""Getting a list of supported language codes"""
3232

33-
client = translate_v3.TranslationServiceClient()
33+
client = translate.TranslationServiceClient()
3434

3535
# TODO(developer): Uncomment and set the following variables
3636
# project = '[Google Cloud Project ID]'

translate/cloud-client/translate_v3_get_supported_languages_for_target.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
# usage: python3 translate_v3_get_supported_languages_for_target.py [--language_code en] [--project_id "[Google Cloud Project ID]"]
2626

2727
# [START translate_v3_get_supported_languages_for_target]
28-
from google.cloud import translate_v3
28+
from google.cloud import translate
2929

3030

3131
def sample_get_supported_languages_with_target(language_code, project_id):
@@ -37,7 +37,7 @@ def sample_get_supported_languages_with_target(language_code, project_id):
3737
human readable names of supported languages.
3838
"""
3939

40-
client = translate_v3.TranslationServiceClient()
40+
client = translate.TranslationServiceClient()
4141

4242
# TODO(developer): Uncomment and set the following variables
4343
# language_code = 'en'

translate/cloud-client/translate_v3_list_glossary.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
# usage: python3 translate_v3_list_glossary.py [--project_id "[Google Cloud Project ID]"]
2626

2727
# [START translate_v3_list_glossary]
28-
from google.cloud import translate_v3
28+
from google.cloud import translate
2929

3030
def sample_list_glossaries(project_id):
3131
"""List Glossaries"""
3232

33-
client = translate_v3.TranslationServiceClient()
33+
client = translate.TranslationServiceClient()
3434

3535
# TODO(developer): Uncomment and set the following variables
3636
# project_id = '[Google Cloud Project ID]'

translate/cloud-client/translate_v3_translate_text.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
# usage: python3 translate_v3_translate_text.py [--text "Hello, world!"] [--target_language fr] [--project_id "[Google Cloud Project ID]"]
2626

2727
# [START translate_v3_translate_text]
28-
from google.cloud import translate_v3
28+
from google.cloud import translate
2929

3030

3131
def sample_translate_text(text, target_language, project_id):
@@ -37,7 +37,7 @@ def sample_translate_text(text, target_language, project_id):
3737
target_language Required. The BCP-47 language code to use for translation.
3838
"""
3939

40-
client = translate_v3.TranslationServiceClient()
40+
client = translate.TranslationServiceClient()
4141

4242
# TODO(developer): Uncomment and set the following variables
4343
# text = 'Text you wish to translate'

translate/cloud-client/translate_v3_translate_text_with_glossary.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
# usage: python3 translate_v3_translate_text_with_glossary.py [--text "Hello, world!"] [--source_language en] [--target_language fr] [--project_id "[Google Cloud Project ID]"] [--glossary_id "[YOUR_GLOSSARY_ID]"]
2626

2727
# [START translate_v3_translate_text_with_glossary]
28-
from google.cloud import translate_v3 as translate
28+
from google.cloud import translate
2929

3030
def sample_translate_text_with_glossary(
3131
text, source_language, target_language, project_id, glossary_id

translate/cloud-client/translate_v3_translate_text_with_glossary_and_model.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
# usage: python3 translate_v3_translate_text_with_glossary_and_model.py [--model_id "[MODEL ID]"] [--glossary_id "[YOUR_GLOSSARY_ID]"] [--text "Hello, world!"] [--target_language fr] [--source_language en] [--project_id "[Google Cloud Project ID]"] [--location global]
2626

2727
# [START translate_v3_translate_text_with_glossary_and_model]
28-
from google.cloud import translate_v3
28+
from google.cloud import translate
2929

3030

3131
def sample_translate_text_glossary_and_model(
@@ -42,7 +42,7 @@ def sample_translate_text_glossary_and_model(
4242
source_language Optional. The BCP-47 language code of the input text.
4343
"""
4444

45-
client = translate_v3.TranslationServiceClient()
45+
client = translate.TranslationServiceClient()
4646

4747
# TODO(developer): Uncomment and set the following variables
4848
# model_id = '[MODEL ID]'
@@ -61,7 +61,7 @@ def sample_translate_text_glossary_and_model(
6161
'us-central1', # The location of the glossary
6262
glossary_id)
6363

64-
glossary_config = translate_v3.types.TranslateTextGlossaryConfig(
64+
glossary_config = translate.types.TranslateTextGlossaryConfig(
6565
glossary=glossary)
6666

6767
response = client.translate_text(

translate/cloud-client/translate_v3_translate_text_with_model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
# usage: python3 translate_v3_translate_text_with_model.py [--model_id "[MODEL ID]"] [--text "Hello, world!"] [--target_language fr] [--source_language en] [--project_id "[Google Cloud Project ID]"] [--location global]
2626

2727
# [START translate_v3_translate_text_with_model]
28-
from google.cloud import translate_v3
28+
from google.cloud import translate
2929

3030

3131
def sample_translate_text_with_model(
@@ -41,7 +41,7 @@ def sample_translate_text_with_model(
4141
source_language Optional. The BCP-47 language code of the input text.
4242
"""
4343

44-
client = translate_v3.TranslationServiceClient()
44+
client = translate.TranslationServiceClient()
4545

4646
# TODO(developer): Uncomment and set the following variables
4747
# model_id = '[MODEL ID]'

0 commit comments

Comments
 (0)