Localize UI Elements
- 3 minutes to read
This lesson explains how to localize an XAF application. It describes how to translate UI elements into German and create a multi-language application.
Note
For more information on localization, review the following topics:
Step-by-Step Instructions
Add the following packages to the MySolution.Blazor.Server and MySolution.Win projects:
Project name Package name MySolution.Blazor.Server DevExpress.ExpressApp.de
DevExpress.ExpressApp.Blazor.deMySolution.Win DevExpress.ExpressApp.de
DevExpress.ExpressApp.Win.deThe packages are available only for the following languages: German (de), Spanish (es), and Japanese (ja). For 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.
In the MySolution.Blazor.Server project, open the appsettings.json file. Add the German language to the DevExpress:ExpressApp:Languages section and enable the runtime language switcher. You should always use the fully qualified language name that includes the country code (for example,
de-DE
instead ofde
):{ // ... "DevExpress": { "ExpressApp": { "Languages": "en-US;de-DE", "ShowLanguageSwitcher": true, // ... } } }
See the Current Culture in XAF ASP.NET Core Blazor Applications help section for more information on how an XAF ASP.NET Core Blazor application determines the default language.
Open the Model.DesignedDiffs.xafml file in the Model Editor. Focus the MySolution 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.
Save the model changes but don’t restart Visual Studio as the Languages Manager suggests. When you restart Visual Studio, the Model Editor loads the localized property value from the assemblies that you added previously and they become available at design time. For the purposes of this tutorial, these values aren’t necessary.
In the Solution Explorer, right-click the Model.DesignedDiffs.Localization.de-DE.xafml file and open its Properties window. Make sure that the Build Action field is set to Embedded resource.
Open the Model.DesignedDiffs.xafml file in the Model Editor. Select the newly added language in the Language combo box.
The localization packages translate standard strings/messages used in XAF. You also need to translate the strings that are unique to your current application (such as object or property names). To do that, locate properties denoted by the “globe” glyph in all the nodes and child nodes and assign a German translation to them. For the purposes of this tutorial, translate the Employees navigation item to Angestellte:
Tip
Instead of going through each node to find strings that require translation one by one, use the Localization Tool to streamline your localization process.
In the MySolution.Win project, open the Model.xafml file in the Model Editor and navigate to the MySolution node. Set the PreferredLanguage property to
de-De
to display the localized strings in the UI when you run the Windows Forms application.Run the application.
In ASP.NET Core Blazor, you can switch the language in the application settings menu. To access the settings menu, click the gear icon in the upper right corner:
The application should display the German translation of the Employees navigation item.
- ASP.NET Core Blazor
- Windows Forms