Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Document Server
[Expand]Reporting
[Expand]Report Server
[Expand]Dashboard
[Collapse]eXpressApp Framework
 [Expand]Fundamentals
 [Expand]Getting Started
 [Expand]Concepts
 [Expand]Design-Time Features
 [Expand]Functional Testing
 [Expand]Deployment
 [Collapse]Task-Based Help
  [Expand]Business Model Design
  [Expand]Application Model
  [Expand]Actions
  [Expand]Navigation
  [Expand]Views
  [Expand]List Editors
  [Expand]Property Editors
  [Expand]Templates
  [Expand]Filtering
  [Expand]Reporting
  [Expand]Dashboards
  [Expand]Scheduler and Notifications
  [Expand]Maps
  [Expand]Security
  [Expand]Workflow
  [Collapse]Localization
    How to: Create a Custom Translation Provider for the Localization Tool
    How to: Localize a WinForms Template
    How to: Localize an XAF Application
    How to: Localize Custom String Constants
  [Expand]Testing
  [Expand]Miscellaneous UI Customizations
 [Expand]Frequently Asked Questions
 [Expand]API Reference
[Expand]CodeRush
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

How to: Localize Custom String Constants

This topic demonstrates how to localize custom strings, using confirmation messages as an example. The Application Model has the Localization node, which allows for the localization of various constants. You can use this node to localize any custom strings used in your applications.

For instance, a feature that you implement in your application could use the following code.

Expanded Add Localization Items in the Model Editor

To make the text of the confirmation message above localizable, you can add a LocalizationItem child node to the Localization | Messages node, and specify its Value property in the required language. The following image demonstrates the necessary changes to be done in the Application Model.

In this instance, you can get the required message text from the new node, using the CaptionHelper.GetLocalizedText static method.

If you decide that you will have to localize multiple custom strings, you can add a special LocalizationGroup node to the Localization node, and specify your strings within it. Following our example, call this node Confirmations. The following image demonstrates these changes.

In this instance, use the following code.

The LocalizationGroup node can have a multilevel structure. You can create a complex hierarchy and access a required item by passing the path to the CaptionHelper.GetLocalizedText method. Do not include the Localization node itself to the path. For instance, to access the Localization | Messages | Confirmations | DataChangingConfirmations group, use the "Messages\Confirmations\DataChangingConfirmations" path.

Expanded Export Localization Items from Resource Files

Alternatively, you can add Localization Items from the resource file. Assume you have the following MyResource.resx resource file in your XAF solution.

To export values from this file to the Application Model, implement a Resource Localizer (XafResourceLocalizer descendant).

Here, "MySolution.Module.MyResource" is the resource name. Items from this resource will be added to the Localization | Messages | Confirmations Localization Group. Register this Resource Localizer within a module by adding its type to the ModuleBase.ResourcesExportedToModel collection.

Alternatively, you can register a resource localizer within the overridden ModuleBase.GetXafResourceLocalizerTypes method.

In this instance, you will have an ability to add or remove a localizer in the Application Designer.

Note

Localizer types, which are defined in the current module, are not displayed in the Resources exported to model dialog of the Module Designer. This behavior is by design and specific to the work of the Visual Studio design time environment, which cannot get the list of localizer types of the module itself, because this information is not serializable.

Rebuild the solution and invoke the Model Editor. You will see that items from the MyResource.resx resource are exported to the Application Model.

Now, you can use the CaptionHelper.GetLocalizedText method to access localizable values from your code.

Expanded See Also

How would you rate this topic?​​​​​​​