1 | unit UItemListForm;
|
---|
2 |
|
---|
3 | {$mode objfpc}{$H+}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | uses
|
---|
8 | Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
|
---|
9 | ComCtrls, UItemTranslationForm, UTextFileStream, StdCtrls;
|
---|
10 |
|
---|
11 | const
|
---|
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 |
|
---|
48 | type
|
---|
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 |
|
---|
88 | var
|
---|
89 | ItemListForm: TItemListForm;
|
---|
90 | Ascending: Boolean;
|
---|
91 |
|
---|
92 | implementation
|
---|
93 |
|
---|
94 | function FileCopy(source,dest: String): Boolean;
|
---|
95 | var
|
---|
96 | fSrc,fDst,len: Integer;
|
---|
97 | ct,units,size: Longint;
|
---|
98 | buffer: packed array [0..2047] of Byte;
|
---|
99 | begin
|
---|
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;
|
---|
125 | end;
|
---|
126 |
|
---|
127 | function SortByColumn(Item1, Item2: TListItem; Data: integer): Integer; stdcall;
|
---|
128 | begin
|
---|
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;
|
---|
135 | end;
|
---|
136 |
|
---|
137 | procedure TItemListForm.FillList;
|
---|
138 | var
|
---|
139 | I: Integer;
|
---|
140 | NewItem: TListItem;
|
---|
141 | CompletedCount: Integer;
|
---|
142 | begin
|
---|
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;
|
---|
162 | end;
|
---|
163 |
|
---|
164 | procedure TItemListForm.FormCreate(Sender: TObject);
|
---|
165 | begin
|
---|
166 | StringList := TList.Create;
|
---|
167 | LastSortedColumn := -1;
|
---|
168 | Ascending := True;
|
---|
169 | end;
|
---|
170 |
|
---|
171 | procedure TItemListForm.ListView1Compare(Sender: TObject; Item1, Item2: TListItem;
|
---|
172 | Data: Integer; var Compare: Integer);
|
---|
173 | begin
|
---|
174 | Compare := AnsiCompareText(Item1.SubItems[0],
|
---|
175 | Item2.SubItems[0]);
|
---|
176 | if not Ascending then Compare := -Compare;
|
---|
177 | end;
|
---|
178 |
|
---|
179 | procedure TItemListForm.FormDestroy(Sender: TObject);
|
---|
180 | var
|
---|
181 | I: Integer;
|
---|
182 | begin
|
---|
183 | for I := 0 to StringList.Count - 1 do
|
---|
184 | TTranslationItem(StringList[I]).Free;
|
---|
185 | StringList.Free;
|
---|
186 | end;
|
---|
187 |
|
---|
188 | procedure TItemListForm.FormShow(Sender: TObject);
|
---|
189 | begin
|
---|
190 | LoadListFromFile;
|
---|
191 | //MergeListFromFile;
|
---|
192 | FillList;
|
---|
193 | end;
|
---|
194 |
|
---|
195 | procedure TItemListForm.Button1Click(Sender: TObject);
|
---|
196 | begin
|
---|
197 | Close;
|
---|
198 | end;
|
---|
199 |
|
---|
200 | procedure TItemListForm.ComboBox1Change(Sender: TObject);
|
---|
201 | begin
|
---|
202 | SaveListToFile;
|
---|
203 | LoadListFromFile;
|
---|
204 | FillList;
|
---|
205 | end;
|
---|
206 |
|
---|
207 | procedure TItemListForm.FormClose(Sender: TObject; var CloseAction: TCloseAction
|
---|
208 | );
|
---|
209 | begin
|
---|
210 | SaveListToFile;
|
---|
211 | end;
|
---|
212 |
|
---|
213 | procedure TItemListForm.ListView1ColumnClick(Sender: TObject; Column: TListColumn);
|
---|
214 | begin
|
---|
215 | if Column.Index = LastSortedColumn then
|
---|
216 | Ascending := not Ascending
|
---|
217 | else
|
---|
218 | LastSortedColumn := Column.Index;
|
---|
219 | //TListView(Sender).CustomSort(@SortByColumn, Column.Index);
|
---|
220 | end;
|
---|
221 |
|
---|
222 | procedure TItemListForm.ListView1DblClick(Sender: TObject);
|
---|
223 | begin
|
---|
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;
|
---|
235 | end;
|
---|
236 |
|
---|
237 | procedure TItemListForm.ListView1KeyPress(Sender: TObject; var Key: Char);
|
---|
238 | begin
|
---|
239 | if Key = #13 then ListView1DblClick(Self);
|
---|
240 | end;
|
---|
241 |
|
---|
242 | procedure TItemListForm.LoadListFromFile;
|
---|
243 | var
|
---|
244 | Source: TTextFileStream;
|
---|
245 | Row: string;
|
---|
246 | NewItem: TTranslationItem;
|
---|
247 | I: Integer;
|
---|
248 | begin
|
---|
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;
|
---|
276 | end;
|
---|
277 |
|
---|
278 | procedure TItemListForm.SaveListToFile;
|
---|
279 | var
|
---|
280 | Source: TTextFileStream;
|
---|
281 | I: Integer;
|
---|
282 | begin
|
---|
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;
|
---|
308 | end;
|
---|
309 |
|
---|
310 | function TItemListForm.RenameToLocale(POFileName: string): string;
|
---|
311 | begin
|
---|
312 | Result := StringReplace(POFileName, '.po', '.' + LocaleName + '.po', [rfReplaceAll]);
|
---|
313 | end;
|
---|
314 |
|
---|
315 | procedure TItemListForm.MergeListFromFile;
|
---|
316 | var
|
---|
317 | Source: TTextFileStream;
|
---|
318 | Row: string;
|
---|
319 | NewItem: TTranslationItem;
|
---|
320 | I: Integer;
|
---|
321 | begin
|
---|
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;
|
---|
353 | end;
|
---|
354 |
|
---|
355 |
|
---|
356 | initialization
|
---|
357 | {$I UItemListForm.lrs}
|
---|
358 |
|
---|
359 | end.
|
---|
360 |
|
---|