LCL: TPOFile: fixed continuation lines

git-svn-id: trunk@35388 -
This commit is contained in:
mattias 2012-02-16 01:53:45 +00:00
parent 5803ddeab4
commit cf8b22b35e

View File

@ -34,7 +34,7 @@
{ $define DebugSimplePoFiles} { $define DebugSimplePoFiles}
{ $define ReadPoTextPChar} //define this to use the old ReadPoText method which uses PChars {$define ReadPoTextPChar} //define this to use the old ReadPoText method which uses PChars
unit SimplePoFiles; unit SimplePoFiles;
@ -490,6 +490,12 @@ msgid "Do not show splash screen"
msgstr "" msgstr ""
} }
type
TMsg = (
mid,
mstr,
mctx
);
var var
l: Integer; l: Integer;
LineLen: Integer; LineLen: Integer;
@ -497,52 +503,54 @@ var
LineStart: PChar; LineStart: PChar;
LineEnd: PChar; LineEnd: PChar;
Identifier: String; Identifier: String;
MsgID,MsgStr,PrevMsgID: String; PrevMsgID: String;
Line: String;
Comments: String; Comments: String;
Context: string;
Flags: string; Flags: string;
TextEnd: PChar; TextEnd: PChar;
i: Integer; i: Integer;
//OldLineStartPos: PtrUInt;
//NewSrc: String;
s: String; s: String;
Handled: Boolean; Handled: Boolean;
CurMsg: TMsg;
Msg: array[TMsg] of string;
procedure ResetVars; procedure ResetVars;
begin begin
MsgId := ''; CurMsg:=mid;
MsgStr := ''; Msg[mid]:='';
Line := ''; Msg[mstr]:='';
Msg[mctx]:='';
Identifier := ''; Identifier := '';
Comments := ''; Comments := '';
Context := '';
Flags := ''; Flags := '';
PrevMsgID := ''; PrevMsgID := '';
end; end;
procedure AddEntry; procedure AddEntry;
var //var
Item: TPOFileItem; // Item: TPOFileItem;
begin begin
if Identifier<>'' then begin if Identifier<>'' then begin
// check for unresolved duplicates in po file // check for unresolved duplicates in po file
{Item := TPOFileItem(FOriginalToItem.Data[MsgID]); {Item := TPOFileItem(FOriginalToItem.Data[Msg[mid]]);
if (Item<>nil) then begin if (Item<>nil) then begin
// fix old duplicate context // fix old duplicate context
if Item.Context='' then if Item.Context='' then
Item.Context:=Item.Identifier; Item.Context:=Item.IdentifierLow;
// set context of new duplicate // set context of new duplicate
if Context='' then if Msg[mctx]='' then
Context := Identifier; Msg[mctx] := Identifier;
// if old duplicate was translated and // if old duplicate was translated and
// new one is not, provide a initial translation // new one is not, provide a initial translation
if MsgStr='' then if Msg[mstr]='' then
MsgStr := Item.Translation; Msg[mstr] := Item.Translation;
end;} end;}
Add(Identifier,MsgID,MsgStr,Comments,Context,Flags,PrevMsgID,0); Add(Identifier,Msg[mid],Msg[mstr],Comments,Msg[mctx],Flags,PrevMsgID,0);
ResetVars; ResetVars;
end else end else
if (Line<>'') and (FHeader=nil) then begin if (Msg[CurMsg]<>'') and (FHeader=nil) then begin
FHeader := TPOFileItem.Create('',MsgID,Line); FHeader := TPOFileItem.Create('',Msg[mid],Msg[CurMsg]);
FHeader.Comments:=Comments; FHeader.Comments:=Comments;
ResetVars; ResetVars;
end end
@ -558,10 +566,7 @@ begin
LineStart:=p; LineStart:=p;
TextEnd:=p+l; TextEnd:=p+l;
Identifier:=''; ResetVars;
Comments:='';
Line:='';
Flags:='';
while LineStart<TextEnd do begin while LineStart<TextEnd do begin
LineEnd:=LineStart; LineEnd:=LineStart;
@ -590,7 +595,7 @@ begin
PrevMsgID:=PrevMsgID+GetUTF8String(LineStart+length('#| msgid "'),LineEnd-1); PrevMsgID:=PrevMsgID+GetUTF8String(LineStart+length('#| msgid "'),LineEnd-1);
Handled:=true; Handled:=true;
end else if IsKey(LineStart, '#| "') then begin end else if IsKey(LineStart, '#| "') then begin
Line := Line + GetUTF8String(LineStart+length('#| "'),LineEnd-1); Msg[CurMsg] := Msg[CurMsg] + GetUTF8String(LineStart+length('#| "'),LineEnd-1);
Handled:=true; Handled:=true;
end; end;
',': ',':
@ -613,24 +618,27 @@ begin
case LineStart[3] of case LineStart[3] of
'i': 'i':
if IsKey(LineStart,'msgid "') then begin if IsKey(LineStart,'msgid "') then begin
MsgID:=MsgID+GetUTF8String(LineStart+length('msgid "'),LineEnd-1); CurMsg:=mid;
Msg[CurMsg]:=Msg[CurMsg]+GetUTF8String(LineStart+length('msgid "'),LineEnd-1);
Handled:=true; Handled:=true;
end; end;
's': 's':
if IsKey(LineStart,'msgstr "') then begin if IsKey(LineStart,'msgstr "') then begin
MsgStr:=MsgStr+GetUTF8String(LineStart+length('msgstr "'),LineEnd-1); CurMsg:=mstr;
Msg[CurMsg]:=Msg[CurMsg]+GetUTF8String(LineStart+length('msgstr "'),LineEnd-1);
Handled:=true; Handled:=true;
end; end;
'c': 'c':
if IsKey(LineStart, 'msgctxt "') then begin if IsKey(LineStart, 'msgctxt "') then begin
Context:=GetUTF8String(LineStart+length('msgctxt "'), LineEnd-1); CurMsg:=mctx;
Msg[CurMsg]:=Msg[CurMsg]+GetUTF8String(LineStart+length('msgctxt "'), LineEnd-1);
Handled:=true; Handled:=true;
end; end;
end; end;
end; end;
'"': '"':
begin begin
if (MsgID='') if (Msg[mid]='')
and IsKey(LineStart,'"Content-Type: text/plain; charset=') then and IsKey(LineStart,'"Content-Type: text/plain; charset=') then
begin begin
FCharSet:=GetUTF8String(LineStart+length('"Content-Type: text/plain; charset='),LineEnd); FCharSet:=GetUTF8String(LineStart+length('"Content-Type: text/plain; charset='),LineEnd);
@ -650,7 +658,8 @@ begin
LineLen:=LineEnd-LineStart;} LineLen:=LineEnd-LineStart;}
end; end;
end; end;
Line := Line + GetUTF8String(LineStart+1,LineEnd-1); // continuation
Msg[CurMsg]:=Msg[CurMsg]+GetUTF8String(LineStart+1,LineEnd-1);
Handled:=true; Handled:=true;
end; end;
end; end;
@ -658,7 +667,7 @@ begin
AddEntry; AddEntry;
end; end;
LineStart:=LineEnd+1; LineStart:=LineEnd+1;
while (LineStart<TextEnd) and (LineStart^ in [#10,#13]) do inc(LineStart); while (LineStart^ in [#10,#13]) do inc(LineStart);
end; end;
AddEntry; AddEntry;