Partilhar via


TextTranslationClient.TranslateAsync Method

Definition

Overloads

TranslateAsync(TextTranslationTranslateOptions, CancellationToken)

Translate Text.

TranslateAsync(String, IEnumerable<String>, String, CancellationToken)

Translate Text.

TranslateAsync(String, String, String, CancellationToken)

Translate Text.

TranslateAsync(IEnumerable<String>, IEnumerable<String>, Guid, String, Nullable<TextType>, String, Nullable<ProfanityAction>, Nullable<ProfanityMarker>, Nullable<Boolean>, Nullable<Boolean>, String, String, String, Nullable<Boolean>, CancellationToken)

Translate Text.

TranslateAsync(IEnumerable<String>, IEnumerable<String>, String, String, Nullable<TextType>, String, Nullable<ProfanityAction>, Nullable<ProfanityMarker>, Nullable<Boolean>, Nullable<Boolean>, String, String, String, Nullable<Boolean>, CancellationToken)

Translate Text.

TranslateAsync(TextTranslationTranslateOptions, CancellationToken)

Source:
TextTranslationClient.cs

Translate Text.

public virtual System.Threading.Tasks.Task<Azure.Response<System.Collections.Generic.IReadOnlyList<Azure.AI.Translation.Text.TranslatedTextItem>>> TranslateAsync (Azure.AI.Translation.Text.TextTranslationTranslateOptions options, System.Threading.CancellationToken cancellationToken = default);
abstract member TranslateAsync : Azure.AI.Translation.Text.TextTranslationTranslateOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Response<System.Collections.Generic.IReadOnlyList<Azure.AI.Translation.Text.TranslatedTextItem>>>
override this.TranslateAsync : Azure.AI.Translation.Text.TextTranslationTranslateOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Response<System.Collections.Generic.IReadOnlyList<Azure.AI.Translation.Text.TranslatedTextItem>>>
Public Overridable Function TranslateAsync (options As TextTranslationTranslateOptions, Optional cancellationToken As CancellationToken = Nothing) As Task(Of Response(Of IReadOnlyList(Of TranslatedTextItem)))

Parameters

options
TextTranslationTranslateOptions

The client translation options.

cancellationToken
CancellationToken

The cancellation token to use.

Returns

Exceptions

options is null.

Applies to

TranslateAsync(String, IEnumerable<String>, String, CancellationToken)

Source:
TextTranslationClient.cs
Source:
TextTranslationClient.cs

Translate Text.

public virtual System.Threading.Tasks.Task<Azure.Response<System.Collections.Generic.IReadOnlyList<Azure.AI.Translation.Text.TranslatedTextItem>>> TranslateAsync (string targetLanguage, System.Collections.Generic.IEnumerable<string> content, string sourceLanguage = default, System.Threading.CancellationToken cancellationToken = default);
abstract member TranslateAsync : string * seq<string> * string * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Response<System.Collections.Generic.IReadOnlyList<Azure.AI.Translation.Text.TranslatedTextItem>>>
override this.TranslateAsync : string * seq<string> * string * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Response<System.Collections.Generic.IReadOnlyList<Azure.AI.Translation.Text.TranslatedTextItem>>>
Public Overridable Function TranslateAsync (targetLanguage As String, content As IEnumerable(Of String), Optional sourceLanguage As String = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of Response(Of IReadOnlyList(Of TranslatedTextItem)))

Parameters

targetLanguage
String

Specifies the language of the output text. The target language must be one of the supported languages included in the translation scope. For example, use to=de to translate to German. It's possible to translate to multiple languages simultaneously by repeating the parameter in the query string. For example, use to=de&to=it to translate to German and Italian.

content
IEnumerable<String>

Array of the text to be translated.

sourceLanguage
String

Specifies the language of the input text. Find which languages are available to translate from by looking up supported languages using the translation scope. If the from parameter isn't specified, automatic language detection is applied to determine the source language.

You must use the from parameter rather than autodetection when using the dynamic dictionary feature. Note: the dynamic dictionary feature is case-sensitive.

cancellationToken
CancellationToken

The cancellation token to use.

Returns

Exceptions

targetLanguage or content is null.

