# Google Cloud Translation v2 API - Class TranslationClient (3.5.0)

<button class="button button-with-icon cloud-select-dropdown__button " aria-haspopup="true">Version latest</button>

- [3.5.0 (latest)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationClient)
- [3.4.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/3.4.0/Google.Cloud.Translation.V2.TranslationClient)
- [3.3.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/3.3.0/Google.Cloud.Translation.V2.TranslationClient)
- [3.2.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/3.2.0/Google.Cloud.Translation.V2.TranslationClient)
- [3.1.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/3.1.0/Google.Cloud.Translation.V2.TranslationClient)
- [3.0.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/3.0.0/Google.Cloud.Translation.V2.TranslationClient)
- [2.1.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/2.1.0/Google.Cloud.Translation.V2.TranslationClient)

    public abstract class TranslationClient : IDisposable

Reference documentation and code samples for the Google Cloud Translation v2 API class TranslationClient.

Abstract class providing operations for Google Cloud Translation.

## Inheritance

[object](https://learn.microsoft.com/dotnet/api/system.object) \> TranslationClient

## Implements

[IDisposable](https://learn.microsoft.com/dotnet/api/system.idisposable)

## Inherited Members

[object.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.object.gethashcode) [object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype) [object.MemberwiseClone()](https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone) [object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring)

## Derived Types

[TranslationClientImpl](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationClientImpl)

## Namespace

[Google.Cloud.Translation.V2](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2)

## Assembly

Google.Cloud.Translation.V2.dll

## Remarks


This abstract class is provided to enable testability while permitting
additional operations to be added in the future. See [Create(GoogleCredential, TranslationModel)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationClient#Google_Cloud_Translation_V2_TranslationClient_Create_Google_Apis_Auth_OAuth2_GoogleCredential_Google_Cloud_Translation_V2_TranslationModel_),
[CreateAsync(GoogleCredential, TranslationModel)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationClient#Google_Cloud_Translation_V2_TranslationClient_CreateAsync_Google_Apis_Auth_OAuth2_GoogleCredential_Google_Cloud_Translation_V2_TranslationModel_) and
[CreateFromApiKey(string, TranslationModel)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationClient#Google_Cloud_Translation_V2_TranslationClient_CreateFromApiKey_System_String_Google_Cloud_Translation_V2_TranslationModel_) to construct instances; alternatively, you can
construct a [TranslationClientImpl](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationClientImpl) directly from a [TranslateService](https://googleapis.dev/dotnet/Google.Apis.Translate.v2/1.68.0.875/api/Google.Apis.Translate.v2.TranslateService.html).


All instance methods declared in this class are virtual, with an implementation which simply
throws [NotImplementedException](https://learn.microsoft.com/dotnet/api/system.notimplementedexception). All these methods are overridden in [TranslationClientImpl](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationClientImpl).


This class implements [IDisposable](https://learn.microsoft.com/dotnet/api/system.idisposable); however, the [Dispose()](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationClient#Google_Cloud_Translation_V2_TranslationClient_Dispose) method only requires calling
if many short-lived instances of [TranslationClient](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationClient) are being created.
Most code would be expected to create a single `TranslationClient` instance, and use this instance throughout
the lifetime of the application. In this case, `Dispose` need not be called.

## Properties

### DefaultModel

    public virtual TranslationModel DefaultModel { get; }

The default translation model used by this client.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationModel` |   |

**Remarks** Each `Translate` method has an optional parameter to override this.

### Service

    public virtual TranslateService Service { get; }

The underlying translation service object used by this client.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://googleapis.dev/dotnet/Google.Apis.Translate.v2/1.68.0.875/api/Google.Apis.Translate.v2.TranslateService.html` |   |

**Remarks** The [TranslationClient](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.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

### Create()

    public static TranslationClient Create()

Synchronously creates a [TranslationClient](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationClient) using application default credentials.
For any non-default values, please use [TranslationClientBuilder](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationClientBuilder).

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationClient` |   |

### Create(GoogleCredential, TranslationModel)

    public static TranslationClient Create(GoogleCredential credential = null, TranslationModel model = TranslationModel.ServiceDefault)

Synchronously creates a [TranslationClient](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationClient), using application default credentials if
no credentials are specified.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `credential` | `https://cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.GoogleCredential.html` Optional [GoogleCredential](https://cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.GoogleCredential.html). If this is non-null, default scopes are applied to it (for credential types that support scoping), overriding any existing scopes in the credentials. To use scoped credentials without any modifications, create a [TranslationClientBuilder](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationClientBuilder) and set the [Credential](https://cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Rest.ClientBuilderBase-1.html#Google_Api_Gax_Rest_ClientBuilderBase_1_Credential) property. |
| `model` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationModel` The default translation model to use. Defaults to [ServiceDefault](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationModel#Google_Cloud_Translation_V2_TranslationModel_ServiceDefault). |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationClient` | The created [TranslationClient](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationClient). |

**Remarks** If a credential is supplied, the default scopes are applied to it (for credential types that support scoping),
overriding any existing scopes in the credentials. To use scoped credentials without any modifications, create
a [TranslationClientBuilder](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationClientBuilder) and set the [Credential](https://cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Rest.ClientBuilderBase-1.html#Google_Api_Gax_Rest_ClientBuilderBase_1_Credential) property.

### CreateAsync()

    public static Task<TranslationClient> CreateAsync()

Asynchronously creates a [TranslationClient](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationClient) using application default credentials.
For any non-default values, please use [TranslationClientBuilder](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationClientBuilder).

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task-1https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationClient` | The task representing the created [TranslationClient](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationClient). |

### CreateAsync(GoogleCredential, TranslationModel)

    public static Task<TranslationClient> CreateAsync(GoogleCredential credential = null, TranslationModel model = TranslationModel.ServiceDefault)

Asynchronously creates a [TranslationClient](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationClient), using application default credentials if
no credentials are specified.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `credential` | `https://cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.GoogleCredential.html` Optional [GoogleCredential](https://cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.GoogleCredential.html). If this is non-null, default scopes are applied to it (for credential types that support scoping), overriding any existing scopes in the credentials. To use scoped credentials without any modifications, create a [TranslationClientBuilder](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationClientBuilder) and set the [Credential](https://cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Rest.ClientBuilderBase-1.html#Google_Api_Gax_Rest_ClientBuilderBase_1_Credential) property. |
| `model` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationModel` The default translation model to use. Defaults to [ServiceDefault](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationModel#Google_Cloud_Translation_V2_TranslationModel_ServiceDefault). |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task-1https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationClient` | The task representing the created [TranslationClient](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationClient). |

**Remarks** If a credential is supplied, the default scopes are applied to it (for credential types that support scoping),
overriding any existing scopes in the credentials. To use scoped credentials without any modifications, create
a [TranslationClientBuilder](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationClientBuilder) and set the [Credential](https://cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Rest.ClientBuilderBase-1.html#Google_Api_Gax_Rest_ClientBuilderBase_1_Credential) property.

### CreateFromApiKey(string, TranslationModel)

    public static TranslationClient CreateFromApiKey(string apiKey, TranslationModel model = TranslationModel.ServiceDefault)

Creates a [TranslationClient](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationClient) from an API key instead of using OAuth2 credentials.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `apiKey` | `https://learn.microsoft.com/dotnet/api/system.string` API key to use. Must not be null. |
| `model` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationModel` The default translation model to use. Defaults to [ServiceDefault](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationModel#Google_Cloud_Translation_V2_TranslationModel_ServiceDefault). |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationClient` | The created [TranslationClient](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationClient). |

**Remarks** You are encouraged to use OAuth2 credentials where possible. This method is primarily provided to make the transition
from using API keys to OAuth2 credentials straightforward.

### DetectLanguage(string)

    public virtual Detection DetectLanguage(string text)

Detects the language of the specified text synchronously.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `text` | `https://learn.microsoft.com/dotnet/api/system.string` The text to detect the language of. Must not be null. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.Detection` | The most likely detected language. |

**Remarks** This implementation simply delegates to [DetectLanguages(IEnumerable\<string\>)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationClient#Google_Cloud_Translation_V2_TranslationClient_DetectLanguages_System_Collections_Generic_IEnumerable_System_String__).
**Example**

    TranslationClient client = TranslationClient.Create();
    Detection result = client.DetectLanguage("It is raining.");
    Console.WriteLine($"Language: {result.Language}; confidence {result.Confidence}");

### DetectLanguageAsync(string, CancellationToken)

    public virtual Task<Detection> DetectLanguageAsync(string text, CancellationToken cancellationToken = default)

Detects the language of the specified text asynchronously.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `text` | `https://learn.microsoft.com/dotnet/api/system.string` The text to detect the language of. Must not be null. |
| `cancellationToken` | `https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken` The token to monitor for cancellation requests. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task-1https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.Detection` | The most likely detected language. |

**Remarks** This implementation simply delegates to [DetectLanguagesAsync(IEnumerable\<string\>, CancellationToken)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationClient#Google_Cloud_Translation_V2_TranslationClient_DetectLanguagesAsync_System_Collections_Generic_IEnumerable_System_String__System_Threading_CancellationToken_).
**Example**

    TranslationClient client = TranslationClient.Create();
    Detection result = await client.DetectLanguageAsync("It is raining.");
    Console.WriteLine($"Language: {result.Language}; confidence {result.Confidence}");

### DetectLanguages(IEnumerable\<string\>)

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

Detects the languages of the specified text items synchronously.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `textItems` | `https://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerable-1https://learn.microsoft.com/dotnet/api/system.string` The text items to detect the language of. Must not be null or contain null elements. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.collections.generic.ilist-1https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.Detection` | A list of detected languages. This will be the same size as `textItems`, in the same order. |

**Example**

    TranslationClient client = TranslationClient.Create();
    IList<Detection> results = client.DetectLanguages(new[] { "It is raining.", RainingTranslation });
    foreach (var result in results)
    {
        Console.WriteLine($"Text: {result.Text}; language: {result.Language}; confidence {result.Confidence}");
    }

### DetectLanguagesAsync(IEnumerable\<string\>, CancellationToken)

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

Detects the languages of the specified text items asynchronously.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `textItems` | `https://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerable-1https://learn.microsoft.com/dotnet/api/system.string` The text items to detect the language of. Must not be null or contain null elements. |
| `cancellationToken` | `https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken` The token to monitor for cancellation requests. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task-1https://learn.microsoft.com/dotnet/api/system.collections.generic.ilist-1https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.Detection` | A list of detected languages. This will be the same size as `textItems`, in the same order. |

**Example**

    TranslationClient client = TranslationClient.Create();
    IList<Detection> results = await client.DetectLanguagesAsync(new[] { "It is raining.", RainingTranslation });
    foreach (var result in results)
    {
        Console.WriteLine($"Text: {result.Text}; language: {result.Language}; confidence {result.Confidence}");
    }

### Dispose()

    public virtual void Dispose()

Dispose of this instance. See the [TranslationClient](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationClient) remarks on when this should be called.

### ListLanguages(string, TranslationModel?)

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

Lists the language supported by the Translate API synchronously.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `target` | `https://learn.microsoft.com/dotnet/api/system.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` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationModel` The model to request languages for. May be null, in which case [DefaultModel](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationClient#Google_Cloud_Translation_V2_TranslationClient_DefaultModel) is used. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.collections.generic.ilist-1https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.Language` | A list of supported languages. |

**Example**

    TranslationClient client = TranslationClient.Create();
    IList<Language> languages = client.ListLanguages(LanguageCodes.English);
    // Display just the first 10 languages for brevity
    foreach (Language language in languages.Take(10))
    {
        Console.WriteLine($"Language: {language.Name}; code {language.Code}");
    }

### ListLanguagesAsync(string, TranslationModel?, CancellationToken)

    public virtual 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` | `https://learn.microsoft.com/dotnet/api/system.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` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationModel` The model to request languages for. May be null, in which case [DefaultModel](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationClient#Google_Cloud_Translation_V2_TranslationClient_DefaultModel) is used. |
| `cancellationToken` | `https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken` The token to monitor for cancellation requests. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task-1https://learn.microsoft.com/dotnet/api/system.collections.generic.ilist-1https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.Language` | A list of supported languages. |

**Example**

    TranslationClient client = await TranslationClient.CreateAsync();
    IList<Language> languages = await client.ListLanguagesAsync(LanguageCodes.English);
    // Display just the first 10 languages for brevity
    foreach (Language language in languages.Take(10))
    {
        Console.WriteLine($"Language: {language.Name}; code {language.Code}");
    }

### TranslateHtml(IEnumerable\<string\>, string, string, TranslationModel?)

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

Translates multiple items of HTML synchronously.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `htmlItems` | `https://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerable-1https://learn.microsoft.com/dotnet/api/system.string` The HTML strings to translate. Must not be null or contain null elements. |
| `targetLanguage` | `https://learn.microsoft.com/dotnet/api/system.string` The code for the language to translate into. Must not be null. |
| `sourceLanguage` | `https://learn.microsoft.com/dotnet/api/system.string` The code for the language to translate from. May be null, in which case the server will detect the source language. |
| `model` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationModel` The model to request for translation. May be null, in which case [DefaultModel](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationClient#Google_Cloud_Translation_V2_TranslationClient_DefaultModel) is used. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.collections.generic.ilist-1https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationResult` | A list of translations. This will be the same size as `htmlItems`, in the same order. |

**Remarks** See the [Translation API documentation](https://cloud.google.com/translate/markup) for more details
on how to translate HTML and the terms of service.
**Example**

    TranslationClient client = TranslationClient.Create();
    IList<TranslationResult> results = client.TranslateHtml(
        new[] { "<p><strong>It is raining.</strong></p>", "<p><strong>It is sunny.</strong></p>" },
        LanguageCodes.French);
    foreach (TranslationResult result in results)
    {
        Console.WriteLine($"Result: {result.TranslatedText}; detected language {result.DetectedSourceLanguage}");
    }

### TranslateHtml(string, string, string, TranslationModel?)

    public virtual TranslationResult TranslateHtml(string html, string targetLanguage, string sourceLanguage = null, TranslationModel? model = null)

Translates a single item of HTML synchronously.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `html` | `https://learn.microsoft.com/dotnet/api/system.string` The HTML to translate. |
| `targetLanguage` | `https://learn.microsoft.com/dotnet/api/system.string` The code for the language to translate into. Must not be null. |
| `sourceLanguage` | `https://learn.microsoft.com/dotnet/api/system.string` The code for the language to translate from. May be null, in which case the server will detect the source language. |
| `model` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationModel` The model to request for translation. May be null, in which case [DefaultModel](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationClient#Google_Cloud_Translation_V2_TranslationClient_DefaultModel) is used. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationResult` | The translation of `html`. |

**Remarks**
This implementation simply delegates to [TranslateHtml(IEnumerable\<string\>, string, string, TranslationModel?)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationClient#Google_Cloud_Translation_V2_TranslationClient_TranslateHtml_System_Collections_Generic_IEnumerable_System_String__System_String_System_String_System_Nullable_Google_Cloud_Translation_V2_TranslationModel__)


See the [Translation API documentation](https://cloud.google.com/translate/markup) for more details
on how to translate HTML and the terms of service.
**Example**

    TranslationClient client = TranslationClient.Create();
    TranslationResult result = client.TranslateHtml("<p><strong>It is raining.</strong></p>", LanguageCodes.French);
    Console.WriteLine($"Result: {result.TranslatedText}; detected language {result.DetectedSourceLanguage}");

### TranslateHtmlAsync(IEnumerable\<string\>, string, string, TranslationModel?, CancellationToken)

    public virtual 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` | `https://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerable-1https://learn.microsoft.com/dotnet/api/system.string` The HTML strings to translate. Must not be null or contain null elements. |
| `targetLanguage` | `https://learn.microsoft.com/dotnet/api/system.string` The code for the language to translate into. Must not be null. |
| `sourceLanguage` | `https://learn.microsoft.com/dotnet/api/system.string` The code for the language to translate from. May be null, in which case the server will detect the source language. |
| `model` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationModel` The model to request for translation. May be null, in which case [DefaultModel](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationClient#Google_Cloud_Translation_V2_TranslationClient_DefaultModel) is used. |
| `cancellationToken` | `https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken` The token to monitor for cancellation requests. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task-1https://learn.microsoft.com/dotnet/api/system.collections.generic.ilist-1https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationResult` | A list of translations. This will be the same size as `htmlItems`, in the same order. |

**Remarks** See the [Translation API documentation](https://cloud.google.com/translate/markup) for more details
on how to translate HTML and the terms of service.
**Example**

See [TranslateHtmlAsync](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationClient#Google_Cloud_Translation_V2_TranslationClient_TranslateHtmlAsync_System_String_System_String_System_String_System_Nullable_Google_Cloud_Translation_V2_TranslationModel__System_Threading_CancellationToken_) for an example using an alternative overload.

### TranslateHtmlAsync(string, string, string, TranslationModel?, CancellationToken)

    public virtual Task<TranslationResult> TranslateHtmlAsync(string html, string targetLanguage, string sourceLanguage = null, TranslationModel? model = null, CancellationToken cancellationToken = default)

Translates a single item of HTML asynchronously.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `html` | `https://learn.microsoft.com/dotnet/api/system.string` The HTML to translate. Must not be null. |
| `targetLanguage` | `https://learn.microsoft.com/dotnet/api/system.string` The code for the language to translate into. Must not be null. |
| `sourceLanguage` | `https://learn.microsoft.com/dotnet/api/system.string` The code for the language to translate from. May be null, in which case the server will detect the source language. |
| `model` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationModel` The model to request for translation. May be null, in which case [DefaultModel](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationClient#Google_Cloud_Translation_V2_TranslationClient_DefaultModel) is used. |
| `cancellationToken` | `https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken` The token to monitor for cancellation requests. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task-1https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationResult` | The translation of `html`. |

**Remarks**
This implementation simply delegates to [TranslateHtmlAsync(IEnumerable\<string\>, string, string, TranslationModel?, CancellationToken)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationClient#Google_Cloud_Translation_V2_TranslationClient_TranslateHtmlAsync_System_Collections_Generic_IEnumerable_System_String__System_String_System_String_System_Nullable_Google_Cloud_Translation_V2_TranslationModel__System_Threading_CancellationToken_)


See the [Translation API documentation](https://cloud.google.com/translate/markup) for more details
on how to translate HTML and the terms of service.
**Example**

    TranslationClient client = await TranslationClient.CreateAsync();
    TranslationResult result = await client.TranslateHtmlAsync("<p><strong>It is raining.</strong></p>", LanguageCodes.French);
    Console.WriteLine($"Result: {result.TranslatedText}; detected language {result.DetectedSourceLanguage}");

### TranslateText(IEnumerable\<string\>, string, string, TranslationModel?)

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

Translates multiple items of text synchronously.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `textItems` | `https://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerable-1https://learn.microsoft.com/dotnet/api/system.string` The text strings to translate. Must not be null or contain null elements. |
| `targetLanguage` | `https://learn.microsoft.com/dotnet/api/system.string` The code for the language to translate into. Must not be null. |
| `sourceLanguage` | `https://learn.microsoft.com/dotnet/api/system.string` The code for the language to translate from. May be null, in which case the server will detect the source language. |
| `model` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationModel` The model to request for translation. May be null, in which case [DefaultModel](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationClient#Google_Cloud_Translation_V2_TranslationClient_DefaultModel) is used. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.collections.generic.ilist-1https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationResult` | A list of translations. This will be the same size as `textItems`, in the same order. |

**Example**

    TranslationClient client = TranslationClient.Create();
    IList<TranslationResult> results = client.TranslateText(
        new[] { "It is raining.", "It is sunny." },
        LanguageCodes.French);
    foreach (TranslationResult result in results)
    {
        Console.WriteLine($"Result: {result.TranslatedText}; detected language {result.DetectedSourceLanguage}");
    }

### TranslateText(string, string, string, TranslationModel?)

    public virtual TranslationResult TranslateText(string text, string targetLanguage, string sourceLanguage = null, TranslationModel? model = null)

Translates a single item of text synchronously.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `text` | `https://learn.microsoft.com/dotnet/api/system.string` The text to translate. |
| `targetLanguage` | `https://learn.microsoft.com/dotnet/api/system.string` The code for the language to translate into. Must not be null. |
| `sourceLanguage` | `https://learn.microsoft.com/dotnet/api/system.string` The code for the language to translate from. May be null, in which case the server will detect the source language. |
| `model` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationModel` The model to request for translation. May be null, in which case [DefaultModel](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationClient#Google_Cloud_Translation_V2_TranslationClient_DefaultModel) is used. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationResult` | The translation of `text`. |

**Remarks** This implementation simply delegates to [TranslateText(IEnumerable\<string\>, string, string, TranslationModel?)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationClient#Google_Cloud_Translation_V2_TranslationClient_TranslateText_System_Collections_Generic_IEnumerable_System_String__System_String_System_String_System_Nullable_Google_Cloud_Translation_V2_TranslationModel__)
**Example**

    TranslationClient client = TranslationClient.Create();
    TranslationResult result = client.TranslateText("It is raining.", LanguageCodes.French);
    Console.WriteLine($"Result: {result.TranslatedText}; detected language {result.DetectedSourceLanguage}");

### TranslateTextAsync(IEnumerable\<string\>, string, string, TranslationModel?, CancellationToken)

    public virtual 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` | `https://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerable-1https://learn.microsoft.com/dotnet/api/system.string` The text strings to translate. Must not be null or contain null elements. |
| `targetLanguage` | `https://learn.microsoft.com/dotnet/api/system.string` The code for the language to translate into. Must not be null. |
| `sourceLanguage` | `https://learn.microsoft.com/dotnet/api/system.string` The code for the language to translate from. May be null, in which case the server will detect the source language. |
| `model` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationModel` The model to request for translation. May be null, in which case [DefaultModel](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationClient#Google_Cloud_Translation_V2_TranslationClient_DefaultModel) is used. |
| `cancellationToken` | `https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken` The token to monitor for cancellation requests. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task-1https://learn.microsoft.com/dotnet/api/system.collections.generic.ilist-1https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationResult` | A list of translations. This will be the same size as `textItems`, in the same order. |

**Example**

See [TranslateTextAsync](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationClient#Google_Cloud_Translation_V2_TranslationClient_TranslateTextAsync_System_String_System_String_System_String_System_Nullable_Google_Cloud_Translation_V2_TranslationModel__System_Threading_CancellationToken_) for an example using an alternative overload.

### TranslateTextAsync(string, string, string, TranslationModel?, CancellationToken)

    public virtual Task<TranslationResult> TranslateTextAsync(string text, string targetLanguage, string sourceLanguage = null, TranslationModel? model = null, CancellationToken cancellationToken = default)

Translates a single item of text asynchronously.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `text` | `https://learn.microsoft.com/dotnet/api/system.string` The text to translate. Must not be null. |
| `targetLanguage` | `https://learn.microsoft.com/dotnet/api/system.string` The code for the language to translate into. Must not be null. |
| `sourceLanguage` | `https://learn.microsoft.com/dotnet/api/system.string` The code for the language to translate from. May be null, in which case the server will detect the source language. |
| `model` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationModel` The model to request for translation. May be null, in which case [DefaultModel](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationClient#Google_Cloud_Translation_V2_TranslationClient_DefaultModel) is used. |
| `cancellationToken` | `https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken` The token to monitor for cancellation requests. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task-1https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationResult` | The translation of `text`. |

**Remarks** This implementation simply delegates to [TranslateTextAsync(IEnumerable\<string\>, string, string, TranslationModel?, CancellationToken)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Translation.V2/latest/Google.Cloud.Translation.V2.TranslationClient#Google_Cloud_Translation_V2_TranslationClient_TranslateTextAsync_System_Collections_Generic_IEnumerable_System_String__System_String_System_String_System_Nullable_Google_Cloud_Translation_V2_TranslationModel__System_Threading_CancellationToken_)
**Example**

    TranslationClient client = await TranslationClient.CreateAsync();
    TranslationResult result = await client.TranslateTextAsync("It is raining.", LanguageCodes.French);
    Console.WriteLine($"Result: {result.TranslatedText}; detected language {result.DetectedSourceLanguage}");