Skip to main content

Localization

  • 3 minutes to read

DevExpress WinUI controls ship with localizable resources for UI elements, such as button captions, menu items, error messages, and dialog boxes. DevExpress WinUI Controls use English as the default language. This topic describes how to localize controls for other languages.

Localization Basics

Localization strings are grouped in localization enumerations. These strings display their values in your application UI. To translate the UI, change these values.

The following table lists supported controls and their localization enumerations:

Control Localization Enumerations
BarCodeControl BarCodeStringID
DocumentViewer DocumentViewerStringID, PrintingStringID
Editors EditorStringID, EditorValidationStringID
GridControl GridStringID
RangeControl EditorValidationStringID
SchedulerControl SchedulerStringId, DXComboBoxStringID, DXListViewStringID

You can use Project Resources or implement a custom String Loader to localize DevExpress WinUI Controls.

Localize Controls in Project Resources

Create a project resource file and add localization strings you want to change. You can also create multiple resource files for each language your application should support.

  1. Add a folder to your project and give it a name that matches the target language (for example, es for Spanish).
  2. Right-click the created folder and select the Add->New Item… command to add the file to the project.

    Localization-SolutionExplorer-DE-AddNewItem

  3. Select the Resources File (.resw), name it, and click Add.

    Localization-AddResourceFile

  4. Add your translated resources to this file.

    Localization-ResourceFile

    Each resource has a name, value, and comment field.

    The resource’s Name should identify a localization string as EnumName_EnumValue. The enumerators that identify localization strings are listed in the previous section.

    The resource’s Value is a translated string you want to display in the UI.

  5. In your application’s static constructor, create a ResourceStringLoader instance and pass the resource file name as a parameter. Then, assign this instance to the Localizer.StringLoader property.

    public partial class App : Application {
        public App() {
            Localizer.StringLoader = new ResourceStringLoader(resourceMap: "myResourceFile");
            this.InitializeComponent();
        }
    }
    

    Alternatively, in step 2 you can name your project resource file DevExpressWinUI.resw and use a shortened version of the following code line:

    public partial class App : Application {
        public App() {
            Localizer.StringLoader = new ResourceStringLoader();
            this.InitializeComponent();
        }
    }
    

Localize Controls with a Custom String Loader

You can implement a Localizer.IStringLoader interface to use a custom localization mechanism in you application.

The code sample below creates a custom localization rule. In this case, the application uses the specified SchedulerStringId_MenuCmd_GoToToday resource value regardless of the system language.

public class MyStringLoader : Localizer.IStringLoader {
    public bool TryGetString(string key, out string value) {
        if (key == "SchedulerStringId_MenuCmd_GotoToday") {
            value = "Hoy";
            return true; 
        }
        value = key;
        return true;
    }
}

public partial class App : Application {
    public App() {
        Localizer.StringLoader = new MyStringLoader();
        this.InitializeComponent();
    }
}