Applies to

TranslateAsync(String, String, String, CancellationToken)

Source:
TextTranslationClient.cs
Source:
TextTranslationClient.cs

Translate Text.

public virtual System.Threading.Tasks.Task<Azure.Response<System.Collections.Generic.IReadOnlyList<Azure.AI.Translation.Text.TranslatedTextItem>>> TranslateAsync (string targetLanguage, string text, string sourceLanguage = default, System.Threading.CancellationToken cancellationToken = default);
abstract member TranslateAsync : string * string * string * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Response<System.Collections.Generic.IReadOnlyList<Azure.AI.Translation.Text.TranslatedTextItem>>>
override this.TranslateAsync : string * string * string * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Response<System.Collections.Generic.IReadOnlyList<Azure.AI.Translation.Text.TranslatedTextItem>>>
Public Overridable Function TranslateAsync (targetLanguage As String, text As String, Optional sourceLanguage As String = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of Response(Of IReadOnlyList(Of TranslatedTextItem)))

Parameters

targetLanguage
String

Specifies the language of the output text. The target language must be one of the supported languages included in the translation scope. For example, use to=de to translate to German. It's possible to translate to multiple languages simultaneously by repeating the parameter in the query string. For example, use to=de&to=it to translate to German and Italian.

text
String

Text to be translated.

sourceLanguage
String

Specifies the language of the input text. Find which languages are available to translate from by looking up supported languages using the translation scope. If the from parameter isn't specified, automatic language detection is applied to determine the source language.

You must use the from parameter rather than autodetection when using the dynamic dictionary feature. Note: the dynamic dictionary feature is case-sensitive.

cancellationToken
CancellationToken

The cancellation token to use.

Returns

Exceptions

targetLanguage or text is null.

Applies to

TranslateAsync(IEnumerable<String>, IEnumerable<String>, Guid, String, Nullable<TextType>, String, Nullable<ProfanityAction>, Nullable<ProfanityMarker>, Nullable<Boolean>, Nullable<Boolean>, String, String, String, Nullable<Boolean>, CancellationToken)

Source:
TextTranslationClient.cs

Translate Text.

public virtual System.Threading.Tasks.Task<Azure.Response<System.Collections.Generic.IReadOnlyList<Azure.AI.Translation.Text.TranslatedTextItem>>> TranslateAsync (System.Collections.Generic.IEnumerable<string> targetLanguages, System.Collections.Generic.IEnumerable<string> content, Guid clientTraceId = default, string sourceLanguage = default, Azure.AI.Translation.Text.TextType? textType = default, string category = default, Azure.AI.Translation.Text.ProfanityAction? profanityAction = default, Azure.AI.Translation.Text.ProfanityMarker? profanityMarker = default, bool? includeAlignment = default, bool? includeSentenceLength = default, string suggestedFrom = default, string fromScript = default, string toScript = default, bool? allowFallback = default, System.Threading.CancellationToken cancellationToken = default);
abstract member TranslateAsync : seq<string> * seq<string> * Guid * string * Nullable<Azure.AI.Translation.Text.TextType> * string * Nullable<Azure.AI.Translation.Text.ProfanityAction> * Nullable<Azure.AI.Translation.Text.ProfanityMarker> * Nullable<bool> * Nullable<bool> * string * string * string * Nullable<bool> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Response<System.Collections.Generic.IReadOnlyList<Azure.AI.Translation.Text.TranslatedTextItem>>>
override this.TranslateAsync : seq<string> * seq<string> * Guid * string * Nullable<Azure.AI.Translation.Text.TextType> * string * Nullable<Azure.AI.Translation.Text.ProfanityAction> * Nullable<Azure.AI.Translation.Text.ProfanityMarker> * Nullable<bool> * Nullable<bool> * string * string * string * Nullable<bool> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Response<System.Collections.Generic.IReadOnlyList<Azure.AI.Translation.Text.TranslatedTextItem>>>
Public Overridable Function TranslateAsync (targetLanguages As IEnumerable(Of String), content As IEnumerable(Of String), Optional clientTraceId As Guid = Nothing, Optional sourceLanguage As String = Nothing, Optional textType As Nullable(Of TextType) = Nothing, Optional category As String = Nothing, Optional profanityAction As Nullable(Of ProfanityAction) = Nothing, Optional profanityMarker As Nullable(Of ProfanityMarker) = Nothing, Optional includeAlignment As Nullable(Of Boolean) = Nothing, Optional includeSentenceLength As Nullable(Of Boolean) = Nothing, Optional suggestedFrom As String = Nothing, Optional fromScript As String = Nothing, Optional toScript As String = Nothing, Optional allowFallback As Nullable(Of Boolean) = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of Response(Of IReadOnlyList(Of TranslatedTextItem)))

