azure.ai.translation.document package¶
- class azure.ai.translation.document.DocumentTranslationApiVersion(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
Document Translation API versions supported by this package
- capitalize()¶
Return a capitalized version of the string.
More specifically, make the first character have upper case and the rest lower case.
- casefold()¶
Return a version of the string suitable for caseless comparisons.
- center(width, fillchar=' ', /)¶
Return a centered string of length width.
Padding is done using the specified fill character (default is a space).
- count(sub[, start[, end]]) int ¶
Return the number of non-overlapping occurrences of substring sub in string S[start:end]. Optional arguments start and end are interpreted as in slice notation.
- encode(encoding='utf-8', errors='strict')¶
Encode the string using the codec registered for encoding.
- encoding
The encoding in which to encode the string.
- errors
The error handling scheme to use for encoding errors. The default is ‘strict’ meaning that encoding errors raise a UnicodeEncodeError. Other possible values are ‘ignore’, ‘replace’ and ‘xmlcharrefreplace’ as well as any other name registered with codecs.register_error that can handle UnicodeEncodeErrors.
- endswith(suffix[, start[, end]]) bool ¶
Return True if S ends with the specified suffix, False otherwise. With optional start, test S beginning at that position. With optional end, stop comparing S at that position. suffix can also be a tuple of strings to try.
- expandtabs(tabsize=8)¶
Return a copy where all tab characters are expanded using spaces.
If tabsize is not given, a tab size of 8 characters is assumed.
- find(sub[, start[, end]]) int ¶
Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end]. Optional arguments start and end are interpreted as in slice notation.
Return -1 on failure.
- format(*args, **kwargs) str ¶
Return a formatted version of S, using substitutions from args and kwargs. The substitutions are identified by braces (‘{’ and ‘}’).
- format_map(mapping) str ¶
Return a formatted version of S, using substitutions from mapping. The substitutions are identified by braces (‘{’ and ‘}’).
- index(sub[, start[, end]]) int ¶
Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end]. Optional arguments start and end are interpreted as in slice notation.
Raises ValueError when the substring is not found.
- isalnum()¶
Return True if the string is an alpha-numeric string, False otherwise.
A string is alpha-numeric if all characters in the string are alpha-numeric and there is at least one character in the string.
- isalpha()¶
Return True if the string is an alphabetic string, False otherwise.
A string is alphabetic if all characters in the string are alphabetic and there is at least one character in the string.
- isascii()¶
Return True if all characters in the string are ASCII, False otherwise.
ASCII characters have code points in the range U+0000-U+007F. Empty string is ASCII too.
- isdecimal()¶
Return True if the string is a decimal string, False otherwise.
A string is a decimal string if all characters in the string are decimal and there is at least one character in the string.
- isdigit()¶
Return True if the string is a digit string, False otherwise.
A string is a digit string if all characters in the string are digits and there is at least one character in the string.
- isidentifier()¶
Return True if the string is a valid Python identifier, False otherwise.
Call keyword.iskeyword(s) to test whether string s is a reserved identifier, such as “def” or “class”.
- islower()¶
Return True if the string is a lowercase string, False otherwise.
A string is lowercase if all cased characters in the string are lowercase and there is at least one cased character in the string.
- isnumeric()¶
Return True if the string is a numeric string, False otherwise.
A string is numeric if all characters in the string are numeric and there is at least one character in the string.
- isprintable()¶
Return True if the string is printable, False otherwise.
A string is printable if all of its characters are considered printable in repr() or if it is empty.
- isspace()¶
Return True if the string is a whitespace string, False otherwise.
A string is whitespace if all characters in the string are whitespace and there is at least one character in the string.
- istitle()¶
Return True if the string is a title-cased string, False otherwise.
In a title-cased string, upper- and title-case characters may only follow uncased characters and lowercase characters only cased ones.
- isupper()¶
Return True if the string is an uppercase string, False otherwise.
A string is uppercase if all cased characters in the string are uppercase and there is at least one cased character in the string.
- join(iterable, /)¶
Concatenate any number of strings.
The string whose method is called is inserted in between each given string. The result is returned as a new string.
Example: ‘.’.join([‘ab’, ‘pq’, ‘rs’]) -> ‘ab.pq.rs’
- ljust(width, fillchar=' ', /)¶
Return a left-justified string of length width.
Padding is done using the specified fill character (default is a space).
- lower()¶
Return a copy of the string converted to lowercase.
- lstrip(chars=None, /)¶
Return a copy of the string with leading whitespace removed.
If chars is given and not None, remove characters in chars instead.
- static maketrans()¶
Return a translation table usable for str.translate().
If there is only one argument, it must be a dictionary mapping Unicode ordinals (integers) or characters to Unicode ordinals, strings or None. Character keys will be then converted to ordinals. If there are two arguments, they must be strings of equal length, and in the resulting dictionary, each character in x will be mapped to the character at the same position in y. If there is a third argument, it must be a string, whose characters will be mapped to None in the result.
- partition(sep, /)¶
Partition the string into three parts using the given separator.
This will search for the separator in the string. If the separator is found, returns a 3-tuple containing the part before the separator, the separator itself, and the part after it.
If the separator is not found, returns a 3-tuple containing the original string and two empty strings.
- removeprefix(prefix, /)¶
Return a str with the given prefix string removed if present.
If the string starts with the prefix string, return string[len(prefix):]. Otherwise, return a copy of the original string.
- removesuffix(suffix, /)¶
Return a str with the given suffix string removed if present.
If the string ends with the suffix string and that suffix is not empty, return string[:-len(suffix)]. Otherwise, return a copy of the original string.
- replace(old, new, count=-1, /)¶
Return a copy with all occurrences of substring old replaced by new.
- count
Maximum number of occurrences to replace. -1 (the default value) means replace all occurrences.
If the optional argument count is given, only the first count occurrences are replaced.
- rfind(sub[, start[, end]]) int ¶
Return the highest index in S where substring sub is found, such that sub is contained within S[start:end]. Optional arguments start and end are interpreted as in slice notation.
Return -1 on failure.
- rindex(sub[, start[, end]]) int ¶
Return the highest index in S where substring sub is found, such that sub is contained within S[start:end]. Optional arguments start and end are interpreted as in slice notation.
Raises ValueError when the substring is not found.
- rjust(width, fillchar=' ', /)¶
Return a right-justified string of length width.
Padding is done using the specified fill character (default is a space).
- rpartition(sep, /)¶
Partition the string into three parts using the given separator.
This will search for the separator in the string, starting at the end. If the separator is found, returns a 3-tuple containing the part before the separator, the separator itself, and the part after it.
If the separator is not found, returns a 3-tuple containing two empty strings and the original string.
- rsplit(sep=None, maxsplit=-1)¶
Return a list of the substrings in the string, using sep as the separator string.
- sep
The separator used to split the string.
When set to None (the default value), will split on any whitespace character (including n r t f and spaces) and will discard empty strings from the result.
- maxsplit
Maximum number of splits. -1 (the default value) means no limit.
Splitting starts at the end of the string and works to the front.
- rstrip(chars=None, /)¶
Return a copy of the string with trailing whitespace removed.
If chars is given and not None, remove characters in chars instead.
- split(sep=None, maxsplit=-1)¶
Return a list of the substrings in the string, using sep as the separator string.
- sep
The separator used to split the string.
When set to None (the default value), will split on any whitespace character (including n r t f and spaces) and will discard empty strings from the result.
- maxsplit
Maximum number of splits. -1 (the default value) means no limit.
Splitting starts at the front of the string and works to the end.
Note, str.split() is mainly useful for data that has been intentionally delimited. With natural text that includes punctuation, consider using the regular expression module.
- splitlines(keepends=False)¶
Return a list of the lines in the string, breaking at line boundaries.
Line breaks are not included in the resulting list unless keepends is given and true.
- startswith(prefix[, start[, end]]) bool ¶
Return True if S starts with the specified prefix, False otherwise. With optional start, test S beginning at that position. With optional end, stop comparing S at that position. prefix can also be a tuple of strings to try.
- strip(chars=None, /)¶
Return a copy of the string with leading and trailing whitespace removed.
If chars is given and not None, remove characters in chars instead.
- swapcase()¶
Convert uppercase characters to lowercase and lowercase characters to uppercase.
- title()¶
Return a version of the string where each word is titlecased.
More specifically, words start with uppercased characters and all remaining cased characters have lower case.
- translate(table, /)¶
Replace each character in the string using the given translation table.
- table
Translation table, which must be a mapping of Unicode ordinals to Unicode ordinals, strings, or None.
The table must implement lookup/indexing via __getitem__, for instance a dictionary or list. If this operation raises LookupError, the character is left untouched. Characters mapped to None are deleted.
- upper()¶
Return a copy of the string converted to uppercase.
- zfill(width, /)¶
Pad a numeric string with zeros on the left, to fill a field of the given width.
The string is never truncated.
- V2024_05_01 = '2024-05-01'¶
This is the default version
- class azure.ai.translation.document.DocumentTranslationClient(endpoint: str, credential: AzureKeyCredential | TokenCredential, **kwargs: Any)[source]¶
DocumentTranslationClient is your interface to the Document Translation service. Use the client to translate whole documents while preserving source document structure and text formatting.
- Parameters:
endpoint (str) – Supported Document Translation endpoint (protocol and hostname, for example: https://<resource-name>.cognitiveservices.azure.com/).
credential (
AzureKeyCredential
orTokenCredential
) – Credentials needed for the client to connect to Azure. This is an instance of AzureKeyCredential if using an API key or a token credential fromazure.identity
.
- Keyword Arguments:
api_version (str or DocumentTranslationApiVersion) – The API version of the service to use for requests. It defaults to the latest service version. Setting to an older version may result in reduced feature compatibility.
Example:
Creating the DocumentTranslationClient with an endpoint and API key.¶from azure.core.credentials import AzureKeyCredential from azure.ai.translation.document import DocumentTranslationClient endpoint = os.environ["AZURE_DOCUMENT_TRANSLATION_ENDPOINT"] key = os.environ["AZURE_DOCUMENT_TRANSLATION_KEY"] document_translation_client = DocumentTranslationClient(endpoint, AzureKeyCredential(key))
Creating the DocumentTranslationClient with a token credential.¶"""DefaultAzureCredential will use the values from these environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET """ from azure.identity import DefaultAzureCredential from azure.ai.translation.document import DocumentTranslationClient endpoint = os.environ["AZURE_DOCUMENT_TRANSLATION_ENDPOINT"] credential = DefaultAzureCredential() document_translation_client = DocumentTranslationClient(endpoint, credential)
- begin_translation(source_url: str, target_url: str, target_language: str, *, source_language: str | None = None, prefix: str | None = None, suffix: str | None = None, storage_type: str | StorageInputType | None = None, category_id: str | None = None, glossaries: List[TranslationGlossary] | None = None, **kwargs: Any) DocumentTranslationLROPoller[ItemPaged[DocumentStatus]] [source]¶
- begin_translation(inputs: StartTranslationDetails, **kwargs: Any) DocumentTranslationLROPoller[ItemPaged[DocumentStatus]]
- begin_translation(inputs: JSON, **kwargs: Any) DocumentTranslationLROPoller[ItemPaged[DocumentStatus]]
- begin_translation(inputs: IO[bytes], **kwargs: Any) DocumentTranslationLROPoller[ItemPaged[DocumentStatus]]
- begin_translation(inputs: List[DocumentTranslationInput], **kwargs: Any) DocumentTranslationLROPoller[ItemPaged[DocumentStatus]]
Begin translating the document(s) in your source container to your target container in the given language.
For supported languages and document formats, see the service documentation: https://docs.microsoft.com/azure/cognitive-services/translator/document-translation/overview
- Parameters:
inputs (List[DocumentTranslationInput] or IO[bytes] or JSON or StartTranslationDetails) – The translation inputs. Each individual input has a single source URL to documents and can contain multiple targets (one for each language) for the destination to write translated documents.
source_url (str) – The source SAS URL to the Azure Blob container containing the documents to be translated. See the service documentation for the supported SAS permissions for accessing source storage containers/blobs: https://aka.ms/azsdk/documenttranslation/sas-permissions
target_url (str) – The target SAS URL to the Azure Blob container where the translated documents should be written. See the service documentation for the supported SAS permissions for accessing target storage containers/blobs: https://aka.ms/azsdk/documenttranslation/sas-permissions
target_language (str) – This is the language code you want your documents to be translated to. See supported language codes here: https://docs.microsoft.com/azure/cognitive-services/translator/language-support#translate
- Keyword Arguments:
source_language (str) – Language code for the source documents. If none is specified, the source language will be auto-detected for each document.
prefix (str) – A case-sensitive prefix string to filter documents in the source path for translation. For example, when using a Azure storage blob Uri, use the prefix to restrict sub folders for translation.
suffix (str) – A case-sensitive suffix string to filter documents in the source path for translation. This is most often use for file extensions.
storage_type (str or StorageInputType) – Storage type of the input documents source string. Possible values include: “Folder”, “File”.
category_id (str) – Category / custom model ID for using custom translation.
glossaries (list[TranslationGlossary]) – Glossaries to apply to translation.
- Returns:
An instance of a DocumentTranslationLROPoller. Call result() on the poller object to return a pageable of DocumentStatus. A DocumentStatus will be returned for each translation on a document.
- Return type:
- Raises:
Example:
Translate the documents in your storage container.¶import os from azure.core.credentials import AzureKeyCredential from azure.ai.translation.document import DocumentTranslationClient endpoint = os.environ["AZURE_DOCUMENT_TRANSLATION_ENDPOINT"] key = os.environ["AZURE_DOCUMENT_TRANSLATION_KEY"] source_container_url = os.environ["AZURE_SOURCE_CONTAINER_URL"] target_container_url = os.environ["AZURE_TARGET_CONTAINER_URL"] client = DocumentTranslationClient(endpoint, AzureKeyCredential(key)) poller = client.begin_translation(source_container_url, target_container_url, "fr") result = poller.result() print(f"Status: {poller.status()}") print(f"Created on: {poller.details.created_on}") print(f"Last updated on: {poller.details.last_updated_on}") print(f"Total number of translations on documents: {poller.details.documents_total_count}") print("\nOf total documents...") print(f"{poller.details.documents_failed_count} failed") print(f"{poller.details.documents_succeeded_count} succeeded") for document in result: print(f"Document ID: {document.id}") print(f"Document status: {document.status}") if document.status == "Succeeded": print(f"Source document location: {document.source_document_url}") print(f"Translated document location: {document.translated_document_url}") print(f"Translated to language: {document.translated_to}\n") elif document.error: print(f"Error Code: {document.error.code}, Message: {document.error.message}\n")
- cancel_translation(translation_id: str, **kwargs: Any) None [source]¶
Cancel a currently processing or queued translation operation. A translation will not be canceled if it is already completed, failed, or canceling. All documents that have completed translation will not be canceled and will be charged. If possible, all pending documents will be canceled. :param str translation_id: The translation operation ID. :return: None :rtype: None :raises ~azure.core.exceptions.HttpResponseError or ~azure.core.exceptions.ResourceNotFoundError:
- close() None [source]¶
Close the
DocumentTranslationClient
session.
- get_document_status(translation_id: str, document_id: str, **kwargs: Any) DocumentStatus ¶
Returns the status for a specific document.
Returns the translation status for a specific document based on the request Id and document Id.
- Parameters:
- Returns:
DocumentStatus. The DocumentStatus is compatible with MutableMapping
- Return type:
- Raises:
- get_supported_document_formats(**kwargs: Any) List[DocumentTranslationFileFormat] [source]¶
Get the list of the document formats supported by the Document Translation service.
- Returns:
A list of supported document formats for translation.
- Return type:
- Raises:
- get_supported_glossary_formats(**kwargs: Any) List[DocumentTranslationFileFormat] [source]¶
Get the list of the glossary formats supported by the Document Translation service.
- Returns:
A list of supported glossary formats.
- Return type:
- Raises:
- get_translation_status(translation_id: str, **kwargs: Any) TranslationStatus ¶
Returns the status for a document translation request.
Returns the status for a document translation request. The status includes the overall request status, as well as the status for documents that are being translated as part of that request.
- Parameters:
translation_id (str) – Format - uuid. The operation id. Required.
- Returns:
TranslationStatus. The TranslationStatus is compatible with MutableMapping
- Return type:
- Raises:
- list_document_statuses(translation_id: str, *, top: int | None = None, skip: int | None = None, document_ids: List[str] | None = None, statuses: List[str] | None = None, created_after: str | datetime | None = None, created_before: str | datetime | None = None, order_by: List[str] | None = None, **kwargs: Any) ItemPaged[DocumentStatus] [source]¶
List all the document statuses for a given translation operation.
- Parameters:
translation_id (str) – ID of translation operation to list documents for.
- Keyword Arguments:
top (int) – The total number of documents to return (across all pages).
skip (int) – The number of documents to skip (from beginning). By default, we sort by all documents in descending order by start time.
statuses (list[str]) – Document statuses to filter by. Options include ‘NotStarted’, ‘Running’, ‘Succeeded’, ‘Failed’, ‘Canceled’, ‘Canceling’, and ‘ValidationFailed’.
created_after (str or datetime) – Get documents created after a certain datetime.
created_before (str or datetime) – Get documents created before a certain datetime.
order_by (list[str]) – The sorting query for the documents. Currently only ‘created_on’ is supported. format: [“param1 asc/desc”, “param2 asc/desc”, …] (ex: ‘created_on asc’, ‘created_on desc’).
- Returns:
A pageable of DocumentStatus.
- Return type:
- Raises:
Example:
List all the document statuses as they are being translated.¶import os import time from azure.core.credentials import AzureKeyCredential from azure.ai.translation.document import DocumentTranslationClient endpoint = os.environ["AZURE_DOCUMENT_TRANSLATION_ENDPOINT"] key = os.environ["AZURE_DOCUMENT_TRANSLATION_KEY"] source_container_url = os.environ["AZURE_SOURCE_CONTAINER_URL"] target_container_url = os.environ["AZURE_TARGET_CONTAINER_URL"] client = DocumentTranslationClient(endpoint, AzureKeyCredential(key)) poller = client.begin_translation(source_container_url, target_container_url, "es") completed_docs = [] while not poller.done(): time.sleep(30) doc_statuses = client.list_document_statuses(poller.id) for document in doc_statuses: if document.id not in completed_docs: if document.status == "Succeeded": print( f"Document at {document.source_document_url} was translated to {document.translated_to} " f"language. You can find translated document at {document.translated_document_url}" ) completed_docs.append(document.id) if document.status == "Failed" and document.error: print( f"Document at {document.source_document_url} failed translation. " f"Error Code: {document.error.code}, Message: {document.error.message}" ) completed_docs.append(document.id) if document.status == "Running": print( f"Document ID: {document.id}, translation progress is " f"{document.translation_progress * 100} percent" ) print("\nTranslation completed.")
- list_translation_statuses(*, top: int | None = None, skip: int | None = None, translation_ids: List[str] | None = None, statuses: List[str] | None = None, created_after: str | datetime | None = None, created_before: str | datetime | None = None, order_by: List[str] | None = None, **kwargs: Any) ItemPaged[TranslationStatus] [source]¶
List all the submitted translation operations under the Document Translation resource.
- Keyword Arguments:
top (int) – The total number of operations to return (across all pages) from all submitted translations.
skip (int) – The number of operations to skip (from beginning of all submitted operations). By default, we sort by all submitted operations in descending order by start time.
translation_ids (list[str]) – Translation operations ids to filter by.
statuses (list[str]) – Translation operation statuses to filter by. Options include ‘NotStarted’, ‘Running’, ‘Succeeded’, ‘Failed’, ‘Canceled’, ‘Canceling’, and ‘ValidationFailed’.
created_after (str or datetime) – Get operations created after a certain datetime.
created_before (str or datetime) – Get operations created before a certain datetime.
order_by (list[str]) – The sorting query for the operations returned. Currently only ‘created_on’ supported. format: [“param1 asc/desc”, “param2 asc/desc”, …] (ex: ‘created_on asc’, ‘created_on desc’).
- Returns:
A pageable of TranslationStatus.
- Return type:
- Raises:
Example:
List all submitted translations under the resource.¶from azure.core.credentials import AzureKeyCredential from azure.ai.translation.document import DocumentTranslationClient endpoint = os.environ["AZURE_DOCUMENT_TRANSLATION_ENDPOINT"] key = os.environ["AZURE_DOCUMENT_TRANSLATION_KEY"] client = DocumentTranslationClient(endpoint, AzureKeyCredential(key)) operations = client.list_translation_statuses() for operation in operations: print(f"ID: {operation.id}") print(f"Status: {operation.status}") print(f"Created on: {operation.created_on}") print(f"Last updated on: {operation.last_updated_on}") print(f"Total number of operations on documents: {operation.documents_total_count}") print(f"Total number of characters charged: {operation.total_characters_charged}") print("\nOf total documents...") print(f"{operation.documents_failed_count} failed") print(f"{operation.documents_succeeded_count} succeeded") print(f"{operation.documents_canceled_count} canceled\n")
- send_request(request: HttpRequest, *, stream: bool = False, **kwargs: Any) HttpResponse [source]¶
Runs the network request through the client’s chained policies.
>>> from azure.core.rest import HttpRequest >>> request = HttpRequest("GET", "https://www.example.org/") <HttpRequest [GET], url: 'https://www.example.org/'> >>> response = client.send_request(request) <HttpResponse: 200 OK>
For more information on this code flow, see https://aka.ms/azsdk/dpcodegen/python/send_request
- Parameters:
request (HttpRequest) – The network request you want to make. Required.
- Keyword Arguments:
stream (bool) – Whether the response payload will be streamed. Defaults to False.
- Returns:
The response of your network call. Does not do error handling on your response.
- Return type:
- class azure.ai.translation.document.DocumentTranslationLROPoller(client: Any, initial_response: Any, deserialization_callback: Callable[[Any], PollingReturnType_co], polling_method: PollingMethod[PollingReturnType_co])[source]¶
A custom poller implementation for Document Translation. Call result() on the poller to return a pageable of
DocumentStatus
.- add_done_callback(func: Callable) None ¶
Add callback function to be run once the long running operation has completed - regardless of the status of the operation.
- Parameters:
func (callable) – Callback function that takes at least one argument, a completed LongRunningOperation.
- continuation_token() str ¶
Return a continuation token that allows to restart the poller later.
- Returns:
An opaque continuation token
- Return type:
- done() bool ¶
Check status of the long running operation.
- Returns:
‘True’ if the process has completed, else ‘False’.
- Return type:
- polling_method() PollingMethod[PollingReturnType_co] ¶
Return the polling method associated to this poller.
- Returns:
The polling method
- Return type:
- remove_done_callback(func: Callable) None ¶
Remove a callback from the long running operation.
- Parameters:
func (callable) – The function to be removed from the callbacks.
- Raises:
ValueError – if the long running operation has already completed.
- result(timeout: float | None = None) PollingReturnType_co ¶
Return the result of the long running operation, or the result available after the specified timeout.
- Parameters:
timeout (float) – Period of time to wait before getting back control.
- Returns:
The deserialized resource of the long running operation, if one is available.
- Return type:
any or None
- Raises:
HttpResponseError – Server problem with the query.
- wait(timeout: float | None = None) None ¶
Wait on the long running operation for a specified length of time. You can check if this call as ended with timeout with the “done()” method.
- Parameters:
timeout (float) – Period of time to wait for the long running operation to complete (in seconds).
- Raises:
HttpResponseError – Server problem with the query.
- property details: TranslationStatus¶
The details for the translation operation
- Returns:
The details for the translation operation.
- Return type:
TranslationStatus
- class azure.ai.translation.document.SingleDocumentTranslationClient(endpoint: str, credential: AzureKeyCredential | TokenCredential, **kwargs: Any)[source]¶
SingleDocumentTranslationClient.
- Parameters:
endpoint (str) – Supported document Translation endpoint, protocol and hostname, for example: https://{TranslatorResourceName}.cognitiveservices.azure.com/translator. Required.
credential (AzureKeyCredential or TokenCredential) – Credential used to authenticate requests to the service. Is either a AzureKeyCredential type or a TokenCredential type. Required.
- Keyword Arguments:
api_version (str) – The API version to use for this operation. Default value is “2024-05-01”. Note that overriding this default value may result in unsupported behavior.
- send_request(request: HttpRequest, *, stream: bool = False, **kwargs: Any) HttpResponse [source]¶
Runs the network request through the client’s chained policies.
>>> from azure.core.rest import HttpRequest >>> request = HttpRequest("GET", "https://www.example.org/") <HttpRequest [GET], url: 'https://www.example.org/'> >>> response = client.send_request(request) <HttpResponse: 200 OK>
For more information on this code flow, see https://aka.ms/azsdk/dpcodegen/python/send_request
- Parameters:
request (HttpRequest) – The network request you want to make. Required.
- Keyword Arguments:
stream (bool) – Whether the response payload will be streamed. Defaults to False.
- Returns:
The response of your network call. Does not do error handling on your response.
- Return type:
- translate(body: DocumentTranslateContent | MutableMapping[str, Any], *, target_language: str, source_language: str | None = None, category: str | None = None, allow_fallback: bool | None = None, **kwargs: Any) Iterator[bytes] ¶
Submit a single document translation request to the Document Translation service.
Use this API to submit a single translation request to the Document Translation Service.
- Parameters:
body (DocumentTranslateContent or JSON) – Is either a DocumentTranslateContent type or a JSON type. Required.
- Keyword Arguments:
target_language (str) – Specifies the language of the output document. The target language must be one of the supported languages included in the translation scope. For example if you want to translate the document in German language, then use targetLanguage=de. Required.
source_language (str) – Specifies source language of the input document. If this parameter isn’t specified, automatic language detection is applied to determine the source language. For example if the source document is written in English, then use sourceLanguage=en. Default value is None.
category (str) – A string specifying the category (domain) of the translation. This parameter is used to get translations from a customized system built with Custom Translator. Add the Category ID from your Custom Translator project details to this parameter to use your deployed customized system. Default value is: general. Default value is None.
allow_fallback (bool) – Specifies that the service is allowed to fall back to a general system when a custom system doesn’t exist. Possible values are: true (default) or false. Default value is None.
- Returns:
Iterator[bytes]
- Return type:
Iterator[bytes]
- Raises:
Example
# JSON input template you can fill out and use as your body input. body = { "document": filetype, "glossary": [filetype] }
Subpackages¶
- azure.ai.translation.document.aio package
AsyncDocumentTranslationLROPoller
AsyncDocumentTranslationLROPoller.continuation_token()
AsyncDocumentTranslationLROPoller.done()
AsyncDocumentTranslationLROPoller.polling_method()
AsyncDocumentTranslationLROPoller.result()
AsyncDocumentTranslationLROPoller.status()
AsyncDocumentTranslationLROPoller.wait()
AsyncDocumentTranslationLROPoller.details
AsyncDocumentTranslationLROPoller.id
DocumentTranslationClient
DocumentTranslationClient.begin_translation()
DocumentTranslationClient.cancel_translation()
DocumentTranslationClient.close()
DocumentTranslationClient.get_document_status()
DocumentTranslationClient.get_supported_document_formats()
DocumentTranslationClient.get_supported_glossary_formats()
DocumentTranslationClient.get_translation_status()
DocumentTranslationClient.list_document_statuses()
DocumentTranslationClient.list_translation_statuses()
DocumentTranslationClient.send_request()
SingleDocumentTranslationClient
- azure.ai.translation.document.models package
DocumentBatch
DocumentBatch.as_dict()
DocumentBatch.clear()
DocumentBatch.copy()
DocumentBatch.get()
DocumentBatch.items()
DocumentBatch.keys()
DocumentBatch.pop()
DocumentBatch.popitem()
DocumentBatch.setdefault()
DocumentBatch.update()
DocumentBatch.values()
DocumentBatch.source
DocumentBatch.storage_type
DocumentBatch.targets
DocumentFilter
DocumentFilter.as_dict()
DocumentFilter.clear()
DocumentFilter.copy()
DocumentFilter.get()
DocumentFilter.items()
DocumentFilter.keys()
DocumentFilter.pop()
DocumentFilter.popitem()
DocumentFilter.setdefault()
DocumentFilter.update()
DocumentFilter.values()
DocumentFilter.prefix
DocumentFilter.suffix
DocumentStatus
DocumentStatus.as_dict()
DocumentStatus.clear()
DocumentStatus.copy()
DocumentStatus.get()
DocumentStatus.items()
DocumentStatus.keys()
DocumentStatus.pop()
DocumentStatus.popitem()
DocumentStatus.setdefault()
DocumentStatus.update()
DocumentStatus.values()
DocumentStatus.characters_charged
DocumentStatus.created_on
DocumentStatus.error
DocumentStatus.id
DocumentStatus.last_updated_on
DocumentStatus.source_document_url
DocumentStatus.status
DocumentStatus.translated_document_url
DocumentStatus.translated_to
DocumentStatus.translation_progress
DocumentTranslateContent
DocumentTranslateContent.as_dict()
DocumentTranslateContent.clear()
DocumentTranslateContent.copy()
DocumentTranslateContent.get()
DocumentTranslateContent.items()
DocumentTranslateContent.keys()
DocumentTranslateContent.pop()
DocumentTranslateContent.popitem()
DocumentTranslateContent.setdefault()
DocumentTranslateContent.update()
DocumentTranslateContent.values()
DocumentTranslateContent.document
DocumentTranslateContent.glossary
DocumentTranslationError
DocumentTranslationError.as_dict()
DocumentTranslationError.clear()
DocumentTranslationError.copy()
DocumentTranslationError.get()
DocumentTranslationError.items()
DocumentTranslationError.keys()
DocumentTranslationError.pop()
DocumentTranslationError.popitem()
DocumentTranslationError.setdefault()
DocumentTranslationError.update()
DocumentTranslationError.values()
DocumentTranslationError.code
DocumentTranslationError.inner_error
DocumentTranslationError.message
DocumentTranslationError.target
DocumentTranslationFileFormat
DocumentTranslationFileFormat.as_dict()
DocumentTranslationFileFormat.clear()
DocumentTranslationFileFormat.copy()
DocumentTranslationFileFormat.get()
DocumentTranslationFileFormat.items()
DocumentTranslationFileFormat.keys()
DocumentTranslationFileFormat.pop()
DocumentTranslationFileFormat.popitem()
DocumentTranslationFileFormat.setdefault()
DocumentTranslationFileFormat.update()
DocumentTranslationFileFormat.values()
DocumentTranslationFileFormat.content_types
DocumentTranslationFileFormat.default_format_version
DocumentTranslationFileFormat.file_extensions
DocumentTranslationFileFormat.file_format
DocumentTranslationFileFormat.format_versions
DocumentTranslationFileFormat.type
DocumentTranslationInput
FileFormatType
FileFormatType.capitalize()
FileFormatType.casefold()
FileFormatType.center()
FileFormatType.count()
FileFormatType.encode()
FileFormatType.endswith()
FileFormatType.expandtabs()
FileFormatType.find()
FileFormatType.format()
FileFormatType.format_map()
FileFormatType.index()
FileFormatType.isalnum()
FileFormatType.isalpha()
FileFormatType.isascii()
FileFormatType.isdecimal()
FileFormatType.isdigit()
FileFormatType.isidentifier()
FileFormatType.islower()
FileFormatType.isnumeric()
FileFormatType.isprintable()
FileFormatType.isspace()
FileFormatType.istitle()
FileFormatType.isupper()
FileFormatType.join()
FileFormatType.ljust()
FileFormatType.lower()
FileFormatType.lstrip()
FileFormatType.maketrans()
FileFormatType.partition()
FileFormatType.removeprefix()
FileFormatType.removesuffix()
FileFormatType.replace()
FileFormatType.rfind()
FileFormatType.rindex()
FileFormatType.rjust()
FileFormatType.rpartition()
FileFormatType.rsplit()
FileFormatType.rstrip()
FileFormatType.split()
FileFormatType.splitlines()
FileFormatType.startswith()
FileFormatType.strip()
FileFormatType.swapcase()
FileFormatType.title()
FileFormatType.translate()
FileFormatType.upper()
FileFormatType.zfill()
FileFormatType.DOCUMENT
FileFormatType.GLOSSARY
InnerTranslationError
InnerTranslationError.as_dict()
InnerTranslationError.clear()
InnerTranslationError.copy()
InnerTranslationError.get()
InnerTranslationError.items()
InnerTranslationError.keys()
InnerTranslationError.pop()
InnerTranslationError.popitem()
InnerTranslationError.setdefault()
InnerTranslationError.update()
InnerTranslationError.values()
InnerTranslationError.code
InnerTranslationError.inner_error
InnerTranslationError.message
InnerTranslationError.target
SourceInput
SourceInput.as_dict()
SourceInput.clear()
SourceInput.copy()
SourceInput.get()
SourceInput.items()
SourceInput.keys()
SourceInput.pop()
SourceInput.popitem()
SourceInput.setdefault()
SourceInput.update()
SourceInput.values()
SourceInput.filter
SourceInput.language
SourceInput.source_url
SourceInput.storage_source
StartTranslationDetails
StartTranslationDetails.as_dict()
StartTranslationDetails.clear()
StartTranslationDetails.copy()
StartTranslationDetails.get()
StartTranslationDetails.items()
StartTranslationDetails.keys()
StartTranslationDetails.pop()
StartTranslationDetails.popitem()
StartTranslationDetails.setdefault()
StartTranslationDetails.update()
StartTranslationDetails.values()
StartTranslationDetails.inputs
Status
Status.capitalize()
Status.casefold()
Status.center()
Status.count()
Status.encode()
Status.endswith()
Status.expandtabs()
Status.find()
Status.format()
Status.format_map()
Status.index()
Status.isalnum()
Status.isalpha()
Status.isascii()
Status.isdecimal()
Status.isdigit()
Status.isidentifier()
Status.islower()
Status.isnumeric()
Status.isprintable()
Status.isspace()
Status.istitle()
Status.isupper()
Status.join()
Status.ljust()
Status.lower()
Status.lstrip()
Status.maketrans()
Status.partition()
Status.removeprefix()
Status.removesuffix()
Status.replace()
Status.rfind()
Status.rindex()
Status.rjust()
Status.rpartition()
Status.rsplit()
Status.rstrip()
Status.split()
Status.splitlines()
Status.startswith()
Status.strip()
Status.swapcase()
Status.title()
Status.translate()
Status.upper()
Status.zfill()
Status.CANCELED
Status.CANCELING
Status.FAILED
Status.NOT_STARTED
Status.RUNNING
Status.SUCCEEDED
Status.VALIDATION_FAILED
StorageInputType
StorageInputType.capitalize()
StorageInputType.casefold()
StorageInputType.center()
StorageInputType.count()
StorageInputType.encode()
StorageInputType.endswith()
StorageInputType.expandtabs()
StorageInputType.find()
StorageInputType.format()
StorageInputType.format_map()
StorageInputType.index()
StorageInputType.isalnum()
StorageInputType.isalpha()
StorageInputType.isascii()
StorageInputType.isdecimal()
StorageInputType.isdigit()
StorageInputType.isidentifier()
StorageInputType.islower()
StorageInputType.isnumeric()
StorageInputType.isprintable()
StorageInputType.isspace()
StorageInputType.istitle()
StorageInputType.isupper()
StorageInputType.join()
StorageInputType.ljust()
StorageInputType.lower()
StorageInputType.lstrip()
StorageInputType.maketrans()
StorageInputType.partition()
StorageInputType.removeprefix()
StorageInputType.removesuffix()
StorageInputType.replace()
StorageInputType.rfind()
StorageInputType.rindex()
StorageInputType.rjust()
StorageInputType.rpartition()
StorageInputType.rsplit()
StorageInputType.rstrip()
StorageInputType.split()
StorageInputType.splitlines()
StorageInputType.startswith()
StorageInputType.strip()
StorageInputType.swapcase()
StorageInputType.title()
StorageInputType.translate()
StorageInputType.upper()
StorageInputType.zfill()
StorageInputType.FILE
StorageInputType.FOLDER
TranslationErrorCode
TranslationErrorCode.capitalize()
TranslationErrorCode.casefold()
TranslationErrorCode.center()
TranslationErrorCode.count()
TranslationErrorCode.encode()
TranslationErrorCode.endswith()
TranslationErrorCode.expandtabs()
TranslationErrorCode.find()
TranslationErrorCode.format()
TranslationErrorCode.format_map()
TranslationErrorCode.index()
TranslationErrorCode.isalnum()
TranslationErrorCode.isalpha()
TranslationErrorCode.isascii()
TranslationErrorCode.isdecimal()
TranslationErrorCode.isdigit()
TranslationErrorCode.isidentifier()
TranslationErrorCode.islower()
TranslationErrorCode.isnumeric()
TranslationErrorCode.isprintable()
TranslationErrorCode.isspace()
TranslationErrorCode.istitle()
TranslationErrorCode.isupper()
TranslationErrorCode.join()
TranslationErrorCode.ljust()
TranslationErrorCode.lower()
TranslationErrorCode.lstrip()
TranslationErrorCode.maketrans()
TranslationErrorCode.partition()
TranslationErrorCode.removeprefix()
TranslationErrorCode.removesuffix()
TranslationErrorCode.replace()
TranslationErrorCode.rfind()
TranslationErrorCode.rindex()
TranslationErrorCode.rjust()
TranslationErrorCode.rpartition()
TranslationErrorCode.rsplit()
TranslationErrorCode.rstrip()
TranslationErrorCode.split()
TranslationErrorCode.splitlines()
TranslationErrorCode.startswith()
TranslationErrorCode.strip()
TranslationErrorCode.swapcase()
TranslationErrorCode.title()
TranslationErrorCode.translate()
TranslationErrorCode.upper()
TranslationErrorCode.zfill()
TranslationErrorCode.INTERNAL_SERVER_ERROR
TranslationErrorCode.INVALID_ARGUMENT
TranslationErrorCode.INVALID_REQUEST
TranslationErrorCode.REQUEST_RATE_TOO_HIGH
TranslationErrorCode.RESOURCE_NOT_FOUND
TranslationErrorCode.SERVICE_UNAVAILABLE
TranslationErrorCode.UNAUTHORIZED
TranslationGlossary
TranslationGlossary.as_dict()
TranslationGlossary.clear()
TranslationGlossary.copy()
TranslationGlossary.get()
TranslationGlossary.items()
TranslationGlossary.keys()
TranslationGlossary.pop()
TranslationGlossary.popitem()
TranslationGlossary.setdefault()
TranslationGlossary.update()
TranslationGlossary.values()
TranslationGlossary.file_format
TranslationGlossary.format_version
TranslationGlossary.glossary_url
TranslationGlossary.storage_source
TranslationStatus
TranslationStatus.as_dict()
TranslationStatus.clear()
TranslationStatus.copy()
TranslationStatus.get()
TranslationStatus.items()
TranslationStatus.keys()
TranslationStatus.pop()
TranslationStatus.popitem()
TranslationStatus.setdefault()
TranslationStatus.update()
TranslationStatus.values()
TranslationStatus.created_on
TranslationStatus.error
TranslationStatus.id
TranslationStatus.last_updated_on
TranslationStatus.status
TranslationStatus.summary
TranslationStatusSummary
TranslationStatusSummary.as_dict()
TranslationStatusSummary.clear()
TranslationStatusSummary.copy()
TranslationStatusSummary.get()
TranslationStatusSummary.items()
TranslationStatusSummary.keys()
TranslationStatusSummary.pop()
TranslationStatusSummary.popitem()
TranslationStatusSummary.setdefault()
TranslationStatusSummary.update()
TranslationStatusSummary.values()
TranslationStatusSummary.canceled
TranslationStatusSummary.failed
TranslationStatusSummary.in_progress
TranslationStatusSummary.not_yet_started
TranslationStatusSummary.success
TranslationStatusSummary.total
TranslationStatusSummary.total_characters_charged
TranslationStorageSource
TranslationStorageSource.capitalize()
TranslationStorageSource.casefold()
TranslationStorageSource.center()
TranslationStorageSource.count()
TranslationStorageSource.encode()
TranslationStorageSource.endswith()
TranslationStorageSource.expandtabs()
TranslationStorageSource.find()
TranslationStorageSource.format()
TranslationStorageSource.format_map()
TranslationStorageSource.index()
TranslationStorageSource.isalnum()
TranslationStorageSource.isalpha()
TranslationStorageSource.isascii()
TranslationStorageSource.isdecimal()
TranslationStorageSource.isdigit()
TranslationStorageSource.isidentifier()
TranslationStorageSource.islower()
TranslationStorageSource.isnumeric()
TranslationStorageSource.isprintable()
TranslationStorageSource.isspace()
TranslationStorageSource.istitle()
TranslationStorageSource.isupper()
TranslationStorageSource.join()
TranslationStorageSource.ljust()
TranslationStorageSource.lower()
TranslationStorageSource.lstrip()
TranslationStorageSource.maketrans()
TranslationStorageSource.partition()
TranslationStorageSource.removeprefix()
TranslationStorageSource.removesuffix()
TranslationStorageSource.replace()
TranslationStorageSource.rfind()
TranslationStorageSource.rindex()
TranslationStorageSource.rjust()
TranslationStorageSource.rpartition()
TranslationStorageSource.rsplit()
TranslationStorageSource.rstrip()
TranslationStorageSource.split()
TranslationStorageSource.splitlines()
TranslationStorageSource.startswith()
TranslationStorageSource.strip()
TranslationStorageSource.swapcase()
TranslationStorageSource.title()
TranslationStorageSource.translate()
TranslationStorageSource.upper()
TranslationStorageSource.zfill()
TranslationStorageSource.AZURE_BLOB
TranslationTarget
TranslationTarget.as_dict()
TranslationTarget.clear()
TranslationTarget.copy()
TranslationTarget.get()
TranslationTarget.items()
TranslationTarget.keys()
TranslationTarget.pop()
TranslationTarget.popitem()
TranslationTarget.setdefault()
TranslationTarget.update()
TranslationTarget.values()
TranslationTarget.category_id
TranslationTarget.glossaries
TranslationTarget.language
TranslationTarget.storage_source
TranslationTarget.target_url