updatepofiles: UpdatePoFileTranslations

git-svn-id: trunk@45666 -
This commit is contained in:
mattias 2014-06-26 01:47:38 +00:00
parent 6fb579df63
commit 20fd1b3c3d
2 changed files with 65 additions and 67 deletions

View File

@ -160,7 +160,8 @@ procedure TranslateResourceStrings(const BaseFilename, Lang, FallbackLang: strin
function UTF8ToSystemCharSet(const s: string): string; inline;
function UpdatePoFile(Files: TStrings; const POFilename: string): boolean;
function UpdatePoFile(RSTFiles: TStrings; const POFilename: string): boolean;
procedure UpdatePoFileTranslations(const BasePOFilename: string; BasePOFile: TPOFile = nil);
implementation
@ -257,63 +258,64 @@ begin
FindCloseUTF8(FileInfo);
end;
function UpdatePOFile(Files: TStrings; const POFilename: string): boolean;
procedure UpdatePoFileTranslations(const BasePOFilename: string; BasePOFile: TPOFile);
var
j: Integer;
Lines: TStringList;
FreeBasePOFile: Boolean;
TranslatedPOFile: TPOFile;
E: EPOFileError;
begin
// Update translated PO files
FreeBasePOFile := false;
Lines := FindAllTranslatedPoFiles(BasePOFilename);
try
for j:=0 to Lines.Count-1 do begin
TranslatedPOFile := TPOFile.Create(Lines[j], true);
try
TranslatedPOFile.Tag:=1;
if BasePOFile=nil then begin
BasePOFile := TPOFile.Create(BasePOFilename, true);
FreeBasePOFile := true;
end;
TranslatedPOFile.UpdateTranslation(BasePOFile);
try
TranslatedPOFile.SaveToFile(Lines[j]);
except
on Ex: Exception do begin
E := EPOFileError.Create(Ex.Message);
E.ResFileName:=Lines[j];
E.POFileName:=BasePOFileName;
raise E;
end;
end;
finally
TranslatedPOFile.Free;
end;
end;
finally
if FreeBasePOFile then
BasePOFile.Free;
Lines.Free;
end;
end;
function UpdatePOFile(RSTFiles: TStrings; const POFilename: string): boolean;
var
InputLines: TStringList;
Filename: string;
BasePoFile, POFile: TPoFile;
BasePoFile: TPoFile;
i: Integer;
E: EPOFileError;
procedure UpdatePoFilesTranslation;
var
j: Integer;
Lines: TStringList;
begin
// Update translated PO files
Lines := FindAllTranslatedPoFiles(POFilename);
try
for j:=0 to Lines.Count-1 do begin
POFile := TPOFile.Create(Lines[j], true);
try
POFile.Tag:=1;
POFile.UpdateTranslation(BasePOFile);
try
POFile.SaveToFile(Lines[j]);
except
on Ex: Exception do begin
E := EPOFileError.Create(Ex.Message);
E.ResFileName:=Lines[j];
E.POFileName:=POFileName;
raise E;
end;
end;
finally
POFile.Free;
end;
end;
finally
Lines.Free;
end;
end;
begin
Result := false;
if (Files=nil) or (Files.Count=0) then begin
if (RSTFiles=nil) or (RSTFiles.Count=0) then begin
if FileExistsUTF8(POFilename) then begin
// just update translated po files
BasePOFile := TPOFile.Create(POFilename, true);
try
UpdatePoFilesTranslation;
finally
BasePOFile.Free;
end;
// just update translated po RSTFiles
UpdatePoFileTranslations(POFilename);
end;
exit;
end;
InputLines := TStringList.Create;
@ -325,9 +327,9 @@ begin
BasePOFile := TPOFile.Create;
BasePOFile.Tag:=1;
// Update po file with lrt or/and rst files
for i:=0 to Files.Count-1 do begin
Filename:=Files[i];
// Update po file with lrt or/and rst RSTFiles
for i:=0 to RSTFiles.Count-1 do begin
Filename:=RSTFiles[i];
if (CompareFileExt(Filename,'.lrt')=0) or
(CompareFileExt(Filename,'.rst')=0) or
(CompareFileExt(Filename,'.rsj')=0) then
@ -357,7 +359,7 @@ begin
BasePOFile.SaveToFile(POFilename);
Result := BasePOFile.Modified;
UpdatePOFilesTranslation;
UpdatePoFileTranslations(POFilename,BasePoFile);
finally
InputLines.Free;

View File

@ -1,22 +1,23 @@
<?xml version="1.0"?>
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="9"/>
<PathDelim Value="\"/>
<Version Value="6"/>
<General>
<Flags>
<SaveOnlyProjectUnits Value="True"/>
<MainUnitHasUsesSectionForAllUnits Value="False"/>
<MainUnitHasCreateFormStatements Value="False"/>
<MainUnitHasTitleStatement Value="False"/>
</Flags>
<SessionStorage Value="InIDEConfig"/>
<MainUnit Value="0"/>
<TargetFileExt Value=".exe"/>
<ActiveEditorIndexAtStart Value="0"/>
</General>
<VersionInfo>
<ProjectVersion Value=""/>
<StringTable ProductVersion=""/>
</VersionInfo>
<BuildModes Count="1">
<Item1 Name="default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<IgnoreBinaries Value="False"/>
@ -26,7 +27,7 @@
<RunParams>
<local>
<FormatVersion Value="1"/>
<LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
<LaunchingApplication PathPlusParams="\usr\X11R6\bin\xterm -T 'Lazarus Run Output' -e $(LazarusDir)\tools\runwait.sh $(TargetCmdLine)"/>
</local>
</RunParams>
<RequiredPackages Count="1">
@ -39,19 +40,14 @@
<Filename Value="updatepofiles.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="UpdatePoFiles"/>
<CursorPos X="39" Y="113"/>
<TopLine Value="100"/>
<EditorIndex Value="0"/>
<UsageCount Value="28"/>
<Loaded Value="True"/>
</Unit0>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="8"/>
<Version Value="11"/>
<PathDelim Value="\"/>
<Other>
<CompilerPath Value="$(CompPath)"/>
</Other>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
</SearchPaths>
</CompilerOptions>
</CONFIG>