Localize Reports in the WinForms Report Designer
- 3 minutes to read
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:
Activate AI Assistant
Install NuGet Packages
Install the following NuGet packages:
Microsoft.Extensions.AI.OpenAI (Version=”9.5.0-preview.1.25265.7”)
Azure.AI.OpenAI (Version=”2.2.0-beta.4”)
This tutorial uses Azure OpenAI. Refer to the AI-powered Extensions help topic for information about NuGet packages required for other supported AI services.
DevExpress.AIIntegration.WinForms.Reporting
(Requires .NET 8 or .NET Framework v4.7.2 and higher)
Optional:
DevExpress.Win.Design
(for .NET projects)
Register AI Client
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());
}
}
Note
Review the following help topic for information on how to register other supported AI services: How to Register an AI Client.
Create and Configure AI Assistant Behavior
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:
Create and Configure AI Assistant Behavior at Runtime
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 => { });
}
}
Localize Report
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.