📄 localtest.pas
字号:
unit LocalTest;
{* Test project to
a) create language file
b) edit language file
c) test language file
d) show how to use the localisation control
by Julian Ziersch, wpcubed GmbH
Note the lines marked with "WPTOOLS5"
*}
interface
{$I WPINC.INC}
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
WPTbar, StdCtrls, ExtCtrls,
WPTblDlg, WPSymDlg, WPTabdlg, WpParPrp, WpParBrd, Wpspdlg1, WPBltDlg,
WPPrvFrm, WP1Style, WpPagPrp, WPUtil, WPStyles, WPXMLint,
WPLngCtr, WPCTRStyleCol,
WPCTRRich, WPRTEDefs, WPCTRMemo, WPActnStr
{$IFDEF WPREPORTER} , WPRepEd{$ENDIF} ;
type
TWPTestLocalize = class(TForm)
WPToolBar1: TWPToolBar;
WPRichText1: TWPRichText;
WPStyleDlg2: TWPStyleDlg;
WPPagePropDlg1: TWPPagePropDlg;
WPOneStyleDlg1: TWPOneStyleDlg;
WPPreviewDlg1: TWPPreviewDlg;
WPBulletDlg1: TWPBulletDlg;
WPSpellCheckDlg1: TWPSpellCheckDlg;
WPParagraphBorderDlg1: TWPParagraphBorderDlg;
WPParagraphPropDlg1: TWPParagraphPropDlg;
WPTabDlg1: TWPTabDlg;
WPSymbolDlg1: TWPSymbolDlg;
WPTableDlg1: TWPTableDlg;
WPStyleCollection1: TWPStyleCollection;
SelectLanguage: TComboBox;
Label1: TLabel;
RadioGroup1: TRadioGroup;
ShowDialog: TButton;
WPLanguageControl1: TWPLanguageControl;
SaveLanguage: TButton;
Label2: TLabel;
Bevel1: TBevel;
procedure FormCreate(Sender: TObject);
procedure ShowDialogClick(Sender: TObject);
procedure SaveLanguageClick(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure SelectLanguageClick(Sender: TObject);
procedure UpdateClick(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{$IFDEF WPREPORTER} WPReportBandsDialog1: TWPReportBandsDialog;{$ENDIF}
public
FLanguageFile : String;
procedure UpdateSelectLanguage;
end;
var
WPTestLocalize: TWPTestLocalize;
implementation
{$R *.DFM}
// Create a List of all dialogs we have dropped on the form
procedure TWPTestLocalize.FormCreate(Sender: TObject);
var i : Integer;
begin
// USAGE!!!
if (WPLanguageControl1.Find('/loc')=nil) or
(WPLanguageControl1.Find('/loc').Count=0) then
begin
ShowMessage('To use this demo please click double on the component' + #13 +
'TWPLanguageControl and load/merge in a language XML file!');
Halt;
end;
{$IFDEF WPREPORTER}
WPReportBandsDialog1:= TWPReportBandsDialog.Create(Self);
{$ENDIF}
for i:=0 to ComponentCount-1 do
if Components[i] is TWPCustomAttrDlg then
RadioGroup1.Items.AddObject( Components[i].ClassName, Components[i]);
if RadioGroup1.Items.Count>0 then
RadioGroup1.ItemIndex := 0;
{ FLanguageFile := ExtractFilePath(Application.EXEName) + 'Default.LNG';
if FileExists(FLanguageFile) then
WPLanguageControl1.LoadFromFile(FLanguageFile); }
UpdateSelectLanguage;
// Default setting for the language control
// WPLanguageControl1.GlobalLanguage := 'EN'; -
// We select the first entry !
WPLanguageControl1.GlobalLanguage :=
WPLanguageControl1.Find('/loc').Elements[0].Name;
SelectLanguage.ItemIndex := 0;
(** WPTOOLS 4 CODE
// The dialogs are updated when they are created the next time
WPLanguageControl1.AutoLoadStrings := TRUE;
// Load new VCL string: Toolbar Hints, actions, etc
WPLanguageControl1.LoadVCLStrings; *)
WPLangInterface := //WPTOOLS5
TWPLocalizationInterface.Create(WPLanguageControl1); //WPTOOLS5
WPTools_LoadVCLStrings; //WPTOOLS5
WPTools_LoadActionStrings; //WPTOOLS5
WPLocalizeLoadForms := TRUE; //WPTOOLS5
end;
procedure TWPTestLocalize.FormDestroy(Sender: TObject);
begin
FreeAndNil(WPLangInterface); //WPTOOLS5
end;
procedure TWPTestLocalize.FormCloseQuery(Sender: TObject;
var CanClose: Boolean);
begin
end;
// Display the selected Dialog
procedure TWPTestLocalize.ShowDialogClick(Sender: TObject);
begin
if RadioGroup1.ItemIndex>=0 then
(RadioGroup1.Items.Objects[RadioGroup1.ItemIndex] as TWPCustomAttrDlg).Execute;
end;
// Check which sub nodes we have in the localization control
procedure TWPTestLocalize.UpdateSelectLanguage;
var i : Integer;
loc : TWPXMLOneLevel;
begin
loc := WPLanguageControl1.Find('/loc');
SelectLanguage.Items.Clear;
if loc=nil then
ShowMessage('The information in WPLanguageControl1 has no branch "/loc"')
else for i:=0 to loc.Count-1 do
SelectLanguage.Items.Add(loc[i].Name);
end;
// SaveLanguageClick is NOT required!
// It is used to save all the strings on the dialogs and the VCL strings to
// a file. You can then load this file into the TWPLanguageControl
// and modify it there.
// But you can also use the strings which *are* already in the WPLanguageControl1
// and create copies of the branches
procedure TWPTestLocalize.SaveLanguageClick(Sender: TObject);
var
i: Integer;
f : string;
begin
f := ExtractFilePath(Application.EXEName)+'wplang.xml';
try
WPLocalizeSaveForms := TRUE; //WPTOOLS5
WPTools_SaveVCLStrings; //WPTOOLS5
WPTools_SaveActionStrings; //WPTOOLS5
for i:=0 to RadioGroup1.Items.Count-1 do
(RadioGroup1.Items.Objects[i] as TWPCustomAttrDlg)._CreateFormAndFree;
// This saves all other definitions, too
WPLanguageControl1.SaveToFile(f);
finally
WPLocalizeSaveForms := FALSE;
ShowMessage('Created the file ' + f);
end;
end;
procedure TWPTestLocalize.SelectLanguageClick(Sender: TObject);
begin
end;
// Select a new language branch
procedure TWPTestLocalize.UpdateClick(Sender: TObject);
begin
WPLanguageControl1.GlobalLanguage := SelectLanguage.Text;
// Load new VCL string: Toolbar Hints, actions, etc
(* WPLanguageControl1.LoadVCLStrings;
// The dialogs are updated when they are created the next time *)
WPTools_LoadVCLStrings; //WPTOOLS5
WPTools_LoadActionStrings; //WPTOOLS5
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -