From 0c333d298e5ed572fe64f2345508be20b60f1ebc Mon Sep 17 00:00:00 2001 From: Puneith Kaul Date: Sun, 13 Nov 2016 15:20:30 -0800 Subject: [PATCH 1/3] 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 51ab697c8f0a..c8ae8fe25581 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 1b5cad92ac3a..bd8ab407136b 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 1d42040027d33bca13df1a5bfc8185ce31fc5f12 Mon Sep 17 00:00:00 2001 From: Puneith Kaul Date: Mon, 14 Nov 2016 10:28:04 -0800 Subject: [PATCH 2/3] 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 c8ae8fe25581..6aeebe2974f7 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 dd92bb7bf998ce0c17dd1eb77eb15fd4fc59371c Mon Sep 17 00:00:00 2001 From: Puneith Kaul Date: Mon, 14 Nov 2016 11:10:36 -0800 Subject: [PATCH 3/3] 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 6aeebe2974f7..5bb4a5085bb9 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 bd8ab407136b..8a2201b8100a 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']))