Skip to main content

Localization

  • 4 minutes to read

DevExpress .NET MAUI Controls ship with localizable resources for UI elements, such as button captions, menu items, error messages, and dialog boxes. The localizable lines that we use in our controls are stored in the localization strings. These localization strings are grouped into resource files by language.

DevExpress .NET MAUI Controls - Localization

Localize Controls: Use Predefined Resource Files

DevExpress .NET MAUI Controls include predefined resource files that contain localization strings for the following languages:

The out-of-the-box resource files are also included in the DevExpress .NET MAUI Project Templates.

These predefined localization files are applied to your application when you change the interface language on your device and restart the application. Refer to the following example to see it in action:

View Example: Localize DevExpress .NET MAUI Controls - Basic Localization

If you need to translate your application’s UI to other languages, or you need to change certain translations, see the rest of this article. The section below describes how you can create your own localization resource file or change translations in code.

Localization Basics

Localization strings are identified by enumeration values. To localize a certain message, you need to associate one of those values with your translation.

The following table lists supported controls and their localization enumerations:

Control Localization Enumerations
DXCollectionView CollectionViewStringId
DataGridView GridStringId
Editors EditorStringId
Scheduler SchedulerStringId
PDF viewer PdfViewerStringId

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

Localize Controls: Add Localization Resource Files

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. In this case, the names of these localization resources should contain culture names. For example, the application uses the myResourceFile.es.resx file when your device’s interface language is set to Spanish.

The example project below contains a custom language’s resource file (DevExpressMaui.pt.resx).

View Example: Localize DevExpress .NET MAUI Controls - Custom Language Resource Project

Change a Default Language’s Resource

Follow the steps below to override a default language’s localization strings.

  1. Create a folder that stores your localization files or use the project’s Resources default folder (used in this topic).
  2. Right-click the folder and select the Add->New Item… command to add the file to the project.

    Localization-SolutionExplorer-DE-AddNewItem

  3. Select the Resources File (.resx), 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(SchedulerExample.Resources.myResourceFile.ResourceManager);
            this.InitializeComponent();
        }
    }
    

    Alternatively, in step 2 you can name your project resource file DevExpressMaui.resx and set the UseDevExpress(MauiAppBuilder, Boolean) constructor’s useLocalization parameter to true :

    using DevExpress.Maui;
    namespace SchedulerExample;
    public static class MauiProgram {
        public static MauiApp CreateMauiApp() {
            var builder = MauiApp.CreateBuilder();
            builder
                .UseDevExpress(useLocalization: true)
                .UseMauiApp<App>()
                // ...
            return builder.Build();
        }
    }
    

Localize Controls: Use a Custom String Loader

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

The following code snippet creates a custom localization rule. In this case, the application uses the specified SchedulerStringId.AppointmentEdit_NewAppointmentTitle resource value regardless of the system language.

public class MyStringLoader : Localizer.IStringLoader {
    public bool TryGetString(string key, out string value) {
        if (key == "SchedulerStringId.AppointmentEdit_NewAppointmentTitle") {
            value = "Novo Compromisso";
            return true;
        }
        value = null;
        return false;
    }
}

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

View Example: Localize DevExpress .NET MAUI Controls - Custom Localized String Project