summaryrefslogtreecommitdiff
path: root/tools/langpackmgr/Unit1.pas
blob: 6de5df25fccfc7d1c3971e551a27466009cdae4e (plain)
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
unit unit1;

interface

uses
  classes, sysutils, fileutil, forms, controls, graphics, dialogs, stdctrls,
  extctrls, Windows;

type

  { tform1 }

  tform1 = class(tform)
    button1: tbutton;
    button2: tbutton;
    button3: tbutton;
    button4: tbutton;
    CheckBox1: TCheckBox;
    memo1: tmemo;
    memo2: tmemo;
    listbox: tlistbox;
    combobox1: tcombobox;
    combobox2: tcombobox;
    radiogroup1: tradiogroup;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure combobox1change(sender: tobject);
    procedure ComboBox2Change(Sender: TObject);
    procedure formcreate(sender: tobject);
    procedure listbox1click(sender: tobject);
    procedure listbox2click(sender: tobject);
    procedure stringview;
    procedure savestring;
    procedure stringlist;

  private
    { private declarations }
  public
    { public declarations }
  end;

var
  form1: tform1;
  locale: string;
  z,j,i,l:integer;
  sr:tsearchrec;
  res:integer;
  s:array[0..1,1..6000] of string;
  u:array[0..6000] of integer;
  first:string;
  filename:string;
  im,m:integer;
  sse:string;
implementation

{$r *.lfm}

{ tform1 }




procedure tform1.stringlist;
 var llist:TStringList;
  begin
  for i := 1 to 6000 do
         begin s[0,i]:='';s[1,i]:='';end;
       j:=0;
   lList:=TstringList.Create;
       lList.LoadFromFile(extractfilePath(application.exename)+'/english/'
       +combobox1.items[combobox1.itemindex]+'.txt');
       first:=lList[0];
       for i := 1 to lList.Count-1 do
           begin
             j:=j+1;
             s[0,j]:=lList[i];
           end;
          lList.LoadFromFile(extractfilePath(application.exename)+'/'
     +locale+'/'+combobox1.items[combobox1.itemindex]+'.txt');
       for z:= 1 to j do
         for i := 1 to lList.count-2 do
           if (copy(s[0,z],1,1)='[')and(s[0,z]=lList[i])
           and (copy(lList[i+1],1,1)<>'[')then
             s[1,z]:=lList[i+1];
       lList.free;
       form1.Caption:='Miranda NG Langpack Tools: Editor -'
       +locale+'\'+combobox1.items[combobox1.itemindex];
       filename:=combobox1.items[combobox1.itemindex];
       listbox.items.Clear;
       z:=0;
       for i := 1 to j do
         if ((copy(s[0,i],1,1)='[')and(s[1,i]='') and (radiogroup1.ItemIndex=0))
         or ((copy(s[0,i],1,1)='[')and (radiogroup1.ItemIndex=1))
         then
           begin
             u[z]:=i;
             z:=z+1;
             listbox.items.add(copy(s[0,i],2,length(s[0,i])-2));
         end;
  end;

procedure tform1.stringview;
  begin
    sse:=copy(s[0,u[listbox.itemindex]],2,
    length(s[0,u[listbox.itemindex]])-2);
    m:=1;
    for im := 1 to length(sse)-1 do
        begin
          if copy(sse,im,2)='\n' then
          begin
            memo1.Lines.Add(copy(sse,m,im-m));
            m:=im+2;
          end;
        end;
    memo2.Lines.Clear;
    l:=listbox.itemindex;
    if m=1 then  memo1.Lines.Add(sse)
    else memo1.Lines.Add(copy(sse,m,length(sse)-m+2));
   if s[1,u[listbox.itemindex]]<>'' then
    begin
      m:=1;
      for im := 1 to length(s[1,u[listbox.itemindex]])-1 do
        begin
          if copy(s[1,u[listbox.itemindex]],im,2)='\n' then
          begin
            memo2.Lines.Add(copy(s[1,u[listbox.itemindex]],m,im-m));
            m:=im+2;
          end;
        end;
    if m=1 then  memo2.Lines.Add(s[1,u[listbox.itemindex]])
    else memo2.Lines.Add(copy(s[1,u[listbox.itemindex]],m,
    length(s[1,u[listbox.itemindex]])-m+2));
    end;
   end;

procedure tform1.savestring;
var sa:integer;
begin
 s[1,u[l]]:='';
 for sa:=0 to memo2.Lines.Count-1 do
   begin
     s[1,u[l]]:=s[1,u[l]]+memo2.Lines[sa];
     if sa<>memo2.Lines.Count-1 then  s[1,u[l]]:=s[1,u[l]]+'\n';
   end;
end;

procedure tform1.formcreate(sender: tobject);
  var
  sr:tsearchrec;
  res:integer;
begin
  if (paramstr(1)='-r') then
    begin
    form1.caption:='Miranda NG Langpack Tools: Replacer';

    end else
    begin
  res:=findfirst(extractfilepath(application.exename)+'*',faanyfile,sr);
  while res = 0 do
      begin
        if ((sr.attr and fadirectory)=fadirectory)
        and ((sr.name='.')or(sr.name='..')) then
          begin res:=findnext(sr); continue; end;
        if ((sr.attr and fadirectory)=fadirectory)
        and (fileexists(extractfilepath(application.exename)+
        '/'+sr.name+'/=head=.txt')) and (sr.name<>'english') then
          ListBox.items.add(sr.name);
        res:=findnext(sr);
      end;
    SysUtils.FindClose(sr);
