@@ -64,7 +64,7 @@ With the value of the `endpoint`, `credential` and a `region`, you can create th
64
64
65
65
``` python
66
66
credential = TranslatorCredential(apikey, region)
67
- text_translator = TextTranslationClient(credential, endpoint = endpoint)
67
+ text_translator = TextTranslationClient(credential = credential , endpoint = endpoint)
68
68
```
69
69
70
70
<!-- END SNIPPET -->
@@ -141,7 +141,7 @@ Renders single source-language text to multiple target-language texts with a sin
141
141
``` python
142
142
try :
143
143
target_languages = [" cs" , " es" , " de" ]
144
- input_text_elements = [InputTextItem( text = " This is a test" ) ]
144
+ input_text_elements = [" This is a test" ]
145
145
146
146
response = text_translator.translate(request_body = input_text_elements, to = target_languages)
147
147
translation = response[0 ] if response else None
156
156
print (f " Text was translated to: ' { translated_text.to} ' and the result is: ' { translated_text.text} '. " )
157
157
158
158
except HttpResponseError as exception:
159
- print (f " Error Code: { exception.error.code} " )
160
- print (f " Message: { exception.error.message} " )
159
+ if exception.error is not None :
160
+ print (f " Error Code: { exception.error.code} " )
161
+ print (f " Message: { exception.error.message} " )
161
162
```
162
163
163
164
<!-- END SNIPPET -->
178
179
language = " zh-Hans"
179
180
from_script = " Hans"
180
181
to_script = " Latn"
181
- input_text_elements = [InputTextItem( text = " 这是个测试。" ) ]
182
+ input_text_elements = [" 这是个测试。" ]
182
183
183
184
response = text_translator.transliterate(
184
185
request_body = input_text_elements, language = language, from_script = from_script, to_script = to_script
@@ -212,7 +213,7 @@ Identifies the positioning of sentence boundaries in a piece of text.
212
213
try :
213
214
include_sentence_length = True
214
215
target_languages = [" cs" ]
215
- input_text_elements = [InputTextItem( text = " The answer lies in machine translation. This is a test." ) ]
216
+ input_text_elements = [" The answer lies in machine translation. This is a test." ]
216
217
217
218
response = text_translator.translate(
218
219
request_body = input_text_elements, to = target_languages, include_sentence_length = include_sentence_length
232
233
print (f " Translated Sentence length: { translated_text.sent_len.trans_sent_len} " )
233
234
234
235
except HttpResponseError as exception:
235
- print (f " Error Code: { exception.error.code} " )
236
- print (f " Message: { exception.error.message} " )
236
+ if exception.error is not None :
237
+ print (f " Error Code: { exception.error.code} " )
238
+ print (f " Message: { exception.error.message} " )
237
239
```
238
240
239
241
<!-- END SNIPPET -->
@@ -252,7 +254,7 @@ Returns equivalent words for the source term in the target language.
252
254
try :
253
255
source_language = " en"
254
256
target_language = " es"
255
- input_text_elements = [InputTextItem( text = " fly" ) ]
257
+ input_text_elements = [" fly" ]
256
258
257
259
response = text_translator.lookup_dictionary_entries(
258
260
request_body = input_text_elements, from_parameter = source_language, to = target_language
0 commit comments