1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187:
| unit Translation;
interface uses IniFiles, Forms, SysUtils, Buttons, StdCtrls, ComCtrls, Classes;
type TTranslation = class private progPath: String;
public Constructor Create; overload; procedure translateFormElements(selectedForm: TForm); function translate(aToTrans: String):String; end;
implementation Constructor TTranslation.Create(); begin progPath:= ExtractFilePath(ParamStr(0)); if progPath[Length(progPath)]<>'\' then progPath := progPath + '\'; end;
function TTranslation.translate(aToTrans: String):String; var f_conf : TIniFile; f_lang : TIniFile; lang : String; begin if (FileExists(progPath + 'data\conf\settings.ini')) then begin f_conf := TIniFile.Create(progPath + 'data\conf\settings.ini'); with f_conf do begin lang := ReadString('config','language','de'); end; end else lang := 'de';
if (FileExists(progPath + 'data\lang\' + lang + '.ini')) then f_lang := TIniFile.Create(progPath + 'data\lang\' + lang + '.ini');
with f_lang do begin aToTrans := ReadString('translations',aToTrans,'no_translation'); aToTrans := StringReplace(aToTrans,'\n',sLineBreak,[rfReplaceAll]); end;
Result:= aToTrans; end;
procedure TTranslation.translateFormElements(selectedForm: TForm); var f_conf : TIniFile; f_lang : TIniFile; c_tmp : Integer; c_tmpClass: TClass; lang : String; i,a : Integer; sList : TStrings; begin with selectedForm do begin if (FileExists(progPath + 'data\conf\settings.ini')) then begin f_conf := TIniFile.Create(progPath + 'data\conf\settings.ini'); with f_conf do begin lang := ReadString('config','language','de'); end; end else lang := 'de';
if (FileExists(progPath + 'data\lang\' + lang + '.ini')) then f_lang := TIniFile.Create(progPath + 'data\lang\' + lang + '.ini');
with f_lang do begin for i := 0 to (ComponentCount - 1) do if (Components[i].ClassType = TLabel) then begin with (Components[i]) as TLabel do begin lang := Caption; if (Pos('text_',lang) > 0) then begin lang := StringReplace(lang,'text_','',[rfReplaceAll]); lang := ReadString('translations',lang,''); lang := StringReplace(lang,'\n',sLineBreak,[rfReplaceAll]); if (lang <> '') then Caption:= lang; end; end; end else if (Components[i].ClassType = TGroupBox) then begin with (Components[i]) as TGroupBox do begin lang := Caption; if (Pos('text_',lang) > 0) then begin lang := StringReplace(lang,'text_','',[rfReplaceAll]); lang := ReadString('translations',lang,''); if (lang <> '') then Caption:= ' ' + lang + ' '; end; end; end else if (Components[i].ClassType = TEdit) then begin with (Components[i]) as TEdit do begin lang := Text; if (Pos('text_',lang) > 0) then begin lang := StringReplace(lang,'text_','',[rfReplaceAll]); lang := ReadString('translations',lang,''); lang := StringReplace(lang,'\n',sLineBreak,[rfReplaceAll]); if (lang <> '') then Text:= lang; end; end; end else if (Components[i].ClassType = TSpeedButton) then begin with (Components[i]) as TSpeedButton do begin lang := Caption; if (Pos('text_',lang) > 0) then begin lang := StringReplace(lang,'text_','',[rfReplaceAll]); lang := ReadString('translations',lang,''); lang := StringReplace(lang,'\n',sLineBreak,[rfReplaceAll]); if (lang <> '') then Caption:= lang; end; end; end else if (Components[i].ClassType = TRadioButton) then begin with (Components[i]) as TRadioButton do begin lang := Caption; if (Pos('text_',lang) > 0) then begin lang := StringReplace(lang,'text_','',[rfReplaceAll]); lang := ReadString('translations',lang,''); lang := StringReplace(lang,'\n',sLineBreak,[rfReplaceAll]); if (lang <> '') then Caption:= lang; end; end; end else if (Components[i].ClassType = TCheckBox) then begin with (Components[i]) as TCheckBox do begin lang := Caption; if (Pos('text_',lang) > 0) then begin lang := StringReplace(lang,'text_','',[rfReplaceAll]); lang := ReadString('translations',lang,''); lang := StringReplace(lang,'\n',sLineBreak,[rfReplaceAll]); if (lang <> '') then Caption:= lang; end; end; end else if (Components[i].ClassType = TTabControl) then begin with (Components[i]) as TTabControl do begin for a := 0 to (Tabs.Count - 1) do begin lang := Tabs.Strings[a]; if (Pos('text_',lang) > 0) then begin lang := StringReplace(lang,'text_','',[rfReplaceAll]); lang := ReadString('translations',lang,''); lang := StringReplace(lang,'\n',sLineBreak,[rfReplaceAll]); if (lang <> '') then Tabs.Strings[a]:= lang; end; end; end; end; end; end; end;
end. |