Class TranslationClientImpl (3.0.0)

public sealed class TranslationClientImpl : TranslationClient, IDisposable

Wrapper around TranslateService to provide simpler operations.

Inheritance

Object > TranslationClient > TranslationClientImpl

Implements

IDisposable

Namespace

Google.Cloud.Translation.V2

Assembly

Google.Cloud.Translation.V2.dll

Remarks

This is the "default" implementation of TranslationClient. Most client code should refer to TranslationClient, creating instances with Create(GoogleCredential, TranslationModel), CreateAsync(GoogleCredential, TranslationModel) and CreateFromApiKey(String, TranslationModel). The constructor of this class is public for the sake of constructor-based dependency injection.

Constructors

TranslationClientImpl(TranslateService, TranslationModel)

public TranslationClientImpl(TranslateService service, TranslationModel model = TranslationModel.ServiceDefault)

Constructs a new client wrapping the given TranslateService.

Parameters
NameDescription
serviceTranslateService

The service to wrap. Must not be null.

modelTranslationModel

The default translation model to use. Defaults to ServiceDefault.

Properties

ApplicationName

public static string ApplicationName { get; set; }

The default application name used when creating a TranslateService. Defaults to "google-cloud-dotnet"; must not be null.

Property Value
TypeDescription
String
Remarks

Most applications will never want to set this, which is why it's in this class rather than TranslationClient.

DefaultModel

public override TranslationModel DefaultModel { get; }

The default translation model used by this client.

Property Value
TypeDescription
TranslationModel
Overrides Remarks

Each Translate method has an optional parameter to override this.

Service

public override TranslateService Service { get; }

The underlying translation service object used by this client.

Property Value
TypeDescription
TranslateService
Overrides Remarks

The TranslationClient class only provides convenience operations built on top of an existing service object. Any more complex operations which are not supported by this wrapper may wish to use the same service object as the wrapper, in order to take advantage of its configuration (for authentication, application naming etc).

Methods

DetectLanguages(IEnumerable<String>)

public override IList<Detection> DetectLanguages(IEnumerable<string> textItems)

Detects the languages of the specified text items synchronously.

Parameter
NameDescription
textItemsIEnumerable<String>

The text items to detect the language of. Must not be null or contain null elements.

Returns
TypeDescription
IList<Detection>

A list of detected languages. This will be the same size as textItems, in the same order.

Overrides

DetectLanguagesAsync(IEnumerable<String>, CancellationToken)

public override async Task<IList<Detection>> DetectLanguagesAsync(IEnumerable<string> textItems, CancellationToken cancellationToken = default(CancellationToken))

Detects the languages of the specified text items asynchronously.

Parameters
NameDescription
textItemsIEnumerable<String>

The text items to detect the language of. Must not be null or contain null elements.

cancellationTokenCancellationToken

The token to monitor for cancellation requests.

Returns
TypeDescription
Task<IList<Detection>>

A list of detected languages. This will be the same size as textItems, in the same order.

Overrides

Dispose()

public override void Dispose()

Dispose of this instance. See the TranslationClient remarks on when this should be called.

Overrides

ListLanguages(String, Nullable<TranslationModel>)

public override IList<Language> ListLanguages(string target = null, TranslationModel? model = null)

Lists the language supported by the Translate API synchronously.

Parameters
NameDescription
targetString

The target language in which to return the language names in the results, for display purposes. May be null, in which case only the language codes are returned.

modelNullable<TranslationModel>

The model to request languages for. May be null, in which case DefaultModel is used.

Returns
TypeDescription
IList<Language>

A list of supported languages.

Overrides

ListLanguagesAsync(String, Nullable<TranslationModel>, CancellationToken)

public override async Task<IList<Language>> ListLanguagesAsync(string target = null, TranslationModel? model = null, CancellationToken cancellationToken = default(CancellationToken))

Lists the language supported by the Translate API asynchronously.

Parameters
NameDescription
targetString

The target language in which to return the language names in the results, for display purposes. May be null, in which case only the language codes are returned.

