ide, i18n: support for multiline messages

git-svn-id: trunk@15454 -
This commit is contained in:
jesus 2008-06-17 20:01:33 +00:00
parent d9ea20a1ef
commit f678aaf278
3 changed files with 64 additions and 20 deletions

View File

@ -70,18 +70,36 @@ var
POValuesHash: TStringHashList; POValuesHash: TStringHashList;
POFileChanged: boolean; POFileChanged: boolean;
POLines: TStrings; POLines: TStrings;
Value,Identifier: string; Identifier: string;
List: TStringList;
procedure AddPoHashEntry; procedure AddListPoHashEntry;
var
i: Integer;
Str: String;
begin begin
if POValuesHash.Find(Value) = -1 then begin
DebugLn(['AddFile2PoAux Add ',Identifier,'="',Value,'"']); if List.Count=1 then
Str := List[0]
else
Str := List.Text;
if POValuesHash.Find(Str) = -1 then begin
POFileChanged := true; POFileChanged := true;
POLines.Add('#: '+Identifier); POLines.Add('#: '+Identifier);
POLines.Add('msgid "'+Value+'"');
if List.Count=1 then
POLines.Add('msgid "'+Str+'"')
else begin
POLines.Add('msgid ""');
for i:= 0 to List.Count-1 do
POLines.Add('"'+List[i]+'\n"');
end;
POLines.Add('msgstr ""'); POLines.Add('msgstr ""');
POLines.Add(''); POLines.Add('');
POValuesHash.Add(Value); POValuesHash.Add(Str);
end; end;
end; end;
@ -89,7 +107,7 @@ var
var var
i,j,n: integer; i,j,n: integer;
p: LongInt; p: LongInt;
Line,UStr: string; Value,Line,UStr: string;
Multi: boolean; Multi: boolean;
begin begin
//for each string in lrt/rst list check if in PO, if not add //for each string in lrt/rst list check if in PO, if not add
@ -101,15 +119,17 @@ var
case FileType of case FileType of
ftLrt: begin ftLrt: begin
p:=Pos('=',Line); p:=Pos('=',Line);
Value:=StrToPoStr( copy(Line,p+1,n-p) );//if p=0, that's OK, all the string List.Clear;
List.add(StrToPoStr( copy(Line,p+1,n-p) ));//if p=0, that's OK, all the string
Identifier:=copy(Line,1,p-1); Identifier:=copy(Line,1,p-1);
AddPoHashEntry; AddListPoHashEntry;
end; end;
ftRst: begin ftRst: begin
if (Line[1]='#') then begin if (Line[1]='#') then begin
Value := ''; Value := '';
Identifier := ''; Identifier := '';
List.Clear;
continue; continue;
end; end;
@ -149,7 +169,7 @@ var
// and re-encode back the rest // and re-encode back the rest
while Ustr<>'' do begin while Ustr<>'' do begin
j := UTF8CharacterLength(pchar(Ustr)); j := UTF8CharacterLength(pchar(Ustr));
if (j=1) and (Ustr[1] in [#0..#31,#128..#255]) then if (j=1) and (Ustr[1] in [#0..#9,#11,#12,#14..#31,#128..#255]) then
Value := Value + '#'+IntToStr(ord(Ustr[1])) Value := Value + '#'+IntToStr(ord(Ustr[1]))
else else
Value := Value + copy(Ustr, 1, j); Value := Value + copy(Ustr, 1, j);
@ -160,9 +180,9 @@ var
break; break;
end; end;
if not Multi then begin if not Multi then begin
Value := StrToPoStr(Value); List.Text := StrToPoStr(Value);
if Value<>'' then if List.Count>0 then
AddPoHashEntry; AddListPoHashEntry;
end; end;
end; end;
end; end;
@ -181,6 +201,7 @@ begin
POLines:=TStringList.Create; POLines:=TStringList.Create;
InputLines:=TStringList.Create; InputLines:=TStringList.Create;
POValuesHash := TStringHashList.Create(true); POValuesHash := TStringHashList.Create(true);
List := TStringList.Create;
try try
//load old po file into a StringList and HashList //load old po file into a StringList and HashList
@ -231,6 +252,7 @@ begin
else else
Result:=mrOk; Result:=mrOk;
finally finally
List.Free;
POLines.Free; POLines.Free;
InputLines.Free; InputLines.Free;
POValuesHash.Free; POValuesHash.Free;

View File

@ -2571,7 +2571,7 @@ begin
{$IFDEF WINDOWS} {$IFDEF WINDOWS}
begin begin
move(lineending[1], dest^, length(LineEnding)); move(lineending[1], dest^, length(LineEnding));
inc(dest^, length(LineEnding)-1); inc(dest, length(LineEnding)-1);
end; end;
{$ELSE} {$ELSE}
Dest^ := LineEnding; Dest^ := LineEnding;

View File

@ -263,21 +263,36 @@ var
LineEnd: PChar; LineEnd: PChar;
Identifier: String; Identifier: String;
MsgID: String; MsgID: String;
MsgStr: String; Line: String;
TextEnd: PChar; TextEnd: PChar;
i: Integer; i: Integer;
procedure AddEntry;
begin
if Identifier<>'' then begin
Add(Identifier,MsgID,Line);
MsgId := '';
Line := '';
Identifier := '';
end;
end;
begin begin
if s='' then exit; if s='' then exit;
l:=length(s); l:=length(s);
p:=PChar(s); p:=PChar(s);
LineStart:=p; LineStart:=p;
TextEnd:=p+l; TextEnd:=p+l;
Identifier:='';
while LineStart<TextEnd do begin while LineStart<TextEnd do begin
LineEnd:=LineStart; LineEnd:=LineStart;
while (not (LineEnd^ in [#0,#10,#13])) do inc(LineEnd); while (not (LineEnd^ in [#0,#10,#13])) do inc(LineEnd);
LineLen:=LineEnd-LineStart; LineLen:=LineEnd-LineStart;
if LineLen>0 then begin if LineLen>0 then begin
if CompareMem(LineStart,sCommentIdentifier,3) then begin if CompareMem(LineStart,sCommentIdentifier,3) then begin
AddEntry; // add peding entry (if exists)
Identifier:=copy(s,LineStart-p+4,LineLen-3); Identifier:=copy(s,LineStart-p+4,LineLen-3);
// the RTL creates identifier paths with point instead of colons // the RTL creates identifier paths with point instead of colons
// fix it: // fix it:
@ -285,18 +300,25 @@ begin
if Identifier[i]=':' then if Identifier[i]=':' then
Identifier[i]:='.'; Identifier[i]:='.';
end else if CompareMem(LineStart,sMsgID,7) then begin end else if CompareMem(LineStart,sMsgID,7) then begin
MsgID:=UTF8CStringToUTF8String(LineStart+7,LineLen-8); // start collecting MsgId lines
Line:=UTF8CStringToUTF8String(LineStart+7,LineLen-8);
end else if CompareMem(LineStart,sMsgStr,8) then begin end else if CompareMem(LineStart,sMsgStr,8) then begin
//MsgStr:=copy(s,LineStart-p+9,LineLen-9); // store collected strings in MsgId
MsgStr:=UTF8CStringToUTF8String(LineStart+8,LineLen-9); MsgId := Line;
Add(Identifier,MsgID,MsgStr); // start collecting MsgStr lines
Line:=UTF8CStringToUTF8String(LineStart+8,LineLen-9);
end else if CompareMem(LineStart,sCharSetIdentifier,35) then begin end else if CompareMem(LineStart,sCharSetIdentifier,35) then begin
FCharSet:=copy(LineStart, 35,LineLen-37); FCharSet:=copy(LineStart, 35,LineLen-37);
end; end else if LineStart^='"' then begin
if Identifier<>'' then
Line := Line + UTF8CStringToUTF8String(LineStart+1,LineLen-2);
end else
AddEntry;
end; end;
LineStart:=LineEnd+1; LineStart:=LineEnd+1;
while (LineStart<TextEnd) and (LineStart^ in [#10,#13]) do inc(LineStart); while (LineStart<TextEnd) and (LineStart^ in [#10,#13]) do inc(LineStart);
end; end;
AddEntry;
end; end;
procedure TPOFile.Add(const Identifier, OriginalValue, TranslatedValue: string procedure TPOFile.Add(const Identifier, OriginalValue, TranslatedValue: string