Back to Devexpress

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

windowsforms-115901-build-an-application-right-to-left-layout-how-to-enable-rtl-mode-for-non-form-based-interfaces-in-a-multiple-culture-application.md

latest5.6 KB
Original Source

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

  • Mar 14, 2021
  • 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.

The localized XtraMessageBox with RTL mode enabled.

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.

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

  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.

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

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

  6. After these steps, if the application runs on an operating system that uses Hebrew, custom text in the message box is automatically translated.

  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.

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.

csharp
using System.Globalization;
using System.Threading;

Thread.CurrentThread.CurrentCulture = new CultureInfo("he");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("he");
vb
Imports System.Globalization
Imports System.Threading

Thread.CurrentThread.CurrentCulture = New CultureInfo("he")
Thread.CurrentThread.CurrentUICulture = New CultureInfo("he")

See Also

How to: Enable RTL Mode in a Right-to-Left Culture Application

How to: Enable RTL Mode for Form's Controls, Strings and Images in a Multiple Culture Application

Localizing WinForms Controls with Satellite Resource Assemblies