Skip to main content

Localization

  • 3 minutes to read

The following DevExpress Win10 App controls display built-in strings that can be localized into various languages.

You can localize control strings in code and by defining them in resources.

Localizing in Code

Use the DevExpress.Core.Localization.Localizer class to localize a control’s built-in text in code. This class provides the static AddString method that allows you to add a control’s localized string for a specific language.

public sealed partial class App : Application {

    static App() {
        Localizer.AddString("de", PdfViewerStringID.OpenButtonText, "Öffnen"); 
    }

}

The first parameter of the AddString method specifies the name of the target language. A list of supported language names can be found in MSDN at:Choosing your languages.

The second parameter is the identifier of a string to be translated. The following enumerators contain available string identifiers.

  • DevExpress.Core.Localization.GridStringID - Enumerates localizable strings for the GridControl
  • DevExpress.Core.Localization.PdfViewerStringID - Enumerates localizable strings for the PdfViewerControl

The third parameter of the AddString method specifies the translated string.

Tip

There is an AddString method overload that does not require the target language name to be specified. A translated string provided with this method will be used in all cases that require the default string.

Localizer.AddString(PdfViewerStringID.OpenButtonText, "Öffnen");

The Localizer.AddString method needs to be called before a localizable control is created. The best place to add localized strings is a static constructor of your Application or Page class.

Localizing by Defining Strings in Project Resources

You can define localized strings in resources as follows.

  1. Add a folder to your project and give it a name matching the target language name.
  2. Add a resource file to this project with the Add->New Item… command, which is available from the folder’s context menu.

    Localization-SolutionExplorer-DE-AddNewItem

    Localization-AddResourceFile

  3. Add localizable strings to this resource file.

    Localization-ResourceFile

    The resource name should identify the localizable string in the form: EnumName_EnumValue. The enumerators that identify localizable strings are listed in the section above.

  4. Enable the use of this resource file with the static DevExpress.Core.Localization.Localizer.EnableResourceStrings property.

    public sealed partial class App : Application {
    
        static App() {
            Localizer.EnableResourceStrings = true;
            //...
        }
    }
    

    This property needs to be set before a localizable control is created (for instance, in a static constructor of your Application or Page class).

Localized Resources Priority

The DevExpress localization mechanism searches for translated strings in the following order.

  1. Strings that were added by the Localizer.AddString method with the target language name specified.
  2. Strings in resource files (if the Localizer.EnableResourceStrings property is enabled).
  3. Default strings that were added by the Localizer.AddString method overload without the parameter identifying the target language name.