How to: Enable RTL Mode for Non-form-based Interfaces in a Multiple Culture Application

  • 4 minutes to read

Your application may contain visual elements that display custom strings and images that are not stored in form resources (e.g., hard coded strings, message boxes, DXPopupMenu, etc.). The adaptation of these elements to Right-to-Left mode also involves a localization step.

To learn how to adapt a Form's UI to RTL mode in an application that supports several languages (including those that use a right-to-left writing system), see How to: Enable RTL Mode for Form's Controls, Strings and Images in a Multiple Culture Application.

Message Boxes

A typical element whose strings are not stored in form resources is a Message Box. Unlike the standard MessageBox, the XtraMessageBox automatically adapts (mirrors) its layout when RTL mode is detected (for the standard MessageBox a special flag needs to be enabled). So, the two things to do when creating a RTL-ready XtraMessageBox are:

  • Translate the message box's custom text and caption (as demonstrated in the walkthrough below).
  • Localize the text of the standard buttons (OK, Cancel, Yes, No, etc.). This task is common to all DevExpress controls that display certain built-in localizable resources and is covered in the Localization document.

In the following figure, you can see an XtraMessageBox displayed for the default culture.

RTL_MessageBox

The localized XtraMessageBox with RTL mode enabled.

RTL_MessageBoxHebrewButtons

DXPopupMenu

The DXPopupMenu automatically reverses the layout of its items in RTL mode. You only need to translate custom text to the target languages, as shown below.

The following walkthrough demonstrates how to localize custom text within XtraMessageBox. The text localization method shown is also applicable to text in DXPopupMenu, hard coded strings, etc.

Walkthrough: How to localize custom strings within an XtraMessageBox

While strings and images within forms and controls should be localized using form-based resources (see How to: Enable RTL Mode for Form's Controls, Strings and Images in a Multiple Culture Application), non-forms-based user interface strings and images, such as strings within message boxes, must be localized using project resources. To provide culture-specific text for message boxes using non-form-based resource files, follow the steps below.

  1. In the Visual Studio Menu Bar, invoke the Project menu, and click Add New Item. Using the Add New Item dialog, create a new Resource File. Name the file Messages.resx. This file is used for the default language.

    RTL_AddNewItem RTL_AddNewItemDialog

  2. Populate the data table with the required string values for the default culture.

    RTL_MessageBoxStrings

  3. Add another new Resource File for a localized application version. Name the file Messages.he.resx. The file name contains a suffix that specifies the culture to which the resource file corresponds.

    TIP

    For a full list of available culture names, refer to the Windows Language Code Identifier (LCID) Reference topic in MSDN.

    RTL_AddNewItem RTL_AddNewItemDialogHebrew

  4. Open the created file using the Solution Explorer window, and populate the data table with the appropriate strings.

    RTL_MessageBoxStringsHebrew

  5. To use localized strings when invoking an XtraMessageBox, see the following code.

    
    using System.Resources;
    //...
    private void button_Click(object sender, EventArgs e) {
        ResourceManager RM = new ResourceManager("WindowsFormsApplication1.Messages", typeof(Form1).Assembly);
    
        XtraMessageBox.Show(
            this.LookAndFeel,
            RM.GetString("strDiscardChangesMessage"),
            RM.GetString("strDiscardChangesCaption"),
            MessageBoxButtons.YesNoCancel
            );
    }
    
  6. After these steps, if the application runs on an operating system that uses Hebrew, custom text in the message box is automatically translated.

    RTL_MessageBoxHebrew

  7. Localize built-in button captions as covered in the Localizing WinForms Controls via Satellite Resource Assemblies document. This approach helps you localize all built-in string resources of DevExpress controls.

    The approach described in this topic involves using the Localization Service to get satellite resource assemblies. When the assemblies are downloaded, locate a folder named according to the abbreviation of the required culture (e.g., he for the Hebrew culture) and simply copy it into the directory where the executable file of your application is located. No code needs to be written, since the application automatically determines the current culture, and loads the appropriate assemblies on startup. The figure below shows the entirely translated message box.

    RTL_MessageBoxHebrewButtons

To test how controls and other visual elements (including XtraMessageBox) are translated to a certain culture, you can manually enable this culture on application startup.


using System.Globalization;
using System.Threading;

Thread.CurrentThread.CurrentCulture = new CultureInfo("he");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("he");
See Also