xtrareports-405435-ai-powered-functionality-desktop-reporting-destop-ai-localization.md
Follow instructions in this help topic to integrate AI-powered Localization functionality into the WinForms Report Designer.
Once you complete the steps below, the Localize with AI button appears in the Localization Editor. This button translates all localizable property values to the selected language:
Install the following NuGet packages:
Microsoft.Extensions.AI.OpenAI (Version=”9.7.1-preview.1.25365.4”)
DevExpress.AIIntegration.WinForms.Reporting (Requires .NET 8 or .NET Framework v4.7.2 and higher)
Optional:
DevExpress.Win.Design (for .NET projects)The following code snippet registers an Azure OpenAI client at application startup:
using Azure.AI.OpenAI;
using DevExpress.AIIntegration;
using Microsoft.Extensions.AI;
using System.ClientModel;
internal static class Program {
static string AzureOpenAIEndpoint { get { return "AZURE_OPENAI_ENDPOINT"; } }
static string AzureOpenAIKey { get { return "AZURE_OPENAI_APIKEY"; } }
static string DeploymentName { get { return "MODEL_NAME"; } } // For example, gpt-4.1.
[STAThread]
static void Main(){
IChatClient client = new AzureOpenAIClient(
new Uri(AzureOpenAIEndpoint),
new ApiKeyCredential(AzureOpenAIKey))
.GetChatClient(DeploymentName).AsIChatClient();
AIExtensionsContainerDesktop.Default.RegisterChatClient(client);
ApplicationConfiguration.Initialize();
Application.Run(new Form1());
}
}
Imports Azure.AI.OpenAI
Imports DevExpress.AIIntegration
Imports Microsoft.Extensions.AI
Imports System.ClientModel
Friend Module Program
Private ReadOnly Property AzureOpenAIEndpoint() As String
Get
Return "AZURE_OPENAI_ENDPOINT"
End Get
End Property
Private ReadOnly Property AzureOpenAIKey() As String
Get
Return "AZURE_OPENAI_APIKEY"
End Get
End Property
Private ReadOnly Property DeploymentName() As String
Get
Return "MODEL_NAME"
End Get
End Property
<STAThread>
Sub Main()
Dim client As IChatClient = (New AzureOpenAIClient(New Uri(AzureOpenAIEndpoint), New ApiKeyCredential(AzureOpenAIKey))).GetChatClient(DeploymentName).AsIChatClient()
AIExtensionsContainerDesktop.Default.RegisterChatClient(client)
ApplicationConfiguration.Initialize()
Application.Run(New Form1())
End Sub
End Module
Tip
How to Register OpenAI, Azure OpenAI, Ollama, and Semantic Kernel Clients.
Follow the steps below to attach the Report Localization Behavior to the WinForms Report Designer control at design time:
Drop the BehaviorManager component from the Toolbox onto a Form.
(For .NET Framework Projects) Use the Register AI-Powered Behaviors option in the BehaviorManager’s smart tag menu to add the “AI-Powered Behaviors” submenu with report behaviors to BehaviorManager.
Use the Edit Behaviors option in the BehaviorManager’s smart tag menu to access the behavior collection.
Add the Report Localization Behavior:
The following code registers ReportLocalizationBehavior and attaches it to the WinForms Report Designer control:
using DevExpress.AIIntegration.WinForms.Reporting;
// ...
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
behaviorManager1.Attach<ReportLocalizationBehavior>(reportDesigner1, behavior => { });
}
}
Imports DevExpress.AIIntegration.WinForms.Reporting
' ...
Partial Public Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
behaviorManager1.Attach(Of ReportLocalizationBehavior)(reportDesigner1, Sub(behavior)
End Sub)
End Sub
End Class
Invoke the Localization Editor. Click the “plus” above the left panel to select a new language. Click the Localize with AI button to translate all localizable property values to the selected language.
The AI icon appears next to the language when localization is complete:
Note
You can also localize a previously added language using AI. In this case, existing translated strings are replaced with AI-translated strings.
The following message appears when you click Apply or OK :
“You are about to apply a translation that may include AI-generated content. We recommend that you review all translated strings before you proceed. Do you want to continue?”
Click Yes to apply changes, or click No to return to the Localization Editor and review/edit AI-translated strings in the right panel.
See Also