source: tools/Lazarus translator/UItemListForm.pas

Last change on this file was 9, checked in by george, 16 years ago
  • Upraveno: Program přepracován pro podporu více překladových souborů a hromadného sloučení s novějšími anglickými verzemi z repozitáře Lazarusu.
  • Upraveno: Adresářová struktura překladových souborů přepracována tak, aby souhlasila se strukturou adresářů repozitáře Lazarusu.
  • Upraveno: Překladové soubory aktualizovány na SVN verzi 0.9.27.
File size: 10.8 KB
Line 
1unit UItemListForm;
2
3{$mode objfpc}{$H+}
4
5interface
6
7uses
8 Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
9 ComCtrls, UItemTranslationForm, UTextFileStream, StdCtrls;
10
11const
12 LazarusRepository: string = '../../../../Lazarus/';
13 TranslationFolder: string = '../../trunk/';
14 TranslationMergeFolder: string = '../../tags/0.9.26/';
15 LocaleName: string = 'cz';
16
17 LanguageFiles: array[0..27] of string = (
18 'languages/lazaruside.po',
19 'languages/installerstrconsts.po',
20 'ideintf/languages/objinspstrconsts.po',
21 'lcl/languages/lclstrconsts.po',
22 'components/cgi/languages/cgimodules.po',
23 'components/codetools/languages/codetoolsstrconsts.po',
24 'components/h2pas/languages/h2passtrconsts.po',
25 'components/lazreport/samples/editor/languages/calleditorwithpkg.po',
26 'components/lazreport/source/languages/lr_const.po',
27 'components/memds/languages/frmselectdataset.po',
28 'components/messagecomposer/languages/messagecomposer.po',
29 'components/prettyformat/languages/pfidesource.po',
30 'components/printers/design/languages/ideprinting.po',
31 'components/projecttemplates/languages/frmtemplatevariables.po',
32 'components/projecttemplates/languages/idetemplateproject.po',
33 'components/projecttemplates/languages/projecttemplates.po',
34 'components/sqldb/languages/registersqldb.po',
35 'components/sqldb/languages/sqlstringspropertyeditordlg.po',
36 'components/synedit/languages/synedit.po',
37 'components/synedit/languages/synhighlighterunixshellscript.po',
38 'components/synedit/languages/synmacrorecorder.po',
39 'components/synunihighlighter/languages/synunidesigner.po',
40 'components/synunihighlighter/languages/synunireg.po',
41 'components/tdbf/languages/registerdbf.po',
42 'components/turbopower_ipro/languages/ipconst.po',
43 'components/turbopower_ipro/languages/iputils.po',
44 'examples/codepageconverter/languages/lazconverter.po',
45 'examples/codepageconverter/languages/mainunit.po'
46 );
47
48type
49 TTranslationItem = class
50 Identification: string;
51 OriginalText: string;
52 TranslatedText: string;
53 end;
54
55 { TMainForm }
56
57 { TItemListForm }
58
59 TItemListForm = class(TForm)
60 Button1: TButton;
61 ListView1: TListView;
62 ProgressBar1: TProgressBar;
63 procedure Button1Click(Sender: TObject);
64 procedure ComboBox1Change(Sender: TObject);
65 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
66 procedure FormShow(Sender: TObject);
67 procedure FormDestroy(Sender: TObject);
68 procedure FormCreate(Sender: TObject);
69 procedure ListView1Compare(Sender: TObject; Item1, Item2: TListItem;
70 Data: Integer; var Compare: Integer);
71 procedure ListView1DblClick(Sender: TObject);
72 procedure ListView1KeyPress(Sender: TObject; var Key: Char);
73 procedure ListView1ColumnClick(Sender: TObject; Column: TListColumn);
74 private
75 public
76 TranslationFile: string;
77 LastSortedColumn: Integer;
78 StringList: TList; // TList<TText>
79 procedure FillList;
80 procedure LoadListFromFile;
81 procedure SaveListToFile;
82 procedure MergeListFromFile;
83 function RenameToLocale(POFileName: string): string;
84 end;
85
86 function FileCopy(source,dest: String): Boolean;
87
88var
89 ItemListForm: TItemListForm;
90 Ascending: Boolean;
91
92implementation
93
94function FileCopy(source,dest: String): Boolean;
95var
96 fSrc,fDst,len: Integer;
97 ct,units,size: Longint;
98 buffer: packed array [0..2047] of Byte;
99begin
100 ct:=0;
101 Result := False; { Assume that it WONT work }
102 if source <> dest then begin
103 fSrc := FileOpen(source,fmOpenRead);
104 if fSrc >= 0 then begin
105 size := FileSeek(fSrc,0,2);
106 units:=size div 2048;
107 FileSeek(fSrc,0,0);
108 fDst := FileCreate(dest);
109 if fDst >= 0 then begin
110 while size > 0 do begin
111 len := FileRead(fSrc,buffer,sizeof(buffer));
112 FileWrite(fDst,buffer,len);
113 size := size - len;
114 if units > 0 then
115 ct:=ct+1;
116 end;
117 FileSetDate(fDst,FileGetDate(fSrc));
118 FileClose(fDst);
119 FileSetAttr(dest,FileGetAttr(source));
120 Result := True;
121 end;
122 FileClose(fSrc);
123 end;
124 end;
125end;
126
127function SortByColumn(Item1, Item2: TListItem; Data: integer): Integer; stdcall;
128begin
129 if Data = 0 then
130 Result := AnsiCompareText(Item1.Caption, Item2.Caption)
131 else
132 Result := AnsiCompareText(Item1.SubItems[Data - 1],
133 Item2.SubItems[Data - 1]);
134 if not Ascending then Result := -Result;
135end;
136
137procedure TItemListForm.FillList;
138var
139 I: Integer;
140 NewItem: TListItem;
141 CompletedCount: Integer;
142begin
143 CompletedCount := 0;
144 with ListView1, Items do begin
145 BeginUpdate;
146 Clear;
147 for I := 0 to StringList.Count - 1 do
148 with TTranslationItem(StringList[I]) do begin
149 NewItem := Add;
150 NewItem.Data := StringList[I];
151 NewItem.Caption := OriginalText;
152 with NewItem.SubItems do begin
153 Add(TranslatedText);
154 Add(Identification);
155 if TranslatedText <> '' then Inc(CompletedCount);
156 end;
157 end;
158 EndUpdate;
159 end;
160 ProgressBar1.Max := StringList.Count;
161 ProgressBar1.Position := CompletedCount;
162end;
163
164procedure TItemListForm.FormCreate(Sender: TObject);
165begin
166 StringList := TList.Create;
167 LastSortedColumn := -1;
168 Ascending := True;
169end;
170
171procedure TItemListForm.ListView1Compare(Sender: TObject; Item1, Item2: TListItem;
172 Data: Integer; var Compare: Integer);
173begin
174 Compare := AnsiCompareText(Item1.SubItems[0],
175 Item2.SubItems[0]);
176 if not Ascending then Compare := -Compare;
177end;
178
179procedure TItemListForm.FormDestroy(Sender: TObject);
180var
181 I: Integer;
182begin
183 for I := 0 to StringList.Count - 1 do
184 TTranslationItem(StringList[I]).Free;
185 StringList.Free;
186end;
187
188procedure TItemListForm.FormShow(Sender: TObject);
189begin
190 LoadListFromFile;
191 //MergeListFromFile;
192 FillList;
193end;
194
195procedure TItemListForm.Button1Click(Sender: TObject);
196begin
197 Close;
198end;
199
200procedure TItemListForm.ComboBox1Change(Sender: TObject);
201begin
202 SaveListToFile;
203 LoadListFromFile;
204 FillList;
205end;
206
207procedure TItemListForm.FormClose(Sender: TObject; var CloseAction: TCloseAction
208 );
209begin
210 SaveListToFile;
211end;
212
213procedure TItemListForm.ListView1ColumnClick(Sender: TObject; Column: TListColumn);
214begin
215 if Column.Index = LastSortedColumn then
216 Ascending := not Ascending
217 else
218 LastSortedColumn := Column.Index;
219 //TListView(Sender).CustomSort(@SortByColumn, Column.Index);
220end;
221
222procedure TItemListForm.ListView1DblClick(Sender: TObject);
223begin
224 if Assigned(ListView1.Selected) then
225 with ItemTranslationForm, TTranslationItem(ListView1.Selected.Data) do begin
226 Memo1.Text := OriginalText;
227 Memo2.Text := TranslatedText;
228 ItemTranslationForm.ShowModal;
229 //OriginalText := Memo1.Text;
230 TranslatedText := Copy(Memo2.Text, 1, Length(Memo2.Text) - 2);
231
232 ListView1.Selected.SubItems[0] := TranslatedText;
233 SaveListToFile;
234 end;
235end;
236
237procedure TItemListForm.ListView1KeyPress(Sender: TObject; var Key: Char);
238begin
239 if Key = #13 then ListView1DblClick(Self);
240end;
241
242procedure TItemListForm.LoadListFromFile;
243var
244 Source: TTextFileStream;
245 Row: string;
246 NewItem: TTranslationItem;
247 I: Integer;
248begin
249 StringList.Clear;
250 NewItem := nil;
251 Source := TTextFileStream.Create(TranslationFile, fmOpenRead);
252 try
253 for I := 0 to 2 do Row := Source.ReadLn; // Skip leading info lines
254
255 while not Source.Eof do begin
256 Row := Source.ReadLn;
257 if Copy(Row, 1, 2) = '#:' then begin
258 NewItem := TTranslationItem.Create;
259 NewItem.Identification := Copy(Row, 4, 255);
260 NewItem.Identification := StringReplace(NewItem.Identification, ':', '.', [rfReplaceAll]);
261 end else
262 if Copy(Row, 1, Pos(' ', Row) - 1) = 'msgid' then begin
263 if Assigned(NewItem) then
264 NewItem.OriginalText := Copy(Row, 8, Length(Row) - 8)
265 end else
266 if Copy(Row, 1, Pos(' ', Row) - 1) = 'msgstr' then begin
267 if Assigned(NewItem) then begin
268 NewItem.TranslatedText := Copy(Row, 9, Length(Row) - 9);
269 StringList.Add(NewItem);
270 end;
271 end;
272 end;
273 finally
274 Source.Free;
275 end;
276end;
277
278procedure TItemListForm.SaveListToFile;
279var
280 Source: TTextFileStream;
281 I: Integer;
282begin
283 Source := TTextFileStream.Create(TranslationFile, fmOpenWrite);
284 with Source do
285 try
286 WriteLn('msgid ""');
287 WriteLn('msgstr ""');
288 WriteLn('"Project-Id-Version: \n"');
289 WriteLn('"POT-Creation-Date: \n"');
290 WriteLn('"PO-Revision-Date: 2009-01-07 19:03+0100\n"');
291 WriteLn('"Last-Translator: Chronos <robie@centrum.cz>\n"');
292 WriteLn('"Translation-Source: http://tv.zdechov.net/svn/lazarus_czech/\n"');
293 WriteLn('"Language-Team: \n"');
294 WriteLn('"MIME-Version: 1.0\n"');
295 WriteLn('"Content-Type: text/plain; charset=UTF-8\n"');
296 WriteLn('"Content-Transfer-Encoding: 8bit\n"');
297 WriteLn('');
298 for I := 0 to StringList.Count - 1 do
299 with TTranslationItem(StringList[I]) do begin
300 WriteLn('#: ' + Identification);
301 WriteLn('msgid "' + OriginalText + '"');
302 WriteLn('msgstr "' + TranslatedText + '"');
303 WriteLn('');
304 end;
305 finally
306 Source.Free;
307 end;
308end;
309
310function TItemListForm.RenameToLocale(POFileName: string): string;
311begin
312 Result := StringReplace(POFileName, '.po', '.' + LocaleName + '.po', [rfReplaceAll]);
313end;
314
315procedure TItemListForm.MergeListFromFile;
316var
317 Source: TTextFileStream;
318 Row: string;
319 NewItem: TTranslationItem;
320 I: Integer;
321begin
322 NewItem := nil;
323 Source := TTextFileStream.Create(TranslationFile, fmOpenRead);
324 try
325 for I := 0 to 2 do Row := Source.ReadLn; // Skip lines
326
327 while not Source.Eof do begin
328 Row := Source.ReadLn;
329 if Copy(Row, 1, 2) = '#:' then begin
330 NewItem := TTranslationItem.Create;
331 NewItem.Identification := Copy(Row, 4, 255);
332 NewItem.Identification := StringReplace(NewItem.Identification, ':', '.', [rfReplaceAll]);
333 end else
334 if Copy(Row, 1, Pos(' ', Row) - 1) = 'msgid' then begin
335 if Assigned(NewItem) then
336 NewItem.OriginalText := Copy(Row, 8, Length(Row) - 8)
337 end else
338 if Copy(Row, 1, Pos(' ', Row) - 1) = 'msgstr' then begin
339 if Assigned(NewItem) then begin
340 NewItem.TranslatedText := Copy(Row, 9, Length(Row) - 9);
341 I := 0;
342 while (I < StringList.Count) and ((TTranslationItem(StringList[I]).OriginalText <> NewItem.OriginalText) or
343 (TTranslationItem(StringList[I]).Identification <> NewItem.Identification)) do Inc(I);
344 if I < StringList.Count then
345 TTranslationItem(StringList[I]).TranslatedText := NewItem.TranslatedText;
346 NewItem.Free;
347 end;
348 end;
349 end;
350 finally
351 Source.Free;
352 end;
353end;
354
355
356initialization
357 {$I UItemListForm.lrs}
358
359end.
360
Note: See TracBrowser for help on using the repository browser.