DevExpress Localizer - VCL Application Localization

来源:百度文库 编辑:神马文学网 时间:2024/04/27 14:29:58

A new localization component - TcxLocalizer - allows you to easily localize applications that use standard, DevExpress or other third-party controls to any language supported by Windows.

With TcxLocalizer, the simplest way to localize your application is the following:

  • Create a resource strings file using the Localizer Editor (a standalone application shipped with the component).
  • Drop the TcxLocalizer component onto a form and link it to the resource strings file.
  • Make certain that the TcxLocalizer.Active property is True.
  • Now you can switch the current locale using a single property.

 

Localizing Developer Express Controls

In our controls, the text displayed in UI elements is stored as resource strings. Prior to the TcxLocalizer component, you had to manually change resource string values. Now, you can use the Localizer Editor to browse all available resource strings for our controls, specify resource string values for any number of locales and store these values to a resource strings file. Note that you can store Unicode strings and use them in applications built with Delphi/C++ Builder 2009.



After you've specified all required values, the created resource strings file can be linked to the TcxLocalizer component. At runtime, DevExpress controls will display text depending upon the current locale.

Localizing Standard or Third-Party Controls

When using standard or third-party components, add support for the IdxLocalizerListener interface, register components with the built-in instance of the TdxResourceStringsRepository as listeners, and implement the interface's TranslationChanged method. In this method, update the control's content using the current locale's strings.

You are free to programmatically assign string constants based on the current locale specified by the TcxLocalizer component. The Localizer Editor, however, provides a more elegant way to accomplish this. You can define custom resource strings with unique names, specify their translations for required languages, and retrieve these translations in the TranslationChanged method.

The following code example demonstrates how a form's caption and a few labels are localized using resource strings defined with the help of the Localizer Editor.

[Delphi]

uses
  cxLocalization, dxCore, cxClasses, CustomResourceStringsUnit;
type
  TForm1 = class(TForm, IdxLocalizerListener)
  cxLocalizer1: TcxLocalizer;
  procedure FormCreate(Sender: TObject);
  procedure FormDestroy(Sender: TObject);

// ...
  public
    procedure TranslationChanged;
  end;
// ...

implementation
// ...

  procedure TForm1.FormCreate(Sender: TObject);
  begin
    dxResourceStringsRepository.AddListener(Self);
  end;

  procedure TForm1.FormDestroy(Sender: TObject);
  begin
    dxResourceStringsRepository.RemoveListener(Self);
  end;

  procedure TForm1.TranslationChanged;
  begin
    Caption := cxGetResourceString(@sMainFormCaption);
    lblDescription.Caption := cxGetResourceString(@sDescription);
    lblFileLocation.Caption := cxGetResourceString(@sFileLocation);
    // ...
  end;

Supported DevExpress Products

Codeless UI localization is supported by the following DevExpress VCL Products:

  • ExpressBars 6
  • ExpressQuantumGrid 6
  • ExpressScheduler 3
  • ExpressQuantumTreeList 4
  • ExpressLayout Control
  • ExpressVerticalGrid
  • ExpressPivotGrid 2
  • ExpressSpellChecker
  • ExpressSpreadSheet
  • ExpressNavBar 2
  • ExpressPrinting System
  • ExpressSkins Library