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;
POFileChanged: boolean;
POLines: TStrings;
Value,Identifier: string;
Identifier: string;
List: TStringList;
procedure AddPoHashEntry;
procedure AddListPoHashEntry;
var
i: Integer;
Str: String;
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;
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('');
POValuesHash.Add(Value);
POValuesHash.Add(Str);
end;
end;
@ -89,7 +107,7 @@ var
var
i,j,n: integer;
p: LongInt;
Line,UStr: string;
Value,Line,UStr: string;
Multi: boolean;
begin
//for each string in lrt/rst list check if in PO, if not add
@ -101,15 +119,17 @@ var
case FileType of
ftLrt: begin
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);
AddPoHashEntry;
AddListPoHashEntry;
end;
ftRst: begin
if (Line[1]='#') then begin
Value := '';
Identifier := '';
List.Clear;
continue;
end;
@ -149,7 +169,7 @@ var
// and re-encode back the rest
while Ustr<>'' do begin
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]))
else
Value := Value + copy(Ustr, 1, j);
@ -160,9 +180,9 @@ var
break;
end;
if not Multi then begin
Value := StrToPoStr(Value);
if Value<>'' then
AddPoHashEntry;
List.Text := StrToPoStr(Value);
if List.Count>0 then
AddListPoHashEntry;
end;
end;
end;
@ -181,6 +201,7 @@ begin
POLines:=TStringList.Create;
InputLines:=TStringList.Create;
POValuesHash := TStringHashList.Create(true);
List := TStringList.Create;
try
//load old po file into a StringList and HashList
@ -231,6 +252,7 @@ begin
else
Result:=mrOk;
finally
List.Free;
POLines.Free;
InputLines.Free;
POValuesHash.Free;

View File

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

View File

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