Parameters

targetLanguages
IEnumerable<String>

Specifies the language of the output text. The target language must be one of the supported languages included in the translation scope. For example, use to=de to translate to German. It's possible to translate to multiple languages simultaneously by repeating the parameter in the query string. For example, use to=de&to=it to translate to German and Italian.

content
IEnumerable<String>

Array of the text to be translated.

clientTraceId
Guid

A client-generated GUID to uniquely identify the request.

sourceLanguage
String

Specifies the language of the input text. Find which languages are available to translate from by looking up supported languages using the translation scope. If the from parameter isn't specified, automatic language detection is applied to determine the source language.

You must use the from parameter rather than autodetection when using the dynamic dictionary feature. Note: the dynamic dictionary feature is case-sensitive.

textType
Nullable<TextType>

Defines whether the text being translated is plain text or HTML text. Any HTML needs to be a well-formed, complete element. Possible values are: plain (default) or html.

category
String

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.

profanityAction
Nullable<ProfanityAction>

Specifies how profanities should be treated in translations. Possible values are: NoAction (default), Marked or Deleted.

profanityMarker
Nullable<ProfanityMarker>

Specifies how profanities should be marked in translations. Possible values are: Asterisk (default) or Tag.

includeAlignment
Nullable<Boolean>

Specifies whether to include alignment projection from source text to translated text. Possible values are: true or false (default).

includeSentenceLength
Nullable<Boolean>

Specifies whether to include sentence boundaries for the input text and the translated text. Possible values are: true or false (default).

suggestedFrom
String

Specifies a fallback language if the language of the input text can't be identified. Language autodetection is applied when the from parameter is omitted. If detection fails, the suggestedFrom language will be assumed.

fromScript
String

Specifies the script of the input text.

toScript
String

Specifies the script of the translated text.

allowFallback
Nullable<Boolean>

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.

allowFallback=false specifies that the translation should only use systems trained for the category specified by the request. If a translation for language X to language Y requires chaining through a pivot language E, then all the systems in the chain (X → E and E → Y) will need to be custom and have the same category. If no system is found with the specific category, the request will return a 400 status code. allowFallback=true specifies that the service is allowed to fall back to a general system when a custom system doesn't exist.

cancellationToken
CancellationToken

The cancellation token to use.

Returns

Exceptions

targetLanguages or content is null.

Applies to

TranslateAsync(IEnumerable<String>, IEnumerable<String>, String, String, Nullable<TextType>, String, Nullable<ProfanityAction>, Nullable<ProfanityMarker>, Nullable<Boolean>, Nullable<Boolean>, String, String, String, Nullable<Boolean>, CancellationToken)

Source:
TextTranslationClient.cs

Translate Text.