end;

end;

procedure tform1.combobox1change(sender: tobject);
  var
  f:textfile;
begin
  if not FileExists(extractfilePath(application.exename)
      +'/'+locale+'/'+combobox1.items[combobox1.itemindex]+'.txt')
      then
      begin
      assignfile(f,extractfilePath(application.exename)
      +'/'+locale+'/'+combobox1.items[combobox1.itemindex]+'.txt');
      rewrite(f);
      closefile(f);
      end;
   stringlist;
   memo1.lines.clear;
   memo2.lines.clear;
end;

procedure tform1.ComboBox2Change(Sender: TObject);
begin

end;

procedure tform1.Button1Click(Sender: TObject);
  var sList:TStringList;
  begin
    savestring;
    sList:=TstringList.Create;
    sList.add(first);
    for i := 0 to j do
      begin
        if copy(s[0,i],1,1)=';' then
          sList.add(s[0,i]);
        if s[1,i]<>'' then
          begin
            sList.add(s[0,i]);
            sList.add(s[1,i]);
          end
        else
        if (copy(s[0,i],1,1)='[')and
        (fileexists(extractfilePath(application.exename)+'clearstring.ini'))then
          begin
          sList.add(s[0,i]);
          sList.add('');
          end;
      end;
  sList.SavetoFile(extractfilePath(application.exename)
  +'/'+locale+'/'+filename+'.txt');
  sList.free;
  stringview;
end;

procedure tform1.Button4Click(Sender: TObject);
  var str:utf8string; i:integer;
   begin
   str:='http://translate.google.com/?hl=&ie=yhgg#auto/';
   if  locale='belarusian' then str:=str+'be/';
   if  locale='bulgarian' then str:=str+'bg/';
   if  locale='chinese' then str:=str+'zh-CN/';
   if  locale='czech' then str:=str+'cs/';
   if  locale='dutch' then str:=str+'da/';
   if  locale='estonian' then str:=str+'et/';
   if  locale='french' then str:=str+'fr/';
   if  locale='german' then str:=str+'de/';
   if  locale='hebrew' then str:=str+'iw/';
   if  locale='hungarian' then str:=str+'hu/';
   if  locale='italian' then str:=str+'it/';
   if  locale='japanese' then str:=str+'ja/';
   if  locale='korean' then str:=str+'ko/';
   if  locale='norwegian' then str:=str+'no/';
   if  locale='polish' then str:=str+'pl/';
   if  locale='portuguese_br' then str:=str+'pt/';
   if  locale='russian' then str:=str+'ru/';
   if  locale='slovak' then str:=str+'sk/';
   if  locale='spanish' then str:=str+'es/';
   if  locale='turkish' then str:=str+'tr/';
   if  locale='ukrainian' then str:=str+'uk/';
   for i:=0 to memo1.Lines.Count-1 do
      begin
      str:=str+memo1.Lines[i];
      if i<memo1.Lines.Count-1 then
      str:=str+'+%0A+';
      end;
   ShellExecute(0, 'open',PChar(str), nil, nil, SW_SHOW);
end;

procedure tform1.Button2Click(Sender: TObject);
 var search:TStringList;
q:integer;
begin
search:=TstringList.Create;
search.LoadFromFile(extractfilePath(application.exename)+
'/'+locale+'/'+'Langpack_'+locale+'.txt');
for q := 0 to listbox.items.Count-1 do
for i := 1 to search.count-1 do
 if (s[0,u[q]]=search[i])and(copy(search[i+1],1,1)<>'[')then
 begin
  s[1,u[q]]:=search[i+1];
  break;
 end;
search.free;
end;

procedure tform1.Button3Click(Sender: TObject);
begin
memo2.lines:=memo1.lines;
end;

procedure tform1.ListBox1Click(sender: tobject);
begin
   if (form1.caption<>'Miranda NG Langpack Tools: Editor')
   then
      begin
        savestring;
        memo1.lines.clear;
        memo2.lines.clear;
{}
        stringview;
      end;
end;

procedure tform1.listbox2click(sender: tobject);
  var
  sr:tsearchrec;
  res:integer;
begin
  if form1.caption='Miranda NG Langpack Tools: Editor'
  then
    begin
      locale:=ListBox.items[listBox.itemindex];
      form1.caption:=form1.caption+': '+locale;
      ListBox.items.clear;
      combobox1.items.add('=CORE=');
      res:=findfirst(extractfilepath(application.exename)
  +'\english\plugins\*.txt', faanyfile, sr);
  while res = 0 do
    begin
      combobox1.items.add('plugins\'+copy(extractfilename(sr.name),1,
      length(extractfilename(sr.name))-4));
      res:=findnext(sr);
    end;
  SysUtils.FindClose(sr);
  res:=findfirst(extractfilepath(application.exename)
  +'\english\weather\*.txt', faanyfile, sr);
  while res = 0 do
    begin
      combobox1.items.add('weather\'+copy(extractfilename(sr.name),1,
      length(extractfilename(sr.name))-4));
      res:=findnext(sr);
    end;
  SysUtils.FindClose(sr);
    end;

  combobox1.itemindex:=0;
  stringlist;
  if (fileexists(extractfilePath(application.exename)+'/'+locale+'/'
  +'Langpack_'+locale+'.txt'))  then button2.Enabled:=true;

end;

end.