unit Tobbnyelv; {$F+} (********************************************************** Többnyelvü kezelői felület interfész ==================================== Szerző: Fogler Tibor http://www.robitbt.hu foglert@robitbt.hu Licensz: GNU/GPL szabad szoftver Felhasznált külső forrásból származó unitok: Bigini - köszönet a szerző(k)nek Utolsó modositás: 2007.09.07 Fogler Tibor Müködése ------- Ha Forditani := false akkor a rutin nem csinál semmit. Ha Forditani = True és a formnév.lng file még nem létezik akkor létrehozza azt a delphiben megtervezett tartalommal. ------------------------------------------------------------------ A nyelvi fájlok a beállítható Nyelvdir -ben vannak formname1.lng - formname1 formon lévő captionok, hint -ek formname2.lng - formname2 formon lévő captionok, hint -ek ....... stringstrasnlate.lng - szöveg konstansok FIGYELEM! Ez a rutin a Főmenü tartalmát nem kezeli. A főmenüt a MenuSaveLoad rutinnal lehet testre szabni illetve lefordítani. Használata: 1. Minden form onCreate -ba : atmeretezo(self) vagy atmeretezoC(self,color1,colr2) 2. Fő program uses -ba felvenni Tobbnyelv 3. Fő program onCreate -ban: Tobbnyelv.Forditani := True;; Tobbnyelv.NyelvDir := 'xxxxxx'; FormFordito(self); 4. A programban szereplő szövegkonstansokat helyettesíteni: StrFordito('konstans') alakkal. **********************************************************) interface uses SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls, Comctrls, FileCtrl, DBctrls, db, Forms, StdCtrls, Buttons, ExtCtrls, Menus, Mask, Stilus, BigIni; Procedure FormFordito(obj : TObject); Function StrFordito(be:string) : string; Procedure FieldsFordito(DS : Tdataset); var Forditani : Boolean; NyelvDir : string; implementation var VanHiba : Boolean; BFstr : TBiginiFile; BFstrStatus : Byte; // 0-nincs megnyitva, 1-megnyitva jó, 2-megnyitva hibás Procedure Fordito1(obj : Tobject; BF : TBiginiFile); var i : Integer; Function CaptionFordito(C:string) : string; var S : String; begin S := BF.ReadString('Translation',Tcontrol(Obj).name+'.caption','@'); if S = '@' then begin VanHiba := True; BF.WriteString('Translation',Tcontrol(Obj).name+'.caption', C); Result := C; end else begin Result := S; end; end; Function HintFordito(H:string) : string; var S : String; begin S := BF.ReadString('Translation',Tcontrol(Obj).name+'.hint','@'); if S = '@' then begin VanHiba := True; BF.WriteString('Translation',Tcontrol(Obj).name+'.hint', H); Result := H; end else begin Result := S; end; end; Function TextFordito(T:string) : string; var S : String; begin S := BF.ReadString('Translation',Tcontrol(Obj).name+'.hint','@'); if S = '@' then begin VanHiba := True; BF.WriteString('Translation',Tcontrol(Obj).name+'.hint', T); Result := T; end else begin Result := S; end; end; Procedure ItemsFordito(Itm : TStrings); var S : String; j : Integer; begin S := BF.ReadString('Translation',Tcontrol(Obj).name+'.items','@'); if S = '@' then begin VanHiba := True; S := ''; for j := 0 to Itm.count - 1 do S := S + Itm[j] + ';'; BF.WriteString('Translation',Tcontrol(Obj).name+'.items', S); end else begin Itm.clear; j := pos(';',S); while j > 0 do begin Itm.add(copy(S,1,j-1)); S := copy(S,j+1, Length(S)); j := pos(';',S); end; end; end; begin if (Obj is TMainMenu) then Exit; // obj forditása if (Obj is Tlabel) then begin with Tlabel(obj) do begin caption := CaptionFordito(caption); end; end; if (Obj is TSpeedButton) then begin with TSpeedButton(obj) do begin caption := CaptionFordito(caption); hint := HintFordito(Hint); end; end; if (Obj is TToolButton) then begin with TToolButton(obj) do begin hint := HintFordito(Hint); end; end; if (Obj is TButton) then begin with TButton(Obj) do begin caption := CaptionFordito(caption); hint := HintFordito(Hint); end; end; if (Obj is TCheckBox) then begin with TCheckBox(Obj) do begin caption := CaptionFordito(caption); hint := HintFordito(Hint); end; end; if (Obj is TRadioButton) then begin with TRadioButton(Obj) do begin caption := CaptionFordito(caption); hint := HintFordito(Hint); end; end; if (Obj is TDBCheckBox) then begin with TDBCheckBox(Obj) do begin caption := CaptionFordito(caption); hint := HintFordito(Hint); end; end; if (Obj is TComboBox) then begin with TComboBox(Obj) do begin hint := HintFordito(Hint); ItemsFordito(Items); end; end; if (Obj is TDBComboBox) then begin with TDBComboBox(Obj) do begin hint := HintFordito(Hint); ItemsFordito(Items); end; end; if (Obj is TGroupBox) then begin with TGroupBox(Obj) do begin caption := CaptionFordito(caption); hint := HintFordito(Hint); end; end; if (Obj is TPanel) then begin with TPanel(obj) do begin caption := CaptionFordito(caption); hint := HintFordito(Hint); end; end; if (Obj is TCustomListBox) then begin with TCustomListBox(Obj) do begin hint := HintFordito(Hint); ItemsFordito(Items); end; end; if (Obj is TCustomUpDown) then begin with TCustomUpDown(Obj) do begin hint := HintFordito(Hint); end; end; if (Obj is TRadioGroup) then begin with TRadioGroup(Obj) do begin caption := CaptionFordito(caption); hint := HintFordito(Hint); ItemsFordito(Items); end; end; if (Obj is TPanel) then begin with TPanel(Obj) do begin caption := CaptionFordito(Hint); hint := HintFordito(Hint); end; end; // az alá tartozóak forditása if (Obj is Twincontrol) and (not (Obj is TRadioGroup)) then begin with Twincontrol(obj) do for i := 0 to ControlCount - 1 do Fordito1(Controls[i], BF); end; end; Procedure FormFordito(obj : TObject); var Filenev : string; i : Integer; BiginiF : TBiginiFile; S : String; begin if not Forditani then Exit; VanHiba := false; if Nyelvdir <> '' then begin if Nyelvdir[Length(Nyelvdir)] = '\' then Nyelvdir := copy(Nyelvdir,1,Length(Nyelvdir)-1); if not DirectoryExists(Nyelvdir) then MkDir(nyelvdir); Filenev := Nyelvdir + '\' + Tcontrol(Obj).Name + '.lng'; end else begin Filenev := TControl(Obj).Name + '.lng'; end; BiginiF := TbiginiFile.create(Filenev); with TForm(Obj) do begin S := BiginiF.ReadString('Translation',Tcontrol(Obj).name+'.caption','@'); if S = '@' then begin VanHiba := True; BiginiF.WriteString('Translation',TControl(Obj).name+'.caption', Tform(obj).caption); end else begin Tform(obj).caption := S; end; for i := 0 to ControlCount - 1 do Fordito1(Controls[i],BiginiF); end; if VanHiba then BiginiF.FlushFile; BiginiF.free; end; Function StrFordito(be:string) : string; var S,Filenev : String; begin if Forditani then begin if Nyelvdir <> '' then begin if Nyelvdir[Length(Nyelvdir)] = '\' then Nyelvdir := copy(Nyelvdir,1,Length(Nyelvdir)-1); if not DirectoryExists(Nyelvdir) then MkDir(nyelvdir); Filenev := Nyelvdir + '\Strings.lng'; end else begin Filenev := 'Strings.lng'; end; if BFstrStatus = 0 then begin BFstr := TBiginiFile.create(Filenev); BFstrStatus := 1; end; with BFstr do begin S := ReadString('Translation',be,'@'); if S = '@' then begin WriteString('Translation',be,be); BFstrStatus := 2; Result := be; end else begin Result := S; end; end; end else begin Result := be; end; end; Procedure FieldsFordito(DS : Tdataset); var i : Integer; begin for i := 0 to DS.FieldCount - 1 do ds.Fields[i].displaylabel := StrFordito(ds.Fields[i].displaylabel); end; initialization Forditani := False; Nyelvdir := ''; BFstrStatus := 0; Finalization if BFstrstatus = 2 then BFstr.flushfile; if BFstrstatus > 0 then BFstr.free; end.