Skip to main content
All docs
V24.2

TranslateRequest(String, String) Constructor

Initializes a new instance of the TranslateRequest class with the specified text and target language.

Namespace: DevExpress.AIIntegration.Extensions

Assembly: DevExpress.AIIntegration.v24.2.dll

NuGet Package: DevExpress.AIIntegration

Declaration

public TranslateRequest(
    string text,
    string language
)

Parameters

Name Type Description
text String

The text to be translated. This value is assigned to the Text property.

language String

The target language for translation. This value is assigned to the Language property.

Remarks

The following example registers an Azure OpenAI client and uses the AI-powered extension to translate the specified text into Italian in a .NET console application:

using Azure;
using Azure.AI.OpenAI;
using Microsoft.Extensions.AI;
using DevExpress.AIIntegration;
using DevExpress.AIIntegration.Extensions;

SetEnvironmentVariables();

// Register an Azure OpenAI client
AIExtensionsContainerDefault defaultAIExtensionsContainer = RegisterAzureOpenAIClient(
    Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT"),
    Environment.GetEnvironmentVariable("AZURE_OPENAI_APIKEY")
);

string textToTranslate = "\"A slow sort of country!\" said the Queen.";
var response = await defaultAIExtensionsContainer.TranslateAsync(
    new TranslateRequest(textToTranslate, "Italian")
);

Console.WriteLine(response);

/* Output:
 * "Un tipo di paese un po' lento!" disse la Regina.
 */

AIExtensionsContainerDefault RegisterAzureOpenAIClient(string azureOpenAIEndpoint, string azureOpenAIKey) {
    IChatClient client = new AzureOpenAIClient(
        new Uri(azureOpenAIEndpoint),
        new AzureKeyCredential(azureOpenAIKey))
            .AsChatClient("gpt-4o-mini");
    return AIExtensionsContainerConsole.CreateDefaultAIExtensionContainer(client);
}

void SetEnvironmentVariables() {
    Environment.SetEnvironmentVariable("AZURE_OPENAI_ENDPOINT", {SPECIFY_YOUR_AZURE_ENDPOINT});
    Environment.SetEnvironmentVariable("AZURE_OPENAI_APIKEY", {SPECIFY_YOU_AZURE_KEY});
}
See Also