Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a method for using the TranslateArray2() #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,47 @@ def translate_array(self, texts, to_lang, from_lang=None, **options):
params['from'] = from_lang

return self.call("TranslateArray", params)

def translate_array_alignment(self, texts, to_lang, from_lang=None, **options):
"""Works just like regular TranslateArray(), except it has an additional
element in the response structure, called "Alignment".

:param texts: A list containing texts for translation.
:param to_lang: A string representing the language code to
translate the text into.
:param from_lang: A string representing the language code of the
translation text. If left None the response will include the
result of language auto-detection. (Default: None)
:param options: A TranslateOptions element containing the values below.
They are all optional and default to the most common settings.

Category: A string containing the category (domain) of the
translation. Defaults to "general".
ContentType: The format of the text being translated. The
supported formats are "text/plain" and "text/html". Any
HTML needs to be well-formed.
Uri: A string containing the content location of this
translation.
User: A string used to track the originator of the submission.
State: User state to help correlate request and response. The
same contents will be returned in the response.
"""
options = {
'Category': "general",
'Contenttype': "text/plain",
'Uri': '',
'User': 'default',
'State': ''
}.update(options)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is prone to #27 too.

params = {
'texts': json.dumps(texts),
'to': to_lang,
'options': json.dumps(options),
}
if from_lang is not None:
params['from'] = from_lang

return self.call("TranslateArray2", params)

def get_languages(self):
"""Fetches the languages supported by Microsoft Translator
Expand Down