From 8f90e391057067270bdd59cfe6e2756cd4b8818e Mon Sep 17 00:00:00 2001 From: Puneith Kaul Date: Sun, 13 Nov 2016 15:20:30 -0800 Subject: [PATCH 1/7] added model in the sample --- translate/cloud-client/quickstart.py | 7 ++++++- translate/cloud-client/snippets.py | 9 ++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/translate/cloud-client/quickstart.py b/translate/cloud-client/quickstart.py index 51ab697c8f0..c8ae8fe2558 100644 --- a/translate/cloud-client/quickstart.py +++ b/translate/cloud-client/quickstart.py @@ -31,8 +31,13 @@ def run_quickstart(): # The target language target = 'ru' + # MT model type `base` or `nmt` + model = 'base' + # Translates some text into Russian - translation = translate_client.translate(text, target_language=target) + translation = translate_client.translate(text, + target_language=target, + model=model) print(u'Text: {}'.format(text)) print(u'Translation: {}'.format(translation['translatedText'])) diff --git a/translate/cloud-client/snippets.py b/translate/cloud-client/snippets.py index 1b5cad92ac3..bd8ab407136 100644 --- a/translate/cloud-client/snippets.py +++ b/translate/cloud-client/snippets.py @@ -63,7 +63,7 @@ def list_languages_with_target(api_key, target): print(u'{name} ({language})'.format(**language)) -def translate_text(api_key, target, text): +def translate_text(api_key, target, text, model='base'): """Translates text into the target language. Target must be an ISO 639-1 language code. @@ -73,7 +73,9 @@ def translate_text(api_key, target, text): # Text can also be a sequence of strings, in which case this method # will return a sequence of results for each text. - result = translate_client.translate(text, target_language=target) + result = translate_client.translate(text, + target_language=target, + model=model) print(u'Text: {}'.format(result['input'])) print(u'Translation: {}'.format(result['translatedText'])) @@ -103,6 +105,7 @@ def translate_text(api_key, target, text): 'translate-text', help=translate_text.__doc__) translate_text_parser.add_argument('target') translate_text_parser.add_argument('text') + translate_text_parser.add_argument('model') args = parser.parse_args() @@ -113,4 +116,4 @@ def translate_text(api_key, target, text): elif args.command == 'list-languages-with-target': list_languages_with_target(args.api_key, args.target) elif args.command == 'translate-text': - translate_text(args.api_key, args.target, args.text) + translate_text(args.api_key, args.target, args.text, args.model) From 0ec80c9921b59becc40f44647b752c86b0654cbe Mon Sep 17 00:00:00 2001 From: Puneith Kaul Date: Mon, 14 Nov 2016 10:28:04 -0800 Subject: [PATCH 2/7] break at opening paren --- translate/cloud-client/quickstart.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/translate/cloud-client/quickstart.py b/translate/cloud-client/quickstart.py index c8ae8fe2558..6aeebe2974f 100644 --- a/translate/cloud-client/quickstart.py +++ b/translate/cloud-client/quickstart.py @@ -35,9 +35,10 @@ def run_quickstart(): model = 'base' # Translates some text into Russian - translation = translate_client.translate(text, - target_language=target, - model=model) + translation = translate_client.translate( + text, + target_language=target, + model=model) print(u'Text: {}'.format(text)) print(u'Translation: {}'.format(translation['translatedText'])) From e5820203ec7978ae4122e15a4eca2d64d722f3c3 Mon Sep 17 00:00:00 2001 From: Puneith Kaul Date: Mon, 14 Nov 2016 11:10:36 -0800 Subject: [PATCH 3/7] added fix for the client as per new lib --- translate/cloud-client/quickstart.py | 2 +- translate/cloud-client/snippets.py | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/translate/cloud-client/quickstart.py b/translate/cloud-client/quickstart.py index 6aeebe2974f..5bb4a5085bb 100644 --- a/translate/cloud-client/quickstart.py +++ b/translate/cloud-client/quickstart.py @@ -24,7 +24,7 @@ def run_quickstart(): api_key = 'YOUR_API_KEY' # Instantiates a client - translate_client = translate.Client(api_key) + translate_client = translate.Client(api_key=api_key) # The text to translate text = u'Hello, world!' diff --git a/translate/cloud-client/snippets.py b/translate/cloud-client/snippets.py index bd8ab407136..8a2201b8100 100644 --- a/translate/cloud-client/snippets.py +++ b/translate/cloud-client/snippets.py @@ -73,9 +73,10 @@ def translate_text(api_key, target, text, model='base'): # Text can also be a sequence of strings, in which case this method # will return a sequence of results for each text. - result = translate_client.translate(text, - target_language=target, - model=model) + result = translate_client.translate( + text, + target_language=target, + model=model) print(u'Text: {}'.format(result['input'])) print(u'Translation: {}'.format(result['translatedText'])) From 0e77c55c87269677c3c470e7882ffd360adea443 Mon Sep 17 00:00:00 2001 From: Puneith Kaul Date: Mon, 14 Nov 2016 15:22:25 -0800 Subject: [PATCH 4/7] added BASE as constant --- translate/cloud-client/quickstart.py | 2 +- translate/cloud-client/snippets.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/translate/cloud-client/quickstart.py b/translate/cloud-client/quickstart.py index 5bb4a5085bb..bae6f50148d 100644 --- a/translate/cloud-client/quickstart.py +++ b/translate/cloud-client/quickstart.py @@ -32,7 +32,7 @@ def run_quickstart(): target = 'ru' # MT model type `base` or `nmt` - model = 'base' + model = translate.BASE # Translates some text into Russian translation = translate_client.translate( diff --git a/translate/cloud-client/snippets.py b/translate/cloud-client/snippets.py index 8a2201b8100..09047deae41 100644 --- a/translate/cloud-client/snippets.py +++ b/translate/cloud-client/snippets.py @@ -63,7 +63,7 @@ def list_languages_with_target(api_key, target): print(u'{name} ({language})'.format(**language)) -def translate_text(api_key, target, text, model='base'): +def translate_text(api_key, target, text, model=translate.BASE): """Translates text into the target language. Target must be an ISO 639-1 language code. From 4c528b20add6717bc1950b0a499a4ee6729fd909 Mon Sep 17 00:00:00 2001 From: Puneith Kaul Date: Mon, 14 Nov 2016 19:40:20 -0800 Subject: [PATCH 5/7] Update quickstart.py --- translate/cloud-client/quickstart.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/translate/cloud-client/quickstart.py b/translate/cloud-client/quickstart.py index bae6f50148d..664d1b16f4f 100644 --- a/translate/cloud-client/quickstart.py +++ b/translate/cloud-client/quickstart.py @@ -27,7 +27,7 @@ def run_quickstart(): translate_client = translate.Client(api_key=api_key) # The text to translate - text = u'Hello, world!' + text = u'Hello, world' # The target language target = 'ru' From 7e06066080e35a989ba870dd53eaa840316e9e49 Mon Sep 17 00:00:00 2001 From: Puneith Kaul Date: Mon, 14 Nov 2016 19:40:32 -0800 Subject: [PATCH 6/7] Update quickstart.py --- translate/cloud-client/quickstart.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/translate/cloud-client/quickstart.py b/translate/cloud-client/quickstart.py index 664d1b16f4f..bae6f50148d 100644 --- a/translate/cloud-client/quickstart.py +++ b/translate/cloud-client/quickstart.py @@ -27,7 +27,7 @@ def run_quickstart(): translate_client = translate.Client(api_key=api_key) # The text to translate - text = u'Hello, world' + text = u'Hello, world!' # The target language target = 'ru' From e529c82ba400fba33dbd0500355d8f0b3c46abf9 Mon Sep 17 00:00:00 2001 From: Puneith Kaul Date: Mon, 14 Nov 2016 21:11:18 -0800 Subject: [PATCH 7/7] changes to constructor translate client --- translate/cloud-client/requirements.txt | 2 +- translate/cloud-client/snippets.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/translate/cloud-client/requirements.txt b/translate/cloud-client/requirements.txt index 1f8e21a1a8d..ba0605c8fdc 100644 --- a/translate/cloud-client/requirements.txt +++ b/translate/cloud-client/requirements.txt @@ -1 +1 @@ -google-cloud-translate==0.20.0 +google-cloud-translate==0.21.0 diff --git a/translate/cloud-client/snippets.py b/translate/cloud-client/snippets.py index 09047deae41..dec8d172553 100644 --- a/translate/cloud-client/snippets.py +++ b/translate/cloud-client/snippets.py @@ -28,7 +28,7 @@ def detect_language(api_key, text): """Detects the text's language.""" - translate_client = translate.Client(api_key) + translate_client = translate.Client(api_key=api_key) # Text can also be a sequence of strings, in which case this method # will return a sequence of results for each text. @@ -41,7 +41,7 @@ def detect_language(api_key, text): def list_languages(api_key): """Lists all available languages.""" - translate_client = translate.Client(api_key) + translate_client = translate.Client(api_key=api_key) results = translate_client.get_languages() @@ -55,7 +55,7 @@ def list_languages_with_target(api_key, target): Target must be an ISO 639-1 language code. See https://g.co/cloud/translate/v2/translate-reference#supported_languages """ - translate_client = translate.Client(api_key) + translate_client = translate.Client(api_key=api_key) results = translate_client.get_languages(target_language=target) @@ -69,7 +69,7 @@ def translate_text(api_key, target, text, model=translate.BASE): Target must be an ISO 639-1 language code. See https://g.co/cloud/translate/v2/translate-reference#supported_languages """ - translate_client = translate.Client(api_key) + translate_client = translate.Client(api_key=api_key) # Text can also be a sequence of strings, in which case this method # will return a sequence of results for each text.