Localization

Top  Previous  Next

For anyone wanting to work with inch units, please add the following line in your code (for example, in the FormCreate event).

 

GlobalValueUnit := euInch;

 

WPTools 5 supports the localization of the texts which are used for filters and error messages and also the localization of the provided property dialogs.

 

The localized strings have to be stored in the TWPLanguageControl which is part of the WPShared package. To install the WPShared package please add the unit wpshared.pas to the WPTools 5 package.

 

Please drop this component and your main form and after a double click, load/merge the XML source files which contain the translated strings:

 

clip0053

 

In WPTools 5 you need to add a few lines of code to activate the localisation since the WPShared and WPTools packages had to be kept strictly seperate. The properties of the TWPLanguageControl, "Active" and "AutoLoadStrings" do not work.

 

To active use this code in the OnCreate event of the form:

 

// requires unit WPUtils and WPActnStr

WPLangInterface := TWPLocalizationInterface.Create(WPLanguageControl1);

WPLanguageControl1.GlobalLanguage := 'DE';

WPLocalizeLoadForms := TRUE;

WPTools_LoadVCLStrings;  

WPTools_LoadActionStrings;

 

In the OnDestroy event add this:

 

WPLangInterface.Free;

 

To change the language at runtime use code like this:

 

WPLanguageControl1.GlobalLanguage := 'DE';

WPLocalizeLoadForms := TRUE;

WPTools_LoadVCLStrings;    // from unit WPUtil

WPTools_LoadActionStrings; // from unit WPActnStr

 

How does the localization work?

 

In WPTools 5 we are using a localization interface which is defined as:

 

IWPLocalizationInterface = interface

   ['{A12EF1F7-E592-4483-855F-67E28332AFC5}']

// This method can be used to save the menu items and captions

  on a certain form. If you use the TWPLocalizeForm class you don't need

  to care about that. }

   procedure SaveForm(

     const Name: string;

     Form: TWinControl;

     Menus, Captions, Hints: Boolean);

// Load all Components on a certain TForm. }

   procedure LoadForm(

     const Name: string;

     Form: TWinControl;

     Menus, Captions, Hints: Boolean);

// This method saves a string list under a certain name. The string list has to use

  the syntax NAME=xxx\n }

   procedure SaveStrings(

     const Name: string;

     Entries: TStrings;

     Charset: Integer);

// Loads back the string(s) saved with  WPLangSaveStrings }

   function LoadStrings(

     const Name: string;

     Entries: TStrings;

     var Charset: Integer): Boolean;

// Method to save a certain string. To save multiple strings use  WPLangSaveStrings

   procedure SaveString(

     const Name, Text: string;

     Charset: Integer);

// Loads back a string saved with WPLangSaveString

   function LoadString(

     const Name: string;

     var Text: string;

     var Charset: Integer): Boolean;

end;

 

This interface is implemented by the TWPLanguageControl. The TWPLocalizeForm (implemented in unit WPUtil, it is the anchestor of all localizable dialogs) automatically uses this interface through the instance of the TWPLocalizationInterface class which must be created by your code: WPLangInterface := TWPLocalizationInterface.Create(WPLanguageControl1);