Back to Devexpress

Localization

maui-404120-common-concepts-localization.md

latest5.8 KB
Original Source

Localization

  • Oct 07, 2024
  • 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.

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:

ControlLocalization Enumeration
DXCollectionViewCollectionViewStringId
DataGridViewGridStringId
EditorsEditorStringId
SchedulerSchedulerStringId
PdfViewerPdfViewerStringId

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.

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

  4. Add your translated resources to this file.

  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.

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.

csharp
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