public virtual System.Threading.Tasks.Task<Azure.Response<System.Collections.Generic.IReadOnlyList<Azure.AI.Translation.Text.TranslatedTextItem>>> TranslateAsync (System.Collections.Generic.IEnumerable<string> targetLanguages, System.Collections.Generic.IEnumerable<string> content, string clientTraceId = default, string sourceLanguage = default, Azure.AI.Translation.Text.TextType? textType = default, string category = default, Azure.AI.Translation.Text.ProfanityAction? profanityAction = default, Azure.AI.Translation.Text.ProfanityMarker? profanityMarker = default, bool? includeAlignment = default, bool? includeSentenceLength = default, string suggestedFrom = default, string fromScript = default, string toScript = default, bool? allowFallback = default, System.Threading.CancellationToken cancellationToken = default);
abstract member TranslateAsync : seq<string> * seq<string> * string * string * Nullable<Azure.AI.Translation.Text.TextType> * string * Nullable<Azure.AI.Translation.Text.ProfanityAction> * Nullable<Azure.AI.Translation.Text.ProfanityMarker> * Nullable<bool> * Nullable<bool> * string * string * string * Nullable<bool> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Response<System.Collections.Generic.IReadOnlyList<Azure.AI.Translation.Text.TranslatedTextItem>>>
override this.TranslateAsync : seq<string> * seq<string> * string * string * Nullable<Azure.AI.Translation.Text.TextType> * string * Nullable<Azure.AI.Translation.Text.ProfanityAction> * Nullable<Azure.AI.Translation.Text.ProfanityMarker> * Nullable<bool> * Nullable<bool> * string * string * string * Nullable<bool> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Response<System.Collections.Generic.IReadOnlyList<Azure.AI.Translation.Text.TranslatedTextItem>>>
Public Overridable Function TranslateAsync (targetLanguages As IEnumerable(Of String), content As IEnumerable(Of String), Optional clientTraceId As String = Nothing, Optional sourceLanguage As String = Nothing, Optional textType As Nullable(Of TextType) = Nothing, Optional category As String = Nothing, Optional profanityAction As Nullable(Of ProfanityAction) = Nothing, Optional profanityMarker As Nullable(Of ProfanityMarker) = Nothing, Optional includeAlignment As Nullable(Of Boolean) = Nothing, Optional includeSentenceLength As Nullable(Of Boolean) = Nothing, Optional suggestedFrom As String = Nothing, Optional fromScript As String = Nothing, Optional toScript As String = Nothing, Optional allowFallback As Nullable(Of Boolean) = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of Response(Of IReadOnlyList(Of TranslatedTextItem)))

Parameters

targetLanguages
IEnumerable<String>

Specifies the language of the output text. The target language must be one of the supported languages included in the translation scope. For example, use to=de to translate to German. It's possible to translate to multiple languages simultaneously by repeating the parameter in the query string. For example, use to=de&to=it to translate to German and Italian.

content
IEnumerable<String>

Array of the text to be translated.

clientTraceId
String

A client-generated GUID to uniquely identify the request.

sourceLanguage
String

Specifies the language of the input text. Find which languages are available to translate from by looking up supported languages using the translation scope. If the from parameter isn't specified, automatic language detection is applied to determine the source language.

You must use the from parameter rather than autodetection when using the dynamic dictionary feature. Note: the dynamic dictionary feature is case-sensitive.

textType
Nullable<TextType>

Defines whether the text being translated is plain text or HTML text. Any HTML needs to be a well-formed, complete element. Possible values are: plain (default) or html.

category
String

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.

profanityAction
Nullable<ProfanityAction>

Specifies how profanities should be treated in translations. Possible values are: NoAction (default), Marked or Deleted.

profanityMarker
Nullable<ProfanityMarker>

Specifies how profanities should be marked in translations. Possible values are: Asterisk (default) or Tag.

includeAlignment
Nullable<Boolean>

Specifies whether to include alignment projection from source text to translated text. Possible values are: true or false (default).

includeSentenceLength
Nullable<Boolean>

Specifies whether to include sentence boundaries for the input text and the translated text. Possible values are: true or false (default).

suggestedFrom
String

Specifies a fallback language if the language of the input text can't be identified. Language autodetection is applied when the from parameter is omitted. If detection fails, the suggestedFrom language will be assumed.

fromScript
String

Specifies the script of the input text.

toScript
String

Specifies the script of the translated text.

allowFallback
Nullable<Boolean>

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.

allowFallback=false specifies that the translation should only use systems trained for the category specified by the request. If a translation for language X to language Y requires chaining through a pivot language E, then all the systems in the chain (X → E and E → Y) will need to be custom and have the same category. If no system is found with the specific category, the request will return a 400 status code. allowFallback=true specifies that the service is allowed to fall back to a general system when a custom system doesn't exist.

cancellationToken
CancellationToken

The cancellation token to use.

Returns

Exceptions

targetLanguages or content is null.

Applies to