📄 langmgr.pas
字号:
end;
end;
end;
if FFontInited then
begin
Form.Font.Name := FLangFontData.Name;
Form.Font.Size := FLangFontData.Size;
Form.Font.Charset := FLangFontData.Charset;
end;
end;
function TLangMgrBase.Trans(Src: string): string;
begin
GetMiscString(Src, Result);
end;
function TLangMgrBase.Trans(Src: string; Args: array of const): string;
begin
Result := Format(Trans(Src), Args);
end;
{ TTDBLangMgr }
constructor TTDBLangMgr.Create;
begin
inherited;
FTinyDatabase := TTinyDatabase.Create(nil);
FFormTable := TTinyTable.Create(nil);
FMiscTable := TTinyTable.Create(nil);
FDBStream := TMemoryStream.Create;
end;
destructor TTDBLangMgr.Destroy;
begin
FTinyDatabase.Free;
FFormTable.Free;
FMiscTable.Free;
FDBStream.Free;
inherited;
end;
function TTDBLangMgr.IsLangFile(FileName: string): Boolean;
var
TinyDB: TTinyDatabase;
begin
Result := False;
if not TTinyDatabase.IsTinyDBFile(FileName) then Exit;
TinyDB := TTinyDatabase.Create(nil);
try
try
TinyDB.DatabaseName := FileName;
TinyDB.Open;
if (TinyDB.TableDefs.IndexOf('Info') = -1) or
(TinyDB.TableDefs.IndexOf('Form') = -1) or
(TinyDB.TableDefs.IndexOf('Misc') = -1) then Exit;
except
Exit;
end;
finally
TinyDB.Free;
end;
Result := True;
end;
function TTDBLangMgr.GetLangNameFromFileName(FileName: string): string;
var
InfoTable: TTinyTable;
begin
Result := '';
InfoTable := TTinyTable.Create(nil);
try
try
InfoTable.DatabaseName := FileName;
InfoTable.TableName := 'Info';
InfoTable.IndexName := 'Name';
InfoTable.Open;
if InfoTable.FindKey(['Language']) then
Result := InfoTable.FieldByName('Value').AsString;
except
end;
finally
InfoTable.Close;
InfoTable.Free;
end;
end;
function TTDBLangMgr.GetFormString(Name: string; var Value: string): Boolean;
begin
Result := False;
if FFormTable.Active then
begin
try
Result := FFormTable.FindKey([Name]);
if Result then Value := FFormTable.FieldByName('Value').AsString;
except
Result := False;
end;
end;
if not Result then Value := '';
end;
function TTDBLangMgr.GetMiscString(Name: string; var Value: string): Boolean;
begin
Result := False;
if FMiscTable.Active then
begin
try
Result := FMiscTable.FindKey([Name]);
if Result then Value := FMiscTable.FieldByName('Value').AsString;
except
Result := False;
end;
end;
if not Result then Value := Name;
end;
function TTDBLangMgr.GetFontData(var FontData: TLangFontData): Boolean;
var
InfoTable: TTinyTable;
begin
Result := True;
InfoTable := TTinyTable.Create(nil);
try
try
with InfoTable do
begin
DatabaseName := SLangMgrDbName;
TableName := 'Info';
IndexName := 'Name';
Open;
end;
if InfoTable.FindKey(['FontName']) then
FontData.Name := InfoTable.FieldByName('Value').AsString
else
Result := False;
if InfoTable.FindKey(['FontSize']) then
FontData.Size := StrToInt(InfoTable.FieldByName('Value').AsString)
else
Result := False;
if InfoTable.FindKey(['FontCharset']) then
FontData.Charset := StrToInt(InfoTable.FieldByName('Value').AsString)
else
Result := False;
except
Result := False;
end;
finally
InfoTable.Close;
InfoTable.Free;
end;
end;
function TTDBLangMgr.InternalInitLang(Index: Integer): Boolean;
begin
Result := True;
try
FDBStream.LoadFromFile(FLangItems[Index].FileName);
with FTinyDatabase do
begin
Close;
MediumType := mtMemory;
DatabaseName := SLangMgrDbName;
FileName := PointerToStr(FDBStream);
Open;
end;
with FFormTable do
begin
Close;
DatabaseName := SLangMgrDbName;
TableName := 'Form';
IndexName := 'Name';
Open;
end;
with FMiscTable do
begin
Close;
DatabaseName := SLangMgrDbName;
TableName := 'Misc';
IndexName := 'Name';
Open;
end;
except
Result := False;
end;
end;
{ TIniLangMgr }
constructor TIniLangMgr.Create;
begin
inherited;
end;
destructor TIniLangMgr.Destroy;
begin
FIniFile.Free;
inherited;
end;
function TIniLangMgr.GetFormString(Name: string; var Value: string): Boolean;
begin
Result := False;
if Assigned(FIniFile) then
begin
Result := FIniFile.ValueExists('Form', Name);
if Result then
Value := FIniFile.ReadString('Form', Name, Value);
end;
end;
function TIniLangMgr.GetMiscString(Name: string; var Value: string): Boolean;
begin
Result := False;
if Assigned(FIniFile) then
begin
Result := FIniFile.ValueExists('Misc', Name);
if Result then
Value := FIniFile.ReadString('Misc', Name, Name)
else
Value := Name;
end;
end;
function TIniLangMgr.GetFontData(var FontData: TLangFontData): Boolean;
begin
Result := True;
try
if FIniFile.ValueExists('Info', 'FontName') then
FontData.Name := FIniFile.ReadString('Info', 'FontName', '')
else
Result := False;
if FIniFile.ValueExists('Info', 'FontSize') then
FontData.Size := FIniFile.ReadInteger('Info', 'FontSize', 9)
else
Result := False;
if FIniFile.ValueExists('Info', 'FontCharset') then
FontData.Charset := FIniFile.ReadInteger('Info', 'FontCharset', 1)
else
Result := False;
finally
end;
end;
function TIniLangMgr.GetLangNameFromFileName(FileName: string): string;
var
IniFile: TIniFile;
begin
IniFile := TIniFile.Create(FileName);
try
Result := IniFile.ReadString('Info', 'Language', '');
finally
IniFile.Free;
end;
end;
function TIniLangMgr.InternalInitLang(Index: Integer): Boolean;
begin
Result := True;
try
FIniFile.Free;
FIniFile := TIniFile.Create(FLangItems[Index].FileName);
except
Result := False;
end;
end;
function TIniLangMgr.IsLangFile(FileName: string): Boolean;
var
IniFile: TIniFile;
begin
Result := True;
IniFile := TIniFile.Create(FileName);
try
if not IniFile.SectionExists('Form') then Result := False;
if not IniFile.SectionExists('Misc') then Result := False;
if not IniFile.SectionExists('Info') then Result := False;
finally
IniFile.Free;
end;
end;
initialization
AppLangMgr := TTDBLangMgr.Create;
finalization
AppLangMgr.Free;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -