diff --git a/tools/updatepofiles.lpi b/tools/updatepofiles.lpi
index 8ec9698f59..efd3b79883 100644
--- a/tools/updatepofiles.lpi
+++ b/tools/updatepofiles.lpi
@@ -1,46 +1,44 @@
-
+
+
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
+
+ -
-
+
-
-
+
+
-
+
@@ -49,5 +47,10 @@
+
+
+
+
+
diff --git a/tools/updatepofiles.pas b/tools/updatepofiles.pas
index 18bba4259f..045e635c6e 100644
--- a/tools/updatepofiles.pas
+++ b/tools/updatepofiles.pas
@@ -1,4 +1,3 @@
-{ $Id$ }
{
***************************************************************************
* *
@@ -25,20 +24,42 @@
updatepofiles - updates po files.
Synopsis:
- updatepofiles filename1.pot [filename2.pot ... filenameN.pot]
+ updatepofiles [--searchdir=
] [filenameA.rsj [filenameB.rsj ... filenameN.rsj]] filename1.pot [filename2.pot ... filenameN.pot]
Description:
- updatepofiles updates the .pot file and merges new strings into
- all translated po files (filename1.*.po)
+ Updatepofiles updates the .pot file from .rsj (or .rst/.lrj) files and merges new strings into
+ all translated po files (filename1.*.po).
+ Examples:
+
+ 1. Only update .po files:
+ updatepofiles /path/to/project1.pot
+
+ 2. Update .pot file from .rsj and then .po files:
+ updatepofiles /path/to/fileA.rsj /path/to/project1.pot
+
+ 3. Update .pot file from several .rsj files:
+ updatepofiles /path/to/fileA.rsj /path/to/fileB.rsj /path/to/project1.pot
+
+ 4. Same as 2, but search .rsj in specified directory and its subdirectories:
+ updatepofiles --searchdir= fileA.rsj /path/to/project1.pot
+
+ Arguments can be repeated as needed, e. g.:
+
+ updatepofiles /path/to/fileA.rsj /path/to/project1.pot /path/to/fileB.rsj /path/to/project2.pot
+
+ will update project1.pot from fileA.rsj and project2.pot from fileB.rsj respectively.
}
program UpdatePoFiles;
{$mode objfpc}{$H+}
uses
- Classes, SysUtils, Translations, LazFileUtils, LazUTF8;
-
+ Classes, SysUtils, Translations, LazFileUtils, LazUTF8, FileUtil;
+
+const
+ ResSearchDirParamName='--searchdir=';
+
var
Files: TStringList;
Prefix: string;
@@ -64,49 +85,100 @@ begin
ResFiles[i].Free;
end;
+function TryFindResFile(ResSearchDir, FileName: string): string;
+var
+ FileNameOnly: String;
+ FL: TStringList;
+ i: integer;
+begin
+ Result:='';
+ if ResSearchDir<>'' then
+ begin
+ FileNameOnly:=ExtractFileName(FileName); //make sure that path to file is removed
+ try
+ FL:=FindAllFiles(ResSearchDir, FileNameOnly, True);
+ if FL.Count>0 then
+ begin
+ Result:=FL[0];
+ i:=1;
+ while iFileAge(Result) then
+ Result:=FL[i];
+ inc(i);
+ end;
+ end;
+ finally
+ FL.Free;
+ end;
+ end;
+ //writeln('Found resource string table file: ', Result);
+end;
+
function ParamsValid: boolean;
var
i: Integer;
+ ResSearchDir: String;
+ CurParam: String;
Filename: String;
Ext: String;
PoIndex: Integer;
+ IsResFile: Boolean;
begin
Result:=false;
PoIndex:=0;
+ ResSearchDir:='';
if ParamCount<1 then
exit;
- for i:=1 to ParamCount do begin
+ for i:=1 to ParamCount do
+ begin
+ CurParam:=ParamStrUTF8(i);
+ if UTF8StartsText(ResSearchDirParamName, CurParam) then
+ begin
+ ResSearchDir:=RightStr(CurParam, Length(CurParam)-Length(ResSearchDirParamName));
+ writeln('Current resource string table file search directory: ', ResSearchDir);
+ end
+ else
+ begin
+ Filename:=CurParam;
- Filename:=ParamStrUTF8(i);
+ Ext:=ExtractFileExt(Filename);
- Ext:=ExtractFileExt(Filename);
+ if (Ext<>'.pot') and (Ext<>'.rst') and (Ext<>'.lrj') and (Ext<>'.rsj') then
+ begin
+ writeln('ERROR: invalid extension: ', Filename);
+ exit;
+ end;
- if not FileExistsUTF8(Filename) then begin
+ IsResFile:=(Ext='.rst') or (Ext='.lrj') or (Ext='.rsj');
- if (Ext='.rst') or (Ext='.lrj') or (Ext='.rsj') then
- continue; // ignore resource files
+ if not FileExistsUTF8(Filename) then
+ begin
+ if IsResFile then
+ Filename:=TryFindResFile(ResSearchDir, Filename); // if resource file does not exist, search it in specified directory
- writeln('ERROR: file not found: ',FileName);
- exit;
+ if (Filename='') or (not IsResFile) then
+ begin
+ writeln('ERROR: file not found: ', FileName);
+ exit;
+ end;
+ end;
+
+ if Ext='.pot' then
+ begin
+ if Files=nil then
+ Files:=TStringList.Create;
+ Files.Add(Filename);
+ inc(PoIndex);
+ SetLength(ResFiles, Files.Count); // make sure Files and ResFiles are in sync
+ end
+ else
+ AddResFile(PoIndex, FileName);
end;
-
- if (Ext<>'.pot') and (Ext<>'.rst') and (Ext<>'.lrj') and (Ext<>'.rsj') then begin
- writeln('ERROR: invalid extension: ',Filename);
- exit;
- end;
-
- if Ext='.pot' then begin
- if Files=nil then
- Files:=TStringList.Create;
- Files.Add(Filename);
- inc(PoIndex);
- SetLength(ResFiles, Files.Count); // make sure Files and ResFiles are in sync
- end else
- AddResFile(PoIndex, FileName);
end;
- Result:=true;
+ Result:=PoIndex>0; // at least one .pot file should be found
end;
procedure UpdateAllPoFiles;
@@ -123,7 +195,7 @@ begin
if not ParamsValid then
writeln('Usage: ',ExtractFileName(ParamStrUTF8(0))
- ,' filename1.pot [filename2.pot ... filenameN.pot]')
+ ,' [--searchdir=] [filenameA.rsj [filenameB.rsj ... filenameN.rsj]] filename1.pot [filename2.pot ... filenameN.pot]')
else
UpdateAllPoFiles;