expressappframework-402956-localization-localize-an-xaf-application.md
This topic describes how to localize XAF applications (WinForms and ASP.NET Core Blazor).
Review the Application Model Basics and Localization Basics topics before proceeding.
Choose the language you want to use in your XAF application.
For XAF ASP.NET Core Blazor applications , add the ApplicationBuilderExtensions.UseRequestLocalization() method call. This enables the RequestLocalizationMiddleware.
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.
To learn how to add a new or modify an existing translation value, refer to the following topic: How to: Localize XAF Application Items Using XAF Tools.
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).
Localizable resources of Windows Forms Templates are not available in the Application Model (the default setting). Refer to the How to: Localize a WinForms Template topic to learn how you can localize Windows Forms templates.
The splash screen form displayed on the Windows Forms application at startup contains a “ Loading “ text label. To change the text, refer to the following topic: Localize a Splash Form.
Start the application to ensure that all the text values are localized.
For XAF ASP.NET Core Blazor UI applications, you can enable the Runtime Language Switcher. You can see the Language Switcher in the following locations:
The login page
The settings menu
To enable the Runtime Language Switcher, set the DevExpress: ExpressApp: ShowLanguageSwitcher value to True in appsettings.json:
{
//
"DevExpress": {
"ExpressApp": {
"Languages": "en-US;de-DE;fr-FR",
"ShowLanguageSwitcher": true
}
}
}
The Languages section must contain at least two supported languages to enable the Runtime Language Switcher. These languages will be displayed in the Language Switcher’s drop-down list.
The application retrieves the language name from CultureInfo.NativeName.
Note
The Runtime Language Switcher requires that IModelApplication.PreferredLanguage is set to (User language).
To change the XAF ASP.NET Core Blazor application language in code, use the IXafCultureInfoService.SetCultureAsync method.
The call of the SetCultureAsync method initiates the following:
RequestLocalizationMiddleware.The code sample below demonstrates how to use IXafCultureInfoService to change the application localization:
File :
MySolution.Blazor.Server\Controllers\GermanCultureController.cs
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using DevExpress.ExpressApp.Blazor;
using DevExpress.ExpressApp.Blazor.Services;
using DevExpress.Persistent.Base;
// ...
public class GermanCultureController : ViewController {
BlazorApplication BlazorApplication => (BlazorApplication)Application;
IXafCultureInfoService CultureInfoService => (IXafCultureInfoService)BlazorApplication.ServiceProvider.GetService(typeof(IXafCultureInfoService));
public GermanCultureController() {
SimpleAction myAction = new SimpleAction(this, "SetGermanCulture", PredefinedCategory.Edit);
myAction.Execute += async (s, e) => await CultureInfoService.SetCultureAsync("de-DE");
}
}
Note
If a current thread’s culture is set to a culture that includes only the language and not the country (for example, “de” or “en”), the currency symbol renders as an international currency symbol (¤), for example: 100.00 ¤.
Refer to the following topics for details:
In XAF ASP.NET Core Blazor applications, the current culture is set in the following order of priority:
Languages collection in appsettings.json should contain this culture.Languages collection does not contain the user’s culture, the application uses the first culture from the collection.When users change the current culture in the Language Switcher, their cookies are updated with the new culture value.
The IModelApplication.PreferredLanguage option affects only the XAF parts of the application (Action’s captions, navigation, layout, etc.), and do not affect the application’s culture.
The application’s current culture depends on both of the following settings:
Languages option in appsettings.json.If your application supports only a single language, specify this language in both appsettings.json and IModelApplication.PreferredLanguage. You should always use the fully qualified language name, for example: xx-YY instead of xx:
{
//
"DevExpress": {
"ExpressApp": {
"Languages": "de-DE"
// ...
}
}
}
Note
The technique described in this section applies to projects that use DxDocumentViewer - the default component in XAF since v.24.1. For more information about migrating to DxDocumentViewer, refer to the following Breaking Change ticket: ReportsV2Module - Migration from DxDocumentViewer to DxReportViewerDxReportViewer does not require additional changes. You can follow the common scenario of an XAF application localization.
The Reporting Module and Filter Editor use DevExpress Web Reporting components - you can use the same technique to localize both.
Note
The example described in this section is available in the following demo and reference materials:
The example below shows how to localize an XAF ASP.NET Core Blazor application to German.
Add German language to the YourSolutionName.Blazor.Server\appsettings.json file of your ASP.NET Core Blazor application.
Add the JSON files with localization resources to the wwwroot\js\localization folder. You can obtain the JSON files from the DevExpress Localization Service. For additional information, refer to the following help topic: Obtain JSON Files from the Localization Service. For the purposes of this example, the following files are used:
In the YourSolutionName.Blazor.Server\Controllers folder, create a View Controller. In this Controller, specify the CustomizeLocalization handler for DxReportDesigner, DxDocumentViewer, and FilterEditor and set the current culture to the client using JSInterop.
Add the CustomizeLocalization handler to the YourSolutionName.Blazor.Server\wwwroot\js\scripts.js file:
Add a jQuery library to your project’s YourSolutionName.Blazor.Server\wwwroot\js folder.
Add scripts.js and jQuery references to the YourSolutionName.Blazor.Server\Pages_Host.cshtml file.
Tip
Since the components’ UI is built on DevExtreme widgets, you can also use one of the techniques described in the following topic: Localization.
To localize the Scheduler module, you need to take additional steps after you follow the general localization scenario for XAF applications described in this topic.
Navigate to the DevExpress Localization Service web page. Add or modify translations for the following strings: SchedulerStringId.AppointmentLabel_* and SchedulerStringId.Caption_*.
Save changes and download updated assemblies.
Add all assemblies from the downloaded package to the corresponding language folder in your application’s bin folder (for example, \YourSolutionName.BlazorServer\bin\Debug etX.X\fr-FR and \YourSolutionName.Win\bin\Debug etX.X\fr-FR for the French language).
Build and run the application.
See Also