unit LrtPoTools; { Copyright (C) 2004 V.I.Volchenko, Lazarus and FreePascal Developers Teams *************************************************************************** * * * This source is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This code is distributed in the hope that it will be useful, but * * WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * * General Public License for more details. * * * * A copy of the GNU General Public License is available on the World * * Wide Web at . You can also * * obtain it by writing to the Free Software Foundation, * * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * * *************************************************************************** } //TODO: Make more quick mechanism for .po updating //This source uses a portion of GPL'ed code from rstconv.pp from fpc/utils {$mode objfpc}{$H+} interface uses Classes, SysUtils, Forms; type TPOStyle=(postStandard,postPropName,postFull); procedure Lrt2Po(const LRTFile:string;POStyle:TPOStyle); procedure CombinePoFiles(SL:TStrings;const FName:string); implementation function OKStr(const s:string):string; var i: Integer; begin Result:=''; for i:=1 to Length(s) do case s[i] of '"':Result:=Result+'\"'; '%':Result:=Result+'\%'; '\':Result:=Result+'\\'; '#':Result:=Result+'\#'; //TODO: check if that's all else Result:=Result+s[i]; end; end; procedure Lrt2Po(const LRTFile: string;POStyle:TPoStyle); var SL1: TStringList; SL2: TStringList; i: Integer; p: LongInt; k: LongInt; s: string; DotPos: LongInt; EqPos: LongInt; s1: String; j: Integer; found: Boolean; m: LongInt; begin SL1:=TStringList.Create; SL2:=TStringList.Create; if FileExists(LRTFile) then SL1.LoadFromFile(LRTFile); // Trying to process RST file in addition if FileExists(ChangeFileExt(LRTFile,'.rst')) then begin SL2.LoadFromFile(ChangeFileExt(LRTFile,'.rst')); // Some code from rstconv used here k:=0; while k EqPos then // paranoia checking. DotPos := 0; s1 := ''; i := EqPos + 1; while i <= Length(s) do begin if s[i] = '''' then begin Inc(i); j := i; while (i <= Length(s)) and (s[i] <> '''') do Inc(i); s1 := s1 + Copy(s, j, i - j); Inc(i); end else if s[i] = '#' then begin Inc(i); j := i; while (i <= Length(s)) and (s[i] in ['0'..'9']) do Inc(i); s1 := s1 + Chr(StrToInt(Copy(s, j, i - j))); end else if s[i] = '+' then begin if k6) and (Length(SL2[i])>6) and (LeftStr(SL1[j],5)='msgid') and (LeftStr(SL2[i],5)='msgid')and (Trim(copy(SL1[j],6,length(SL1[j])-5))=Trim(copy(SL2[i],5,length(SL2[i])-4))) then //found! begin //Ignore any comment etc k:=j; while (k'msgstr')) do inc(k); if (k'msgstr')) do inc(m); if (m'msgid' then exit; if LeftStr(S4,5)<>'msgid' then exit; if Trim(copy(s3,6,length(s3)-5))<>Trim(copy(s4,6,length(s4)-5)) then exit; Result:=true; end; begin SL1:=TStringList.Create; SL2:=TStringList.Create; for i:=0 to SL.Count-1 do begin SL2.Clear; SL2.LoadFromFile(SL[i]); SL1.AddStrings(SL2); end; //Removing dublicates. Seems that I have just overprogrammed the code. //This code needs to be tested. SL2.Clear;//SL2 will be IDList k:=0; while k'msgstr') do begin SL2.Add(SL1[k]); inc(k); end; if k