lcl: add support for rsj translation files

git-svn-id: trunk@43744 -
This commit is contained in:
paul 2014-01-17 01:14:32 +00:00
parent a51ef5c65e
commit 94e8ee0649

View File

@ -64,10 +64,10 @@ interface
uses uses
Classes, SysUtils, LCLProc, FileUtil, StringHashList, AvgLvlTree, Classes, SysUtils, LCLProc, FileUtil, StringHashList, AvgLvlTree,
LConvEncoding; LConvEncoding, jsonparser, fpjson;
type type
TStringsType = (stLrt, stRst); TStringsType = (stLrt, stRst, stRsj);
TTranslateUnitResult = (turOK, turNoLang, turNoFBLang, turEmptyParam); TTranslateUnitResult = (turOK, turNoLang, turNoFBLang, turEmptyParam);
type type
@ -324,8 +324,9 @@ begin
// Update po file with lrt or/and rst files // Update po file with lrt or/and rst files
for i:=0 to Files.Count-1 do begin for i:=0 to Files.Count-1 do begin
Filename:=Files[i]; Filename:=Files[i];
if (CompareFileExt(Filename,'.lrt')=0) if (CompareFileExt(Filename,'.lrt')=0) or
or (CompareFileExt(Filename,'.rst')=0) then (CompareFileExt(Filename,'.rst')=0) or
(CompareFileExt(Filename,'.rsj')=0) then
try try
//DebugLn(''); //DebugLn('');
//DebugLn(['AddFiles2Po Filename="',Filename,'"']); //DebugLn(['AddFiles2Po Filename="',Filename,'"']);
@ -334,6 +335,9 @@ begin
if CompareFileExt(Filename,'.lrt')=0 then if CompareFileExt(Filename,'.lrt')=0 then
BasePOFile.UpdateStrings(InputLines, stLrt) BasePOFile.UpdateStrings(InputLines, stLrt)
else
if CompareFileExt(Filename,'.rsj')=0 then
BasePOFile.UpdateStrings(InputLines, stRsj)
else else
BasePOFile.UpdateStrings(InputLines, stRst); BasePOFile.UpdateStrings(InputLines, stRst);
@ -852,108 +856,133 @@ var
p := 1; p := 1;
end; end;
procedure UpdateFromRsj;
var
Parser: TJSONParser;
JsonData: TJSONData;
JsonItem: TJSONObject;
I: Integer;
begin
Parser := TJSONParser.Create(InputLines.Text);
try
JsonData := Parser.Parse.GetPath('strings');
for I := 0 to JsonData.Count - 1 do
begin
JsonItem := JsonData.Items[I] as TJSONObject;
UpdateItem(JsonItem.Get('name'), JsonItem.Get('value'));
end;
finally
Parser.Free;
end;
end;
begin begin
ClearModuleList; ClearModuleList;
UntagAll; UntagAll;
// for each string in lrt/rst list check if it's already in PO if SType = stRsj then
// if not add it UpdateFromRsj
Value := ''; else
Identifier := ''; begin
i := 0; // for each string in lrt/rst list check if it's already in PO
while i < InputLines.Count do begin // if not add it
Value := '';
Identifier := '';
i := 0;
while i < InputLines.Count do begin
Line := InputLines[i]; Line := InputLines[i];
n := Length(Line); n := Length(Line);
if n=0 then if n=0 then
// empty line // empty line
else else
if SType=stLrt then begin if SType=stLrt then begin
p:=Pos('=',Line);
Value :=copy(Line,p+1,n-p); //if p=0, that's OK, all the string
Identifier:=copy(Line,1,p-1);
UpdateItem(Identifier, Value);
end else begin
// rst file
if Line[1]='#' then begin
// rst file: comment
Value := '';
Identifier := '';
MultilinedValue := false;
end else begin
p:=Pos('=',Line); p:=Pos('=',Line);
if P>0 then begin Value :=copy(Line,p+1,n-p); //if p=0, that's OK, all the string
Identifier:=copy(Line,1,p-1);
UpdateItem(Identifier, Value);
Identifier := copy(Line,1,p-1); end else begin
inc(p); // points to ' after = // rst file
if Line[1]='#' then begin
// rst file: comment
Value := ''; Value := '';
while p<=n do begin Identifier := '';
MultilinedValue := false;
if Line[p]='''' then begin end else begin
inc(p);
j:=p; p:=Pos('=',Line);
while (p<=n)and(Line[p]<>'''') do if P>0 then begin
inc(p);
Value := Value + copy(Line, j, P-j); Identifier := copy(Line,1,p-1);
inc(p); inc(p); // points to ' after =
continue;
end else Value := '';
if Line[p] = '#' then begin while p<=n do begin
// a #decimal
repeat if Line[p]='''' then begin
inc(p); inc(p);
j:=p; j:=p;
while (p<=n)and(Line[p] in ['0'..'9']) do while (p<=n)and(Line[p]<>'''') do
inc(p); inc(p);
Value := Value + copy(Line, j, P-j);
inc(p);
continue;
end else
if Line[p] = '#' then begin
// a #decimal
repeat
inc(p);
j:=p;
while (p<=n)and(Line[p] in ['0'..'9']) do
inc(p);
Ch := Chr(StrToInt(copy(Line, j, p-j))); Ch := Chr(StrToInt(copy(Line, j, p-j)));
Value := Value + Ch; Value := Value + Ch;
if Ch in [#13,#10] then if Ch in [#13,#10] then
MultilinedValue := True; MultilinedValue := True;
if (p=n) and (Line[p]='+') then if (p=n) and (Line[p]='+') then
NextLine; NextLine;
until (p>n) or (Line[p]<>'#'); until (p>n) or (Line[p]<>'#');
end else end else
if Line[p]='+' then if Line[p]='+' then
NextLine NextLine
else
inc(p); // this is an unexpected string
end;
if Value<>'' then begin
if MultiLinedValue then begin
// check that we end on lineending, multilined
// resource strings from rst usually do not end
// in lineending, fix here.
if not (Value[Length(Value)] in [#13,#10]) then
Value := Value + LineEnding;
end;
// po requires special characters as #number
p:=1;
while p<=length(Value) do begin
j := UTF8CharacterLength(pchar(@Value[p]));
if (j=1) and (Value[p] in [#0..#9,#11,#12,#14..#31,#127..#255]) then
Value := copy(Value,1,p-1)+'#'+IntToStr(ord(Value[p]))+copy(Value,p+1,length(Value))
else else
inc(p,j); inc(p); // this is an unexpected string
end; end;
UpdateItem(Identifier, Value); if Value<>'' then begin
end; if MultiLinedValue then begin
// check that we end on lineending, multilined
// resource strings from rst usually do not end
// in lineending, fix here.
if not (Value[Length(Value)] in [#13,#10]) then
Value := Value + LineEnding;
end;
// po requires special characters as #number
p:=1;
while p<=length(Value) do begin
j := UTF8CharacterLength(pchar(@Value[p]));
if (j=1) and (Value[p] in [#0..#9,#11,#12,#14..#31,#127..#255]) then
Value := copy(Value,1,p-1)+'#'+IntToStr(ord(Value[p]))+copy(Value,p+1,length(Value))
else
inc(p,j);
end;
end; // if p>0 then begin UpdateItem(Identifier, Value);
end;
end; // if p>0 then begin
end;
end; end;
end;
inc(i); inc(i);
end;
end; end;
RemoveUntaggedModules; RemoveUntaggedModules;