public sealed class TranslationClientImpl : TranslationClient, IDisposable
Reference documentation and code samples for the Google Cloud Translation v2 API class TranslationClientImpl.
Wrapper around TranslateService to provide simpler operations.
Implements
IDisposableNamespace
GoogleGoogle.CloudGoogle.Cloud.TranslationV2Assembly
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 | |
---|---|
Name | Description |
service | TranslateService The service to wrap. Must not be null. |
model | TranslationModel 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 | |
---|---|
Type | Description |
string |
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 | |
---|---|
Type | Description |
TranslationModel |
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 | |
---|---|
Type | Description |
TranslateService |
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 | |
---|---|
Name | Description |
textItems | IEnumerablestring The text items to detect the language of. Must not be null or contain null elements. |
Returns | |
---|---|
Type | Description |
IListDetection | A list of detected languages. This will be the same size as |
DetectLanguagesAsync(IEnumerable<string>, CancellationToken)
public override Task<IList<Detection>> DetectLanguagesAsync(IEnumerable<string> textItems, CancellationToken cancellationToken = default)
Detects the languages of the specified text items asynchronously.
Parameters | |
---|---|
Name | Description |
textItems | IEnumerablestring The text items to detect the language of. Must not be null or contain null elements. |
cancellationToken | CancellationToken The token to monitor for cancellation requests. |
Returns | |
---|---|
Type | Description |
TaskIListDetection | A list of detected languages. This will be the same size as |
Dispose()
public override void Dispose()
Dispose of this instance. See the TranslationClient remarks on when this should be called.
ListLanguages(string, TranslationModel?)
public override IList<Language> ListLanguages(string target = null, TranslationModel? model = null)
Lists the language supported by the Translate API synchronously.
Parameters | |
---|---|
Name | Description |
target | string 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. |
model | TranslationModel The model to request languages for. May be null, in which case DefaultModel is used. |
Returns | |
---|---|
Type | Description |
IListLanguage | A list of supported languages. |
ListLanguagesAsync(string, TranslationModel?, CancellationToken)
public override Task<IList<Language>> ListLanguagesAsync(string target = null, TranslationModel? model = null, CancellationToken cancellationToken = default)
Lists the language supported by the Translate API asynchronously.
Parameters | |
---|---|
Name | Description |
target | string 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. |
model | TranslationModel The model to request languages for. May be null, in which case DefaultModel is used. |
cancellationToken | CancellationToken The token to monitor for cancellation requests. |
Returns | |
---|---|
Type | Description |
TaskIListLanguage | A list of supported languages. |
TranslateHtml(IEnumerable<string>, string, string, TranslationModel?)
public override IList<TranslationResult> TranslateHtml(IEnumerable<string> htmlItems, string targetLanguage, string sourceLanguage = null, TranslationModel? model = null)
Translates multiple items of HTML synchronously.
Parameters | |
---|---|
Name | Description |
htmlItems | IEnumerablestring The HTML strings to translate. Must not be null or contain null elements. |
targetLanguage | string The code for the language to translate into. Must not be null. |
sourceLanguage | string The code for the language to translate from. May be null, in which case the server will detect the source language. |
model | TranslationModel The model to request for translation. May be null, in which case DefaultModel is used. |
Returns | |
---|---|
Type | Description |
IListTranslationResult | A list of translations. This will be the same size as |
See the Translation API documentation for more details on how to translate HTML and the terms of service.
TranslateHtmlAsync(IEnumerable<string>, string, string, TranslationModel?, CancellationToken)
public override Task<IList<TranslationResult>> TranslateHtmlAsync(IEnumerable<string> htmlItems, string targetLanguage, string sourceLanguage = null, TranslationModel? model = null, CancellationToken cancellationToken = default)
Translates multiple items of HTML asynchronously.
Parameters | |
---|---|
Name | Description |
htmlItems | IEnumerablestring The HTML strings to translate. Must not be null or contain null elements. |
targetLanguage | string The code for the language to translate into. Must not be null. |
sourceLanguage | string The code for the language to translate from. May be null, in which case the server will detect the source language. |
model | TranslationModel The model to request for translation. May be null, in which case DefaultModel is used. |
cancellationToken | CancellationToken The token to monitor for cancellation requests. |
Returns | |
---|---|
Type | Description |
TaskIListTranslationResult | A list of translations. This will be the same size as |
See the Translation API documentation for more details on how to translate HTML and the terms of service.
TranslateText(IEnumerable<string>, string, string, TranslationModel?)
public override IList<TranslationResult> TranslateText(IEnumerable<string> textItems, string targetLanguage, string sourceLanguage = null, TranslationModel? model = null)
Translates multiple items of text synchronously.
Parameters | |
---|---|
Name | Description |
textItems | IEnumerablestring The text strings to translate. Must not be null or contain null elements. |
targetLanguage | string The code for the language to translate into. Must not be null. |
sourceLanguage | string The code for the language to translate from. May be null, in which case the server will detect the source language. |
model | TranslationModel The model to request for translation. May be null, in which case DefaultModel is used. |
Returns | |
---|---|
Type | Description |
IListTranslationResult | A list of translations. This will be the same size as |
TranslateTextAsync(IEnumerable<string>, string, string, TranslationModel?, CancellationToken)
public override Task<IList<TranslationResult>> TranslateTextAsync(IEnumerable<string> textItems, string targetLanguage, string sourceLanguage = null, TranslationModel? model = null, CancellationToken cancellationToken = default)
Translates multiple items of text asynchronously.
Parameters | |
---|---|
Name | Description |
textItems | IEnumerablestring The text strings to translate. Must not be null or contain null elements. |
targetLanguage | string The code for the language to translate into. Must not be null. |
sourceLanguage | string The code for the language to translate from. May be null, in which case the server will detect the source language. |
model | TranslationModel The model to request for translation. May be null, in which case DefaultModel is used. |
cancellationToken | CancellationToken The token to monitor for cancellation requests. |
Returns | |
---|---|
Type | Description |
TaskIListTranslationResult | A list of translations. This will be the same size as |