How to: Localize an XAF .NET 5 Application (Blazor and WinForms)
- 3 minutes to read
This topic describes how to localize XAF .NET 5 applications (WinForms and Blazor).
Tip
Refer to the How to: Localize an XAF Application topic for information on ho to localize XAF .NET Framework Applications.
Review the Application Model Basics and Localization Basics topics before proceeding.
Choose the language you want to use in your XAF application.
Pre-installed languages: German (de), Spanish (es), Japanese (ja) and Russian (ru). These assemblies are available in DevExpress Local NuGet Feed, for example,
DevExpress.ExpressApp.de
orDevExpress.ExpressApp.Core.All.de
.Other languages:
- Use the Localization Service to download satellite assemblies. See the Localize Standard XAF Modules and DevExpress Controls Used in an Application topic for more information on how to use this service to localize XAF modules.
- Place the downloaded assemblies in the following folders:
- in your application bin folder, for example
\Solution1.BlazorServer\bin\Debug\net5.0\fr
for French. This enable runtime localization. - in your Model Editor’s folder, for example
C:\Program Files (x86)\DevExpress 20.2\Components\Tools\eXpressAppFrameworkNetCore\Model Editor\fr
for French. This enable design-time localization.
- in your application bin folder, for example
Satellite assemblies are reusable in any other project.
Note
Remember to deploy the required satellite assemblies when deploying an XAF application. Refer to the Deployment Tutorial for more details.
For XAF Blazor applications. Add the ApplicationBuilderExtensions.UseRequestLocalization() method call. This enables the RequestLocalizationMiddleware.
namespace MainDemo.Blazor.ServerSide { public class Startup { // ... public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { // ... app.UseHttpsRedirection(); // Enable the RequestLocalizationMiddleware app.UseRequestLocalization(); app.UseStaticFiles(); app.UseRouting(); // ... } } }
In
appsettings.json
, specify languages used in your application in theDevExpress:ExpressApp:Languages
section. This languages list is used to:- load satellite assemblies
- specify the RequestLocalizationMiddleware’s RequestLocalizationOptions.SupportedCultures option.
The first language in this list is used as the default language (specified in the RequestLocalizationOptions.SupportedCultures).
{ // "DevExpress": { "ExpressApp": { "Languages": "en;de;fr" // ... } } }
In the module project, double-click the Model.DesignedDiffs.xafml file to invoke the Model Editor. Focus the root node and click Languages Manager… in the Language combo box on the Model Editor Toolbar. Add the target language in the invoked dialog and click OK. Restart Visual Studio to load localized values from the satellite assemblies and specify the application’s target language in the Language combo box.
Refer to the Localization Basics topic for more information.
- To add a new or modify an existing translation value, use one of the tools described in the How to: Localize XAF Application Items Using XAF Tools topic.
- To specify an application’s language, invoke the Model Editor for an application project, navigate to the Application node, and set the IModelApplication.PreferredLanguage property to a language. Refer to the Localization Basics topic for more details. If you want your application’s language to match the language on the user’s device, set the PreferredLanguage property to (User language).
- Windows Forms Templates‘ localizable resources are not available in the Application Model by default. Refer to the How to: Localize a WinForms Template to learn how you can localize Windows Forms templates.
- The splash screen form displayed on the Windows Forms application startup contains a “Loading“ text label. You can specify a different text as described in the Localize a Splash Form topic.
- Start the application to ensure that all the text values are localized.