-
Notifications
You must be signed in to change notification settings - Fork 0
/
pafLang.pas
124 lines (99 loc) · 5.74 KB
/
pafLang.pas
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
unit pafLang;
interface
uses
Vcl.Controls, forms;
function fCreateLangIniFiles(varPath:string):boolean;
function fReadIniToVariable(varPath, varLang:string):boolean;
function fSetLangToForm(varFmName:string; varObject:TWinControl):boolean;
implementation
uses
System.SysUtils,
System.IOUtils,
Vcl.ComCtrls,
Vcl.StdCtrls,
json,
gVariables,
pafIni;
//******************************************************************************
//Ñîçäàíèå INI ôàéëà ñ íàñòðîéêàìè ÿçûêà äëÿ âñåõ êîìïîíåíò ïðîãðàììû
//varPath - ïóòü äî ïàïêè ãäå ëåæàò ôàéëû ñ ÿçûêàì
//******************************************************************************
function fCreateLangIniFiles(varPath:string):boolean;
begin
Write_ini_str('fmStart', 'TabEnter', 'Enter', varPath + '\ENG.ini');
Write_ini_str('fmStart', 'TabEnter', 'Âõîä', varPath + '\RUS.ini');
Write_ini_str('fmStart', 'GroupBoxUser', 'Login', varPath + '\ENG.ini');
Write_ini_str('fmStart', 'GroupBoxUser', 'Ïîëüçîâàòåëü', varPath + '\RUS.ini');
Write_ini_str('fmStart', 'GroupBoxPassword', 'Password', varPath + '\ENG.ini');
Write_ini_str('fmStart', 'GroupBoxPassword', 'Ïàðîëü', varPath + '\RUS.ini');
Write_ini_str('fmStart', 'TabDatabase', 'Database', varPath + '\ENG.ini');
Write_ini_str('fmStart', 'TabDatabase', 'Áàçà äàííûõ', varPath + '\RUS.ini');
Write_ini_str('fmStart', 'GroupBoxDatabasePath', 'Path', varPath + '\ENG.ini');
Write_ini_str('fmStart', 'GroupBoxDatabasePath', 'Ïóòü', varPath + '\RUS.ini');
Write_ini_str('fmStart', 'GroupBoxDatabaseLogin', 'Login', varPath + '\ENG.ini');
Write_ini_str('fmStart', 'GroupBoxDatabaseLogin', 'Ïîëüçîâàòåëü', varPath + '\RUS.ini');
Write_ini_str('fmStart', 'GroupBoxDatabasePassword', 'Password', varPath + '\ENG.ini');
Write_ini_str('fmStart', 'GroupBoxDatabasePassword', 'Ïàðîëü', varPath + '\RUS.ini');
Write_ini_str('fmStart', 'GroupBoxDatabaseIPaddress', 'IP address', varPath + '\ENG.ini');
Write_ini_str('fmStart', 'GroupBoxDatabaseIPaddress', 'IP àäðåñ ', varPath + '\RUS.ini');
end;
//******************************************************************************
//******************************************************************************
//******************************************************************************
//÷òåíèå ini ôàéëà ñ âûáðàíûì ÿçûêîì â ãëîáàëüíóþ ïåðåìåííóþ ñîäåðæàùàÿ íàçâàíèÿ âñåõ êîìïîíåíò â ïðîãðàììå
//varPath - ïóòü äî ïàïêè ñ ÿçûêîì
//varLang - ÿçûê = èìÿ ôàéëà
//******************************************************************************
function fReadIniToVariable(varPath, varLang:string):boolean;
var
F : TextFile;
S : String;
varKey:string;
varValue:string;
varSection:string;
begin
gvarLangIni.Clear; //î÷èùàåì ñëîâàðü
varPath := varPath + '\' + varLang + '.ini'; //ìîäèôèöèðóåì ïóòü äî ôàéëû ñ ini ôàéëîì
AssignFile(F,varPath);
Reset(F); // ×èòàåì ôàéë ïîñòðî÷íî, â öèêëå , ãäå :
while NOT EoF(F) do // EoF - êîíåö ôàéëà, (End Of File). Â öèêëå -
begin
ReadLn(F,S); // áåðåì ñòðîêó, è
if Pos('[', S) <> 0 then varSection := Copy( S, 2, Length(S) - 2 ); // åñëè ýòî ñåêöèÿ çàïèñûâàåì íàçâàíèå
if Pos('=', S) <> 0 then // åñëè ýòî êëþ÷=çíà÷åíèå òî íà÷èíàåì ïîëó÷àòü çíà÷åíèÿ
begin
if Pos('=', S) <> 0 then varKey := varSection + '.' + Copy(S, 1, Pos('=', S)-1); //êîïèðóåì êëþ÷, è äåëàåì êîíêðàòèíàöèþ ñ ñåêöèåé
if Pos('=', S) <> 0 then varValue := Copy(S, Pos('=', S)+1, Length(S) - Pos('=',S));//êîïèðóåì çíà÷åíèå
gvarLangIni.Add(varKey, varValue); //äîáàâëÿåì ïàðó êëþ÷=çíà÷åíèå â ñëîâàðü
end;
end;
end;
//******************************************************************************
//******************************************************************************
//******************************************************************************
//óñòàíàâëèâàåì èìåíà îáúåêòîâ â êîìïîíåíòû
//varFmName - èìÿ ôîðìû ãäå áóäåò ìåíÿòñÿ ÿçûê
//varObject - ôîðìà ãäå íàõîäÿòñÿ îáúåêòû
//******************************************************************************
function fSetLangToForm(varFmName:string; varObject:TWinControl):boolean;
var
i:integer;
varControl:Tcontrol;
varText: string;
begin
for i:=0 to varObject.ControlCount - 1 do //ïåðåáèðàåì âñå êîìïîíåíòû íà ôîðìå
begin
varControl := varObject.Controls[i]; //çàïèñûâàåì ññûëêó íà îáúåêò â ïåðåìåííóþ
varText := varFmName + '.' + varControl.Name; //
if gvarLangIni.ContainsKey(varText) then //åñëè åñòü êëþ÷ ñ ýòèì èìåíåì (èìåíåìå ôîðìû + èìÿ êîìïîíåíòà íà ôîðìå) òî
begin //
if (varControl is TTabSheet) then (varControl as TTabSheet).Caption := gvarLangIni[varText]; //ïðîâåðÿåì ÷òî çà îáúåêò è ïðèâîäèì åãî ê ýòîìó âèäó ïðèñâàèâàÿ îïèñàíèå
if (varControl is TGroupBox) then (varControl as TGroupBox).Caption := gvarLangIni[varText];
end;
//ïðîâåðÿåì ÿâëÿåòñÿ ëè îáúåêò îáúåêòîì êîòîðû ìîæåò ñîäåðæàòü äðóãèå ýëåìåíòû
if (varControl is TPageControl) then fSetLangToForm(varFmName, (varControl as TPageControl)); //îáúåêò ìîæåò ñîäåðæàòü äðóãèå îáåúêòû, ïîýòîìó ïåðåäàåì èìÿ ôîðìû (äëÿ ïîèñêà íóæíîãî êëþ÷à) è ñàì îáúåêò
if (varControl is TTabSheet) then fSetLangToForm(varFmName, (varControl as TTabSheet));
end;
end;
end.
end.