modelNullable<TranslationModel>

The model to request languages for. May be null, in which case DefaultModel is used.

cancellationTokenCancellationToken

The token to monitor for cancellation requests.

Returns
TypeDescription
Task<IList<Language>>

A list of supported languages.

Overrides

TranslateHtml(IEnumerable<String>, String, String, Nullable<TranslationModel>)

public override IList<TranslationResult> TranslateHtml(IEnumerable<string> htmlItems, string targetLanguage, string sourceLanguage = null, TranslationModel? model = null)

Translates multiple items of HTML synchronously.

Parameters
NameDescription
htmlItemsIEnumerable<String>

The HTML strings to translate. Must not be null or contain null elements.

targetLanguageString

The code for the language to translate into. Must not be null.

sourceLanguageString

The code for the language to translate from. May be null, in which case the server will detect the source language.

modelNullable<TranslationModel>

The model to request for translation. May be null, in which case DefaultModel is used.

Returns
TypeDescription
IList<TranslationResult>

A list of translations. This will be the same size as htmlItems, in the same order.

Overrides Remarks

See the Translation API documentation for more details on how to translate HTML and the terms of service.

TranslateHtmlAsync(IEnumerable<String>, String, String, Nullable<TranslationModel>, CancellationToken)

public override async Task<IList<TranslationResult>> TranslateHtmlAsync(IEnumerable<string> htmlItems, string targetLanguage, string sourceLanguage = null, TranslationModel? model = null, CancellationToken cancellationToken = default(CancellationToken))

Translates multiple items of HTML asynchronously.

Parameters
NameDescription
htmlItemsIEnumerable<String>

The HTML strings to translate. Must not be null or contain null elements.

targetLanguageString

The code for the language to translate into. Must not be null.

sourceLanguageString

The code for the language to translate from. May be null, in which case the server will detect the source language.

modelNullable<TranslationModel>

The model to request for translation. May be null, in which case DefaultModel is used.

cancellationTokenCancellationToken

The token to monitor for cancellation requests.

Returns
TypeDescription
Task<IList<TranslationResult>>

A list of translations. This will be the same size as htmlItems, in the same order.

Overrides Remarks

See the Translation API documentation for more details on how to translate HTML and the terms of service.

TranslateText(IEnumerable<String>, String, String, Nullable<TranslationModel>)

public override IList<TranslationResult> TranslateText(IEnumerable<string> textItems, string targetLanguage, string sourceLanguage = null, TranslationModel? model = null)

Translates multiple items of text synchronously.

Parameters
NameDescription
textItemsIEnumerable<String>

The text strings to translate. Must not be null or contain null elements.

targetLanguageString

The code for the language to translate into. Must not be null.

sourceLanguageString

The code for the language to translate from. May be null, in which case the server will detect the source language.

modelNullable<TranslationModel>

The model to request for translation. May be null, in which case DefaultModel is used.

Returns
TypeDescription
IList<TranslationResult>

A list of translations. This will be the same size as textItems, in the same order.

Overrides

TranslateTextAsync(IEnumerable<String>, String, String, Nullable<TranslationModel>, CancellationToken)

public override async Task<IList<TranslationResult>> TranslateTextAsync(IEnumerable<string> textItems, string targetLanguage, string sourceLanguage = null, TranslationModel? model = null, CancellationToken cancellationToken = default(CancellationToken))

Translates multiple items of text asynchronously.

Parameters
NameDescription
textItemsIEnumerable<String>

The text strings to translate. Must not be null or contain null elements.

targetLanguageString

The code for the language to translate into. Must not be null.

sourceLanguageString

The code for the language to translate from. May be null, in which case the server will detect the source language.

modelNullable<TranslationModel>

The model to request for translation. May be null, in which case DefaultModel is used.

cancellationTokenCancellationToken

The token to monitor for cancellation requests.

Returns
TypeDescription
Task<IList<TranslationResult>>

A list of translations. This will be the same size as textItems, in the same order.

Overrides