TWPLanguageControl Component
Properties Methods Events

Unit
WPLngCtr

Declaration
TWPLanguageControl = class(TWPCustomXMLTree)

Hierarchy
TComponent <--TWPCustomXMLInterface <--TWPCustomXMLTree <--TWPLanguageControl

Subclasses
None

Description
This class - one instance is allowed in one project - manages the localization of the WP products and can be used for your own forms, too. It inherits from the WP XML interface class:

You can use the property editor (double click) to load and save the language data. This property also allows it to load and save sub-trees of the XML tree so you can add and remove language resources.

WPTools 4:
The localization can be done through the function pointers defined in unit WPLocalize or using the class TWPLocalizeForm. Please note that the function pointers in WPLocalize are all NULL as long as no instance of TWPLanguageControl has been created!

WPTools 5:
The localization has been updated. Instead of the interface unit wplocalize.dcu a COM interface is used. This interface has to be created in the main form of the application, using an instance of this class:
   WPLangInterface:=TWPLocalizationInterface.Create(WPLanguageControl1);   
   WPTools_LoadVCLStrings;                                   
   WPTools_LoadActionStrings;                                
   WPLocalizeLoadForms := TRUE;

This code can be used to switch languages:
var NewText : String; // This is the language id, for example "EN"
begin
  // Check if there is an entry for this language id
  if WPLanguageControl1.Find('/loc/'+NewText)<>nil  then
  begin
     // Switches the language ID
     WPLanguageControl1.GlobalLanguage := NewText;
	 // Load the VCL strings (everything what is not on a form) 
     WPLanguageControl1.LoadVCLStrings;
	 WPTools_LoadActionStrings;
  end 
  else ShowMessage('Language Code ' + NewText + ' was not defined!');

After this code all new instances of TWPLocalizeForm (and the WPTools Dialogs) will load the strings from the different XML branch.
To update the forms which already have been created use TWPLocalizeForm.LoadLocStrings or, if your form does not inherit from this class, do it in just one line of code:
   WPLanguageControl1.LoadForm('Forms/' + Form1.Name, Form1 ,true,true,true);


To save the strings on a form which does not inherit from TWPLocalizeForm you can do it, too:
  WPLanguageControl1.SaveForm('Forms/Main',Self,true,true,true); // Update the XML Tree
  WPLanguageControl1.SaveToFile('LocFile.XML');

The procedure "WPLanguageControl1.SaveToFile" saves the complete XML tree which includes all other definitions, including other languages and the WPTools strings. To avoid that you can also save only a certain XML branch:
var xml : TWPXMLOneLevel;
    f : String;
begin
  F := ExtractFilePath(Application.EXEName) + 'MainForm.XML';

  xml := WPLanguageControl1.SaveForm('Forms/Main',Self,true,true,true);
  // ... any other forms ?
  // ...

  // This saves the branch we have just created
  // You can later 'merge' it into the main tree with the XML property editor
  // To save the complete tree use xml.Parent.SaveToFile ...
  xml.Comment := 'Localisation of ' + ClassName + '(' + Name + ')';
  xml.SaveToFile(F,true);
end;


Introduced Properties
Active 
AutoLoadStrings 
AutoSaveStrings 
FileName 
GlobalLanguage 
OnLoaded 
XMLData 
XMLParent 

Introduced Methods
Create 
Destroy 
Loaded 
LoadForm 
LoadString 
LoadStrings 
LoadVCLStrings 
SaveForm 
SaveString 
SaveStrings 
SaveVCLStrings 
WPAutoLocalize 

Introduced Events
AfterLoadForm 
AfterSaveForm 
BeforeLoadForm 
BeforeSaveForm 


Copyright (C) by WPCUBED GmbH - Munich
http://www.wpcubed.com