📄 localize.pas
字号:
unit localize;
interface
uses
SysUtils, Forms, Classes, ComCtrls, Buttons, StdCtrls, ExtCtrls,
inifiles, dialogs,checklst,menus,graphics,Grids;
procedure localizeControls(form:TForm);
function localizeString(value:string):string;
const
lng_id='rfe_';
implementation
uses main_u;
function ConvertLineBreak(s:string):string;
var p:integer;
begin
p:=pos('\n',s);
while p>0 do
begin
s[p]:=#13;
s[p+1]:=#10;
p:=pos('\n',s);
end;
result:=s;
end;
function RemoveNumber(str:string):string;
begin
result:=str;
while result[length(result)] in ['0'..'9','.'] do
delete(result,length(result),1);
end;
procedure localizeControls(form:TForm);
var i,j:integer;
c:TComponent;
ini:Tinifile;
s,cname:string;
begin
if FileExists(extractfilepath(paramstr(0))+lng_id+Form_RFEMain.CB_Language.text+'.lng') then
begin
ini:=Tinifile.create(extractfilepath(paramstr(0))+lng_id+Form_RFEMain.CB_Language.text+'.lng');
s:=ini.ReadString('Main','Font','');
if s<>'' then form.Font.Name:=s;
s:=ini.ReadString('Main','Charset','DEFAULT_CHARSET');
if s<>'DEFAULT_CHARSET' then
begin
IdentToCharset(s,j);
form.Font.Charset:=j;
end;
for i:=0 to form.ComponentCount-1 do
begin
if (form.Components[i] is TComponent) then
begin
c:=(form.Components[i] as TComponent);
if (c is TListview) then
begin
for j:=1 to (c as TListview).Columns.count do
begin
s:=ConvertLineBreak(ini.ReadString('controls',c.name+'.'+inttostr(j),''));
if s<>'' then (c as TListview).Columns[j-1].caption:=s;
end;
s:=ConvertLineBreak(ini.ReadString('controls',c.name+'.hint',''));
if s<>'' then (c as TListview).Hint:=s;
end else if (c is TCheckListBox) then
begin
for j:=1 to (c as TCheckListbox).items.count do
begin
s:=ConvertLineBreak(ini.ReadString('controls',c.name+'.'+inttostr(j),''));
if s<>'' then (c as TCheckListbox).items.Strings[j-1]:=s;
end; //for CheckListbox.items
end else if (c is TStringgrid) then
begin
for j:=1 to (c as TStringgrid).RowCount do
begin
s:=ConvertLineBreak(ini.ReadString('controls',c.name+'.'+inttostr(j),''));
if s<>'' then (c as TStringgrid).Cells[0,j-1]:=s;
end; //for Stringgrid.rowcount
end else if (c is TCombobox) then
begin
for j:=1 to (c as TCombobox).items.count do
begin
s:=ini.ReadString('controls',c.name+'.'+inttostr(j),'');
if s<>'' then (c as TCombobox).items.Strings[j-1]:=s;
end;
end else
begin
cname:=c.name;
//making menu-captions same as toolbutton-hints
if copy(cname,1,3)='MI_' then cname:='TB_'+copy(cname,4,length(cname)-3);
s:=ConvertLineBreak(ini.ReadString('controls',RemoveNumber(cname),''));
if s<>'' then
begin
if (c is TCheckbox) then (c as Tcheckbox).caption:=s;
if (c is TLabel) then (c as TLabel).caption:=s;
if (c is TSpeedButton) then (c as TSpeedButton).caption:=s;
if (c is TButton) then (c as TButton).caption:=s;
if (c is TRadioButton) then (c as TRadioButton).caption:=s;
if (c is TMenuitem) then (c as TMenuitem).caption:=s;
if (c is TToolButton) then (c as TToolbutton).Hint:=s;
if (c is TTabsheet) then (c as TTabsheet).caption:=s;
if (c is TGroupBox) then (c as TGroupBox).caption:=s;
if (c is TRadiogroup) then
begin
(c as TRadioGroup).caption:=s;
//if not (c=Form_TsctMain.RdGrp_Eol) then
//begin
for j:=1 to (c as TRadioGroup).items.count do
begin
s:=ConvertLineBreak(ini.ReadString('controls',c.name+'.'+inttostr(j),''));
if s<>'' then (c as TRadioGroup).items.Strings[j-1]:=s;
end; //for radiogroup.items
//end; //c=RdGrp_eol
end; //c is TRadiogroup
end; //s<>''
end; //not a font-panel
end; //c is TComponent
end; //for 0 to component.count-1
ini.free;
end; //languagefile present
end;
function localizeString(value:string):string;
var ini:Tinifile;
s:string;
begin
ini:=Tinifile.create(extractfilepath(paramstr(0))+lng_id+Form_RFEMain.CB_Language.text+'.lng');
s:=convertLineBreak(ini.ReadString('Strings',value,''));
if s='' then
begin
if value='Msg_IDExists' then s:='Kenner %s ist doppelt belegt';
if value='Msg_NoFile' then s:='keine datei 黚ergeben';
if value='Msg_NothingToCompile' then s:='Keine Resource zum Compilieren';
if value='Msg_CompilerNotFound' then s:='Compiler nicht gefunden!';
if value='Msg_MissingInput' then s:='fehlende Eingabe';
if value='Msg_ParseError' then s:='Parsingfehler';
if value='Msg_NothingSelected' then s:='Kein Eintrag markiert';
if value='Msg_MustRestart' then s:='Sie m黶sen RFE neu starten um diese Funktion zu aktivieren';
if value='Msg_GetVersionError' then s:='Fehler beim holen der Versionsdaten';
if value='Ask_VisitWebpage' then s:='neuere Version vorhanden (%s)'+#13#13+
'M鯿hten Sie zur Projektseite wechseln, um die neue Version zu downloaden?';
if value='Ask_Delete' then s:='M鯿hten Sie die markierten Eintr鋑e l鰏chen?';
end;
ini.free;
result:=ConvertLineBreak(s);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -